diff --git a/src/app/pages/inactivity/inactivity.page.ts b/src/app/pages/inactivity/inactivity.page.ts index 223409792..7ae1e66c6 100644 --- a/src/app/pages/inactivity/inactivity.page.ts +++ b/src/app/pages/inactivity/inactivity.page.ts @@ -110,7 +110,7 @@ export class InactivityPage implements OnInit { domainName: environment.domain, BasicAuthKey: "" } - let attempt = await this.authService.login(this.userattempt, false) + let attempt = await this.authService.login(this.userattempt, {saveSession: false}) if (attempt) { diff --git a/src/app/pages/login/login.page.ts b/src/app/pages/login/login.page.ts index f1a0441f4..04e468f91 100644 --- a/src/app/pages/login/login.page.ts +++ b/src/app/pages/login/login.page.ts @@ -16,7 +16,7 @@ import { SessionStore } from 'src/app/store/session.service'; export class LoginPage implements OnInit { logstatus: boolean; - username: string = environment.defaultuser; + username: string = SessionStore.user.Email || environment.defaultuser; password: string = environment.defaultuserpwd; userattempt: UserForm; code = [] @@ -35,26 +35,7 @@ export class LoginPage implements OnInit { ) { } - ngOnInit() { - - let userData = this.sessionStore.user - - const loginPreference = userData?.LoginPreference - const pin = userData?.PIN - - if (pin) { - this.hasPin = true - } else { - this.hasPin = false - } - - if (loginPreference) { - this.loginPreference = loginPreference - } else { - this.loginPreference = '' - } - - } + ngOnInit() {} //Function to validade the login inputs validateUsername() { @@ -95,13 +76,23 @@ export class LoginPage implements OnInit { domainName: environment.domain, BasicAuthKey: "" } - let attempt = await this.authService.login(this.userattempt) + + let attempt = await this.authService.login(this.userattempt, {saveSession: false}) if (attempt) { - await this.authService.loginChat(this.userattempt); - await this.getToken(); - this.router.navigate(['/pin']); + if (attempt.UserId == SessionStore.user.UserId) { + await this.authService.SetSession(attempt, this.userattempt); + this.authService.loginChat(this.userattempt); + this.getToken(); + SessionStore.setInativity(true) + this.goback() + } else { + SessionStore.delete() + window.localStorage.clear(); + await this.authService.SetSession(attempt, this.userattempt); + this.router.navigate(['/pin']); + } } } @@ -114,4 +105,15 @@ export class LoginPage implements OnInit { } } + + goback() { + const pathName = SessionStore.user.UrlBeforeInactivity + if(pathName) { + this.router.navigate([pathName]); + } else { + this.router.navigate(['/home/events']); + } + + } + } diff --git a/src/app/services/auth.service.ts b/src/app/services/auth.service.ts index b5339cc31..8f848e0a8 100644 --- a/src/app/services/auth.service.ts +++ b/src/app/services/auth.service.ts @@ -41,7 +41,7 @@ export class AuthService { } - async login(user: UserForm, saveSession = true): Promise { + async login(user: UserForm, {saveSession = true}): Promise { user.BasicAuthKey = 'Basic ' + btoa(user.username + ':' + this.aesencrypt.encrypt(user.password,user.username )); this.headers = this.headers.set('Authorization',user.BasicAuthKey); diff --git a/src/app/services/inativity.service.ts b/src/app/services/inativity.service.ts index 1ea52ceca..a93c50a3f 100644 --- a/src/app/services/inativity.service.ts +++ b/src/app/services/inativity.service.ts @@ -29,7 +29,7 @@ export class InativityService { function resetTimer() { clearTimeout(t); - t = setTimeout(userIsNotActive, 60000 * 5); // time is in milliseconds + t = setTimeout(userIsNotActive, 60000 * 15); // time is in milliseconds } } }