From ccc7784489736eb3da5d23e58b12343c90aec149 Mon Sep 17 00:00:00 2001 From: Paola Date: Tue, 6 Jul 2021 20:49:15 -0600 Subject: [PATCH 1/2] Remover procesos en service Google --- .../login/usuario-google-log-in.service.ts | 25 +------------------ 1 file changed, 1 insertion(+), 24 deletions(-) diff --git a/src/main/webapp/app/login/usuario-google-log-in.service.ts b/src/main/webapp/app/login/usuario-google-log-in.service.ts index 5d6818c..a6c3739 100644 --- a/src/main/webapp/app/login/usuario-google-log-in.service.ts +++ b/src/main/webapp/app/login/usuario-google-log-in.service.ts @@ -5,28 +5,5 @@ import { Observable, ReplaySubject } from 'rxjs'; providedIn: 'root', }) export class UsuarioGoogleLogInService { - constructor(private auth2: gapi.auth2.GoogleAuth, private subject: ReplaySubject) { - gapi.load('auth2', () => { - this.auth2 = gapi.auth2.init({ - client_id: '178178891217-b517thad8f15d4at2vk2410v7a09dcvt.apps.googleusercontent.com', - }); - }); - } - - public sigIn() { - this.auth2 - .signIn({ - // - }) - .then(user => { - this.subject.next(user); - }) - .catch(() => { - this.subject.next(); //NULL - }); - } - - public observable(): Observable { - return this.subject.asObservable(); - } + constructor() {} } From 08a1cc5c32faa60166709f8327443e2e05a2fdfd Mon Sep 17 00:00:00 2001 From: Paola Date: Tue, 6 Jul 2021 20:49:15 -0600 Subject: [PATCH 2/2] Agregar servicio de loggeo Google --- src/main/webapp/app/login/login.component.ts | 17 +++++++++++-- .../login/usuario-google-log-in.service.ts | 25 +------------------ 2 files changed, 16 insertions(+), 26 deletions(-) diff --git a/src/main/webapp/app/login/login.component.ts b/src/main/webapp/app/login/login.component.ts index 765e35e..ae9a36a 100644 --- a/src/main/webapp/app/login/login.component.ts +++ b/src/main/webapp/app/login/login.component.ts @@ -4,7 +4,7 @@ import { Router } from '@angular/router'; import { LoginService } from 'app/login/login.service'; import { AccountService } from 'app/core/auth/account.service'; -import { SocialAuthService } from 'angularx-social-login'; +import { SocialAuthService, SocialUser } from 'angularx-social-login'; import { GoogleLoginProvider } from 'angularx-social-login'; @Component({ @@ -24,6 +24,9 @@ export class LoginComponent implements OnInit, AfterViewInit { rememberMe: [false], }); + user: SocialUser = new SocialUser(); + loggedIn: boolean = false; + constructor( private accountService: AccountService, private loginService: LoginService, @@ -33,7 +36,12 @@ export class LoginComponent implements OnInit, AfterViewInit { ) {} ngOnInit(): void { - //console.log("Google ID: "+ GoogleLoginProvider.PROVIDER_ID) + //Servicio para verificar si el usuario se encuentra loggeado + this.authService.authState.subscribe(user => { + this.user = user; + this.loggedIn = user != null; + }); + // if already authenticated then navigate to home page this.accountService.identity().subscribe(() => { if (this.accountService.isAuthenticated()) { @@ -46,10 +54,15 @@ export class LoginComponent implements OnInit, AfterViewInit { this.username.nativeElement.focus(); } + //Inicio Google signInWithGoogle(): void { this.authService.signIn(GoogleLoginProvider.PROVIDER_ID); } + refreshToken(): void { + this.authService.refreshAuthToken(GoogleLoginProvider.PROVIDER_ID); + } + login(): void { this.loginService .login({ diff --git a/src/main/webapp/app/login/usuario-google-log-in.service.ts b/src/main/webapp/app/login/usuario-google-log-in.service.ts index 5d6818c..a6c3739 100644 --- a/src/main/webapp/app/login/usuario-google-log-in.service.ts +++ b/src/main/webapp/app/login/usuario-google-log-in.service.ts @@ -5,28 +5,5 @@ import { Observable, ReplaySubject } from 'rxjs'; providedIn: 'root', }) export class UsuarioGoogleLogInService { - constructor(private auth2: gapi.auth2.GoogleAuth, private subject: ReplaySubject) { - gapi.load('auth2', () => { - this.auth2 = gapi.auth2.init({ - client_id: '178178891217-b517thad8f15d4at2vk2410v7a09dcvt.apps.googleusercontent.com', - }); - }); - } - - public sigIn() { - this.auth2 - .signIn({ - // - }) - .then(user => { - this.subject.next(user); - }) - .catch(() => { - this.subject.next(); //NULL - }); - } - - public observable(): Observable { - return this.subject.asObservable(); - } + constructor() {} }