formatting fixes

This commit is contained in:
2019-10-17 12:14:27 -05:00
parent 725313e545
commit 0d7136ce3d
6 changed files with 50 additions and 46 deletions

3
.vscode/settings.json vendored Normal file
View File

@@ -0,0 +1,3 @@
{
"python.pythonPath": "C:\\Python27\\python.exe"
}

View File

@@ -10,26 +10,26 @@ import { Hub } from '@aws-amplify/core';
})
export class AuthComponent implements OnInit {
constructor( private _router: Router, private _zone: NgZone ) { }
constructor( private router: Router, private zone: NgZone ) { }
ngOnInit() {
Hub.listen('auth', ({ payload: { event, data } }) => {
switch (event) {
case 'signIn':
this._zone.run(() => {
this._router.navigate(['/']);
this.zone.run(() => {
this.router.navigate(['/']);
});
break;
case 'signOut':
this._zone.run(() => {
this._router.navigate(['/auth/signin']);
this.zone.run(() => {
this.router.navigate(['/auth/signin']);
});
break;
}
});
Auth.currentAuthenticatedUser()
.then(() => {
this._router.navigate(['auth/profile']);
this.router.navigate(['auth/profile']);
})
.catch(() => {});
}

View File

@@ -7,13 +7,13 @@ import Auth from '@aws-amplify/auth';
providedIn: 'root'
})
export class AuthGuard implements CanActivate {
constructor( private _router: Router ) { }
constructor( private router: Router ) { }
canActivate(
next: ActivatedRouteSnapshot,
state: RouterStateSnapshot): Observable<boolean> | Promise<boolean> | boolean {
return Auth.currentAuthenticatedUser().then(() => { return true; })
return Auth.currentAuthenticatedUser().then(() => true)
.catch(() => {
this._router.navigate(['auth/signin']);
this.router.navigate(['auth/signin']);
return false;
});
}

View File

@@ -17,38 +17,39 @@ export interface NewUser {
})
export class AuthService {
public loggedIn: boolean;
private _authState: Subject<CognitoUser|any> = new Subject<CognitoUser|any>();
authState: Observable<CognitoUser|any> = this._authState.asObservable();
public static SIGN_IN = 'signIn';
public static SIGN_OUT = 'signOut';
public static FACEBOOK = CognitoHostedUIIdentityProvider.Facebook;
public static GOOGLE = CognitoHostedUIIdentityProvider.Google;
public loggedIn: boolean;
private authStateSubject: Subject<CognitoUser|any> = new Subject<CognitoUser|any>();
authState: Observable<CognitoUser|any> = this.authStateSubject.asObservable();
constructor() {
Hub.listen('auth', (data) => {
const { channel, payload } = data;
if (channel === 'auth') {
this._authState.next(payload.event);
this.authStateSubject.next(payload.event);
}
});
}
signUp(user: NewUser): Promise<CognitoUser|any> {
return Auth.signUp({
"username": user.email,
"password": user.password,
"attributes": {
"email": user.email,
"given_name": user.firstName,
"family_name": user.lastName,
"phone_number": user.phone
username: user.email,
password: user.password,
attributes: {
email: user.email,
given_name: user.firstName,
family_name: user.lastName,
phone_number: user.phone
}
});
}
signIn(username: string, password: string):Promise<CognitoUser|any> {
signIn(username: string, password: string): Promise<CognitoUser|any> {
return new Promise((resolve, reject) => {
Auth.signIn(username, password)
.then((user: CognitoUser|any) => {
@@ -63,9 +64,9 @@ export class AuthService {
.then(() => this.loggedIn = false);
}
socialSignIn(provider:CognitoHostedUIIdentityProvider): Promise<ICredentials> {
socialSignIn(provider: CognitoHostedUIIdentityProvider): Promise<ICredentials> {
return Auth.federatedSignIn({
'provider': provider
provider
});
}

View File

@@ -15,7 +15,7 @@ import { LoaderService } from 'src/app/loader/loader.service';
export class SignInComponent {
signinForm: FormGroup = new FormGroup({
email: new FormControl('',[ Validators.email, Validators.required ]),
email: new FormControl('', [ Validators.email, Validators.required ]),
password: new FormControl('', [ Validators.required, Validators.min(6) ])
});
@@ -26,9 +26,9 @@ export class SignInComponent {
constructor(
public auth: AuthService,
private _notification: NotificationService,
private _router: Router,
private _loader: LoaderService ) { }
private notification: NotificationService,
private router: Router,
private loader: LoaderService ) { }
getEmailInputError() {
if (this.emailInput.hasError('email')) {
@@ -46,26 +46,26 @@ export class SignInComponent {
}
signIn() {
this._loader.show();
this.loader.show();
this.auth.signIn(this.emailInput.value, this.passwordInput.value)
.then((user: CognitoUser|any) => {
this._loader.hide();
this._router.navigate(['']);
this.loader.hide();
this.router.navigate(['']);
})
.catch((error: any) => {
this._loader.hide();
this._notification.show(error.message);
this.loader.hide();
this.notification.show(error.message);
switch (error.code) {
case "UserNotConfirmedException":
case 'UserNotConfirmedException':
environment.confirm.email = this.emailInput.value;
environment.confirm.password = this.passwordInput.value;
this._router.navigate(['auth/confirm']);
this.router.navigate(['auth/confirm']);
break;
case "UsernameExistsException":
this._router.navigate(['auth/signin']);
case 'UsernameExistsException':
this.router.navigate(['auth/signin']);
break;
}
})
});
}
async signInWithFacebook() {

View File

@@ -30,9 +30,9 @@ export class HomeComponent implements OnInit {
gaugeMin = 0;
gaugeMax = 100;
gaugeThresholds = {
'0' : { color : 'red'},
'33' : { color : 'orange'},
'66' : { color : 'green'}
0 : { color : 'red'},
33 : { color : 'orange'},
66 : { color : 'green'}
};
constructor() {