Improve login

This commit is contained in:
Peter Maquiran
2021-09-02 12:17:14 +01:00
parent 3614a2eba7
commit 1f2631fcdf
10 changed files with 51 additions and 75 deletions
+27 -25
View File
@@ -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']);
}
}
}