From 137117eda246f7e23db704687f6062d94afa0b4b Mon Sep 17 00:00:00 2001 From: Nicola Lanzilotto Date: Mon, 16 Oct 2023 19:14:13 +0200 Subject: [PATCH] Improvements and bug fixing --- src/app/auth/autologin/autologin.component.ts | 74 +++++++- src/app/auth/signin/signin.component.html | 2 +- src/app/auth/signin/signin.component.ts | 12 +- src/app/auth/signup/signup.component.ts | 12 +- src/app/core/auth.guard.ts | 10 + src/app/core/auth.service.ts | 49 +---- .../create-project-gs.component.ts | 5 +- src/app/home/home.component.ts | 12 +- .../knowledge-bases.component.ts | 171 +++++++++++++++++- src/app/projects/projects.component.ts | 4 +- 10 files changed, 282 insertions(+), 69 deletions(-) diff --git a/src/app/auth/autologin/autologin.component.ts b/src/app/auth/autologin/autologin.component.ts index a1df8dfc1010..2f82eb02628e 100755 --- a/src/app/auth/autologin/autologin.component.ts +++ b/src/app/auth/autologin/autologin.component.ts @@ -11,6 +11,7 @@ import { AppConfigService } from '../../services/app-config.service'; import { environment } from '../../../environments/environment'; import { ProjectService } from '../../services/project.service'; import { LoggerService } from '../../services/logger/logger.service'; +import { LocalDbService } from 'app/services/users-local-db.service'; @Component({ selector: 'appdashboard-autologin', @@ -26,8 +27,7 @@ export class AutologinComponent implements OnInit { FCMcurrentToken: string; user: any; public version: string = environment.VERSION; - - + public hasSignedInWithGoogle: boolean = false; constructor( private route: ActivatedRoute, @@ -36,7 +36,8 @@ export class AutologinComponent implements OnInit { public sso: SsoService, public appConfigService: AppConfigService, private projectService: ProjectService, - private logger: LoggerService + private logger: LoggerService, + private localDbService: LocalDbService ) { this.user = auth.user_bs.value; @@ -59,6 +60,15 @@ export class AutologinComponent implements OnInit { } + + ngOnInit() { + this.logger.log('[AUTOLOGIN] SSO - autologin page'); + this.detectMobile(); + + } + + + getJWTAndRouteParamsAndLogin() { this.route.params.subscribe((params) => { this.logger.log('[AUTOLOGIN] SSO - autologin page params ', params) @@ -96,11 +106,7 @@ export class AutologinComponent implements OnInit { }); } - ngOnInit() { - this.logger.log('[AUTOLOGIN] SSO - autologin page'); - this.detectMobile(); - } detectMobile() { @@ -135,10 +141,10 @@ export class AutologinComponent implements OnInit { } this.sso.getCurrentAuthenticatedUser(JWT).subscribe(auth_user => { - this.logger.log('[AUTOLOGIN] SSO - ssoLogin getCurrentAuthenticatedUser RES ', auth_user); + // console.log('[AUTOLOGIN] SSO - ssoLogin getCurrentAuthenticatedUser RES ', auth_user); const user = { firstname: auth_user['firstname'], lastname: auth_user['lastname'], _id: auth_user['_id'], email: auth_user['email'], emailverified: auth_user['emailverified'], token: JWT } - this.logger.log('[AUTOLOGIN] SSO - ssoLogin getCurrentAuthenticatedUser user ', user); + // console.log('[AUTOLOGIN] SSO - ssoLogin getCurrentAuthenticatedUser user ', user); localStorage.setItem('user', JSON.stringify(user)); localStorage.setItem(chatPrefix + '__tiledeskToken', JWT); @@ -147,6 +153,14 @@ export class AutologinComponent implements OnInit { this.router.navigate([route]); + // get if user has used Signin with Google + const hasSigninWithGoogle = this.localDbService.getFromStorage('swg') + if ( hasSigninWithGoogle ) { + this.localDbService.removeFromStorage('swg') + // console.log('[AUTOLOGIN] SSO removeFromStorage swg') + this.trackUserHasSignedInWithGoogle(user) + } + this.logger.log('[AUTOLOGIN] SSO - ssoLogin JWT before to get permsission ', JWT) this.logger.log('[AUTOLOGIN] SSO - ssoLogin storedJWT before to get permsission ', storedJWT) if (JWT !== storedJWT) { @@ -179,6 +193,48 @@ export class AutologinComponent implements OnInit { }); } + trackUserHasSignedInWithGoogle(user) { + if (!isDevMode()) { + if (window['analytics']) { + // try { + // window['analytics'].page("Auth Page, Sign in with Google", { + + // }); + // } catch (err) { + // this.logger.error('Sign in with Google page error', err); + // } + + let userFullname = '' + if (user.firstname && user.lastname) { + userFullname = user.firstname + ' ' + user.lastname + } else if (user.firstname && !user.lastname) { + userFullname = user.firstname + } + + try { + window['analytics'].identify(user._id, { + name: userFullname, + email: user.email, + logins: 5, + + }); + } catch (err) { + this.logger.error('identify Sign in with Google event error', err); + } + // Segments + try { + window['analytics'].track('Signed In', { + "username": userFullname, + "userId": user._id, + 'method': "Sign in with Google" + }); + } catch (err) { + this.logger.error('track Sign in with Google event error', err); + } + } + } + } + getProjectFromRemotePublishAndSaveInStorage(project_id) { this.projectService.getProjects().subscribe((prjcts: any) => { diff --git a/src/app/auth/signin/signin.component.html b/src/app/auth/signin/signin.component.html index abe65c7cdf4b..cfe12ef1f570 100755 --- a/src/app/auth/signin/signin.component.html +++ b/src/app/auth/signin/signin.component.html @@ -113,7 +113,7 @@