From 0d7136ce3d0f2dca6430523c6ea9ae393e5c06f7 Mon Sep 17 00:00:00 2001 From: Nico Melone Date: Thu, 17 Oct 2019 12:14:27 -0500 Subject: [PATCH] formatting fixes --- .vscode/settings.json | 3 ++ src/app/auth/auth.component.ts | 14 ++++----- src/app/auth/auth.guard.ts | 8 +++--- src/app/auth/auth.service.ts | 35 ++++++++++++----------- src/app/auth/sign-in/sign-in.component.ts | 30 +++++++++---------- src/app/home/home.component.ts | 6 ++-- 6 files changed, 50 insertions(+), 46 deletions(-) create mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..88322cc --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "python.pythonPath": "C:\\Python27\\python.exe" +} \ No newline at end of file diff --git a/src/app/auth/auth.component.ts b/src/app/auth/auth.component.ts index c5b83ab..c89c113 100644 --- a/src/app/auth/auth.component.ts +++ b/src/app/auth/auth.component.ts @@ -10,28 +10,28 @@ 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(() => {}); } -} \ No newline at end of file +} diff --git a/src/app/auth/auth.guard.ts b/src/app/auth/auth.guard.ts index 2e99123..456df33 100644 --- a/src/app/auth/auth.guard.ts +++ b/src/app/auth/auth.guard.ts @@ -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 | Promise | boolean { - return Auth.currentAuthenticatedUser().then(() => { return true; }) - .catch(() => { - this._router.navigate(['auth/signin']); + return Auth.currentAuthenticatedUser().then(() => true) + .catch(() => { + this.router.navigate(['auth/signin']); return false; }); } diff --git a/src/app/auth/auth.service.ts b/src/app/auth/auth.service.ts index 4c03d54..d9680a0 100644 --- a/src/app/auth/auth.service.ts +++ b/src/app/auth/auth.service.ts @@ -17,38 +17,39 @@ export interface NewUser { }) export class AuthService { - public loggedIn: boolean; - private _authState: Subject = new Subject(); - authState: Observable = this._authState.asObservable(); - public static SIGN_IN = 'signIn'; - public static SIGN_OUT = 'signOut'; + public static SIGN_OUT = 'signOut'; public static FACEBOOK = CognitoHostedUIIdentityProvider.Facebook; public static GOOGLE = CognitoHostedUIIdentityProvider.Google; + public loggedIn: boolean; + private authStateSubject: Subject = new Subject(); + authState: Observable = 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 { 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 { + signIn(username: string, password: string): Promise { return new Promise((resolve, reject) => { Auth.signIn(username, password) .then((user: CognitoUser|any) => { @@ -63,10 +64,10 @@ export class AuthService { .then(() => this.loggedIn = false); } - socialSignIn(provider:CognitoHostedUIIdentityProvider): Promise { + socialSignIn(provider: CognitoHostedUIIdentityProvider): Promise { return Auth.federatedSignIn({ - 'provider': provider + provider }); } -} \ No newline at end of file +} diff --git a/src/app/auth/sign-in/sign-in.component.ts b/src/app/auth/sign-in/sign-in.component.ts index 43b6707..2405aed 100644 --- a/src/app/auth/sign-in/sign-in.component.ts +++ b/src/app/auth/sign-in/sign-in.component.ts @@ -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() { @@ -77,4 +77,4 @@ export class SignInComponent { const socialResult = await this.auth.socialSignIn(AuthService.GOOGLE); console.log('google Result:', socialResult); } -} \ No newline at end of file +} diff --git a/src/app/home/home.component.ts b/src/app/home/home.component.ts index 3fa61d2..5d8ff7b 100644 --- a/src/app/home/home.component.ts +++ b/src/app/home/home.component.ts @@ -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() {