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 { export class AuthComponent implements OnInit {
constructor( private _router: Router, private _zone: NgZone ) { } constructor( private router: Router, private zone: NgZone ) { }
ngOnInit() { ngOnInit() {
Hub.listen('auth', ({ payload: { event, data } }) => { Hub.listen('auth', ({ payload: { event, data } }) => {
switch (event) { switch (event) {
case 'signIn': case 'signIn':
this._zone.run(() => { this.zone.run(() => {
this._router.navigate(['/']); this.router.navigate(['/']);
}); });
break; break;
case 'signOut': case 'signOut':
this._zone.run(() => { this.zone.run(() => {
this._router.navigate(['/auth/signin']); this.router.navigate(['/auth/signin']);
}); });
break; break;
} }
}); });
Auth.currentAuthenticatedUser() Auth.currentAuthenticatedUser()
.then(() => { .then(() => {
this._router.navigate(['auth/profile']); this.router.navigate(['auth/profile']);
}) })
.catch(() => {}); .catch(() => {});
} }

View File

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

View File

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

View File

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

View File

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