This commit is contained in:
tiago.kayaya
2021-09-02 13:22:10 +01:00
18 changed files with 355 additions and 221 deletions
+28 -28
View File
@@ -6,7 +6,6 @@ import { ToastService } from 'src/app/services/toast.service';
import { environment } from 'src/environments/environment';
import { AlertController } from '@ionic/angular';
import { NotificationsService } from 'src/app/services/notifications.service';
import { LocalstoreService } from 'src/app/store/localstore.service';
import { SessionStore } from 'src/app/store/session.service';
@Component({
@@ -17,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 = []
@@ -32,31 +31,11 @@ export class LoginPage implements OnInit {
private router: Router,
private authService: AuthService,
private toastService: ToastService,
public alertController: AlertController,
private localstoreService: LocalstoreService
public alertController: AlertController
) {
}
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() {
@@ -97,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']);
}
}
}
@@ -116,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']);
}
}
}