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
+7 -2
View File
@@ -2,6 +2,7 @@ import { Injectable } from '@angular/core';
import { ActivatedRouteSnapshot, CanActivate, Router, RouterStateSnapshot, UrlTree } from '@angular/router';
import { Observable } from 'rxjs';
import { SessionStore } from '../store/session.service';
import { AlertController, Platform } from '@ionic/angular';
@Injectable({
providedIn: 'root'
@@ -9,14 +10,18 @@ import { SessionStore } from '../store/session.service';
export class InactivityGuard implements CanActivate {
constructor(
private router:Router
private router:Router,
private platform: Platform,
){}
canActivate(
route: ActivatedRouteSnapshot,
state: RouterStateSnapshot): Observable<boolean | UrlTree> | Promise<boolean | UrlTree> | boolean | UrlTree {
if(SessionStore.exist && SessionStore.user.Inactivity && !SessionStore.hasPin ) {
if (this.platform.is('desktop') || this.platform.is('mobileweb')) {
this.router.navigate(['/home/events']);
return false
} else if(SessionStore.exist && SessionStore.user.Inactivity && !SessionStore.hasPin ) {
return true
} else if(SessionStore.exist && !SessionStore.user.Inactivity) {
return true
+8 -4
View File
@@ -8,19 +8,23 @@ import { SessionStore } from '../store/session.service';
providedIn: 'root'
})
export class LoginGuard implements CanActivate {
constructor( private router:Router,
private localstoreService: LocalstoreService) {
constructor( private router:Router) {
}
canActivate(
route: ActivatedRouteSnapshot,
state: RouterStateSnapshot): Observable<boolean | UrlTree> | Promise<boolean | UrlTree> | boolean | UrlTree {
if(window.location.pathname == '/' && SessionStore.exist ) {
if(SessionStore.exist && SessionStore.user.Inactivity && SessionStore.user.LoginPreference != 'Pin' ) {
this.router.navigate(['/home/events']);
return false
} else if(SessionStore.exist && !SessionStore.hasPin ) {
this.router.navigate(['/pin']);
return false
} else if(SessionStore.exist && !SessionStore.user.Inactivity && SessionStore.user.LoginPreference == 'Pin' ) {
this.router.navigate(['/inactivity']);
return false
} else {
return true
}
}
@@ -53,7 +53,7 @@
</div>
</div>
<div class="login-preference width-100" *ngIf="!production">
<div class="login-preference width-100" *ngIf="!platform.is('desktop') && !platform.is('mobileweb')">
<div class="preference">Preferência Login</div>
<ion-row>
@@ -73,11 +73,6 @@
</ion-row>
</div>
<div hidden class="d-flex width-100 justify-center mt-10">
<button hidden (click)="addPin()" class="btn-ok buttonSize" fill="clear" color="#fff" >
<ion-label>Alterar PIN</ion-label>
</button>
</div>
</div>
</div>
</ion-content>
@@ -4,6 +4,7 @@ import { FingerprintPage } from 'src/app/shared/fingerprint/fingerprint.page';
import { PinPage } from 'src/app/shared/pin/pin.page';
import { SessionStore } from 'src/app/store/session.service';
import { environment } from 'src/environments/environment';
import { Platform } from '@ionic/angular';
@Component({
selector: 'app-edit-profile',
@@ -16,7 +17,8 @@ export class EditProfilePage implements OnInit {
production = environment.production
constructor(private modalController:ModalController,
private animationController: AnimationController
private animationController: AnimationController,
public platform: Platform,
) {}
ngOnInit() {}
+2 -3
View File
@@ -11,7 +11,6 @@ import { JsonStore } from '../../services/jsonStore.service';
import { StorageService } from '../../services/storage.service';
import { NotificationsService } from '../../services/notifications.service';
import { SessionStore } from 'src/app/store/session.service';
import { synchro } from 'src/app/services/socket/synchro.service';
@Component({
selector: 'app-profile',
@@ -43,7 +42,7 @@ export class ProfilePage implements OnInit {
private zone: NgZone,
private notificationservice: NotificationsService,
private platform: Platform,
private notificationsService: NotificationsService,
private notificationsService: NotificationsService,
) {
this.loggeduser = authService.ValidatedUser;
@@ -222,7 +221,7 @@ export class ProfilePage implements OnInit {
SessionStore.setInativity(false)
setTimeout(() => {
this.router.navigate(['/login']);
this.router.navigateByUrl('/', { replaceUrl: true });
}, 100)
}
@@ -1,37 +1,6 @@
<ion-content class="text-white">
<div class="main-wrapper">
<div class="wrapper" *ngIf="SessionStore.user.LoginPreference == 'Password' && SessionStore.hasPin || SessionStore.user.LoginPreference == null && SessionStore.hasPin || SessionStore.user.LoginPreference == 'None' && SessionStore.hasPin || enterWithPassword">
<div class="bg-1 d-flex justify-center align-center">
<div class="bg-2 d-flex justify-center align-center">
<div class="bg-3 d-flex justify-center align-center">
<div class="bg-4 d-flex justify-center align-center">
<div class="div-logo">
<img src='assets/images/fullLogo.png' alt='logo'>
</div>
</div>
</div>
</div>
</div>
<h3 class="center text-white">Inicie a sessão</h3>
<form class="form">
<p class="form-label text-white">Email</p>
<ion-item class="form-input">
<ion-input type="text" [(ngModel)]="username" name="input-username"></ion-input>
</ion-item>
<p class="form-label text-white">Palavra-passe</p>
<ion-item class="form-input">
<ion-input (keyup.enter)="Login()" type="password" [(ngModel)]="password" name="input-password" ></ion-input>
</ion-item>
<div class="d-flex pt-25">
<button class="btn-ok btn-login" fill="clear" expand="block" shape="round" (click)="Login()">Iniciar</button>
</div>
</form>
<div class="msg-bottom d-flex">
<p class="msg-bottom-p">Uma iniciativa do Gabinete do Presidente da República</p>
</div>
</div>
<div class="main-content d-flex flex-column width" *ngIf="!SessionStore.hasPin || SessionStore.hasPin && SessionStore.user.LoginPreference == 'Pin' && !enterWithPassword " >
+1 -1
View File
@@ -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) {
+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']);
}
}
}
+1 -1
View File
@@ -41,7 +41,7 @@ export class AuthService {
}
async login(user: UserForm, saveSession = true): Promise<LoginUserRespose> {
async login(user: UserForm, {saveSession = true}): Promise<LoginUserRespose> {
user.BasicAuthKey = 'Basic ' + btoa(user.username + ':' + this.aesencrypt.encrypt(user.password,user.username ));
this.headers = this.headers.set('Authorization',user.BasicAuthKey);
+1 -1
View File
@@ -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
}
}
}