mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-18 20:47:54 +00:00
add inactivity page
This commit is contained in:
@@ -1,18 +1,14 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { StorageService } from './storage.service';
|
||||
import { Router } from '@angular/router';
|
||||
import { HttpClient, HttpHeaders, HttpParams } from '@angular/common/http';
|
||||
import { User, UserForm, UserSession } from '../models/user.model';
|
||||
import { HttpClient, HttpHeaders } from '@angular/common/http';
|
||||
import { LoginUserRespose, UserForm, UserSession } from '../models/user.model';
|
||||
import { environment } from 'src/environments/environment';
|
||||
import { HttpService } from './http.service';
|
||||
import { BehaviorSubject, Observable } from 'rxjs';
|
||||
import { BehaviorSubject } from 'rxjs';
|
||||
import { AuthConnstants } from '../config/auth-constants';
|
||||
import { AlertController } from '@ionic/angular';
|
||||
import { LocalstoreService } from '../store/localstore.service';
|
||||
import { ToastService } from './toast.service';
|
||||
import { UserStore } from 'src/app/store/user.service'
|
||||
import { SHA1, SHA256, AES, enc } from 'crypto-js'
|
||||
import { SessionStore } from '../store/session.service';
|
||||
import { AESEncrypt } from '../services/aesencrypt.service';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
@@ -21,19 +17,16 @@ export class AuthService {
|
||||
userData$ = new BehaviorSubject<any>('');
|
||||
userId$ = new BehaviorSubject<any>('');
|
||||
headers: HttpHeaders;
|
||||
public ValidatedUser: User;
|
||||
public ValidatedUser: UserSession;
|
||||
public ValidatedUserChat:any;
|
||||
opts:any;
|
||||
userStore = UserStore
|
||||
|
||||
constructor(
|
||||
private http: HttpClient,
|
||||
private httpService: HttpService,
|
||||
private storageService:StorageService,
|
||||
private router:Router,
|
||||
public alertController: AlertController,
|
||||
private localstoreService: LocalstoreService,
|
||||
private toastService: ToastService,
|
||||
private aesencrypt: AESEncrypt,
|
||||
) {
|
||||
|
||||
this.headers = new HttpHeaders();
|
||||
@@ -48,12 +41,8 @@ export class AuthService {
|
||||
|
||||
}
|
||||
|
||||
|
||||
async login(user: UserForm): Promise<boolean> {
|
||||
// user.BasicAuthKey = 'Basic ' + btoa(user.username + '@' + user.domainName + ':' + user.password);
|
||||
user.BasicAuthKey = 'Basic ' + btoa(user.username + ':' + user.password); //conversão em base64 das credenciais inseridas
|
||||
console.log('Basic ' + btoa(user.username + ':' + SHA1(user.password).toString())); //conversão em base64 das credenciais inseridas
|
||||
|
||||
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);
|
||||
this.opts = {
|
||||
@@ -63,41 +52,39 @@ export class AuthService {
|
||||
let response: any;
|
||||
|
||||
try {
|
||||
response = await this.http.post<User>(environment.apiURL + "UserAuthentication/Login", '', this.opts).toPromise();
|
||||
const session: UserSession = Object.assign(new UserSession(), response)
|
||||
|
||||
|
||||
if (response) {
|
||||
if( session.RoleID == 100000014) {
|
||||
session.Profile = 'PR'
|
||||
} else if(session.RoleID == 100000011) {
|
||||
session.Profile = 'MDGPR'
|
||||
}
|
||||
session.BasicAuthKey = user.BasicAuthKey
|
||||
this.ValidatedUser = response;
|
||||
|
||||
console.log('session', session)
|
||||
|
||||
this.userStore.reset(session)
|
||||
SessionStore.reset(session)
|
||||
|
||||
this.storageService.store(AuthConnstants.USER, response);
|
||||
|
||||
return true;
|
||||
response = await this.http.post<LoginUserRespose>(environment.apiURL + "UserAuthentication/Login", '', this.opts).toPromise();
|
||||
if(saveSession) {
|
||||
this.SetSession(response, user)
|
||||
}
|
||||
|
||||
} catch (error) {
|
||||
if(error.status == 0) {
|
||||
this.toastService.badRequest('Verifique a sua conexão com a internet e volte a tentar')
|
||||
} else {
|
||||
this.toastService.badRequest('O email e/ou palavra-passe estão incorretas ou verifique a sua conexão com a internet e volte a tentar');
|
||||
}
|
||||
return false;
|
||||
|
||||
} finally {
|
||||
return response
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
logout(){
|
||||
SetSession(response: LoginUserRespose, user:UserForm) {
|
||||
const session: UserSession = Object.assign(SessionStore.user, response)
|
||||
|
||||
if (response) {
|
||||
if( session.RoleID == 100000014) {
|
||||
session.Profile = 'PR'
|
||||
} else if(session.RoleID == 100000011) {
|
||||
session.Profile = 'MDGPR'
|
||||
}
|
||||
|
||||
session.BasicAuthKey = user.BasicAuthKey
|
||||
|
||||
SessionStore.reset(session)
|
||||
this.ValidatedUser = SessionStore.user;
|
||||
this.storageService.store(AuthConnstants.USER, response);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
logout() {
|
||||
this.ValidatedUser = null;
|
||||
}
|
||||
|
||||
@@ -125,27 +112,12 @@ export class AuthService {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
//Get user data from RocketChat | global object
|
||||
getUserData(){
|
||||
this.storageService.get(AuthConnstants.AUTH).then(res=>{
|
||||
this.userData$.next(res);
|
||||
});
|
||||
}
|
||||
//Get user Id | global object
|
||||
getUserId(){
|
||||
/* this.storageService.get(AuthConnstants.USER).then(res=>{
|
||||
this.userId$.next(res);
|
||||
}); */
|
||||
}
|
||||
|
||||
getProfile(){
|
||||
/* this.storageService.get(AuthConnstants.PROFILE).then(res=>{
|
||||
return res;
|
||||
}); */
|
||||
}
|
||||
|
||||
logoutChat(){
|
||||
//this.storageService.clear();
|
||||
|
||||
Reference in New Issue
Block a user