mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-21 13:55:51 +00:00
add inactivity page
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
import { TestBed } from '@angular/core/testing';
|
||||
|
||||
import { AESEncrypt } from './aesencrypt.service';
|
||||
|
||||
describe('AuthService', () => {
|
||||
let service: AESEncrypt;
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({});
|
||||
service = TestBed.inject(AESEncrypt);
|
||||
});
|
||||
|
||||
it('should be created', () => {
|
||||
expect(service).toBeTruthy();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,60 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import CryptoJS from 'crypto-js';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class AESEncrypt {
|
||||
|
||||
ivArray = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]
|
||||
constructor() { }
|
||||
|
||||
encrypt(encryptData, pass) {
|
||||
var text = "Pro-it te espera!!!!";
|
||||
//Creating the Vector Key
|
||||
var iv = CryptoJS.enc.Hex.parse(this.toHexString(this.ivArray));
|
||||
//Encoding the Password in from UTF8 to byte array
|
||||
var Pass = CryptoJS.enc.Utf8.parse(pass);
|
||||
//Encoding the Salt in from UTF8 to byte array
|
||||
var Salt = CryptoJS.enc.Utf8.parse("gabinetedigital");
|
||||
//Creating the key in PBKDF2 format to be used during the decryption
|
||||
var key128Bits1000Iterations = CryptoJS.PBKDF2(Pass.toString(CryptoJS.enc.Utf8), Salt, { keySize: 128 / 32, iterations: 1000 });
|
||||
|
||||
//Decrypting the string contained in cipherParams using the PBKDF2 key
|
||||
var decrypted = CryptoJS.AES.encrypt(encryptData, key128Bits1000Iterations, { mode: CryptoJS.mode.CBC, iv: iv, padding: CryptoJS.pad.Pkcs7 });
|
||||
console.log('AES encrypt',decrypted.toString());
|
||||
|
||||
return decrypted.toString();
|
||||
}
|
||||
|
||||
decrypt(deceyptData,pass) {
|
||||
|
||||
//Creating the Vector Key
|
||||
var iv = CryptoJS.enc.Hex.parse(this.toHexString(this.ivArray));
|
||||
//Encoding the Password in from UTF8 to byte array
|
||||
var Pass = CryptoJS.enc.Utf8.parse(pass);
|
||||
//Encoding the Salt in from UTF8 to byte array
|
||||
var Salt = CryptoJS.enc.Utf8.parse("gabinetedigital");
|
||||
//Creating the key in PBKDF2 format to be used during the decryption
|
||||
var key128Bits1000Iterations = CryptoJS.PBKDF2(Pass.toString(CryptoJS.enc.Utf8), Salt, { keySize: 128 / 32, iterations: 1000 });
|
||||
//Enclosing the test to be decrypted in a CipherParams object as supported by the CryptoJS libarary
|
||||
var cipherParams = CryptoJS.lib.CipherParams.create({
|
||||
ciphertext: CryptoJS.enc.Base64.parse(deceyptData)
|
||||
})
|
||||
|
||||
//Decrypting the string contained in cipherParams using the PBKDF2 key
|
||||
var decrypted = CryptoJS.AES.decrypt(cipherParams, key128Bits1000Iterations, { mode: CryptoJS.mode.CBC, iv: iv, padding: CryptoJS.pad.Pkcs7 });
|
||||
console.log('AES decrypt',decrypted.toString(CryptoJS.enc.Utf8));
|
||||
|
||||
return decrypted.toString(CryptoJS.enc.Utf8);
|
||||
}
|
||||
|
||||
toHexString(byteArray) {
|
||||
return Array.from(byteArray, (value: any) => {
|
||||
return ('0' + (value & 0xFF).toString(16)).slice(-2);
|
||||
}).join('')
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -4,14 +4,14 @@ import { Observable } from 'rxjs';
|
||||
import { HttpClient, HttpHeaders, HttpParams } from '@angular/common/http';
|
||||
import { environment } from 'src/environments/environment';
|
||||
import { AuthService } from '../services/auth.service';
|
||||
import { User } from '../models/user.model';
|
||||
import { LoginUserRespose } from '../models/user.model';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class AttachmentsService {
|
||||
|
||||
loggeduser: User;
|
||||
loggeduser: LoginUserRespose;
|
||||
headers: HttpHeaders;
|
||||
|
||||
constructor(private http: HttpClient, user: AuthService) {
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -4,7 +4,7 @@ import { HttpClient, HttpHeaders, HttpParams } from '@angular/common/http';
|
||||
import { Observable } from 'rxjs';
|
||||
import { environment } from 'src/environments/environment';
|
||||
import { AuthService } from '../services/auth.service';
|
||||
import { User } from '../models/user.model';
|
||||
import { LoginUserRespose } from '../models/user.model';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
@@ -12,7 +12,7 @@ import { User } from '../models/user.model';
|
||||
export class ContactsService {
|
||||
|
||||
authheader = {};
|
||||
loggeduser: User;
|
||||
loggeduser: LoginUserRespose;
|
||||
headers: HttpHeaders;
|
||||
|
||||
constructor(private http: HttpClient, user: AuthService) {
|
||||
|
||||
@@ -4,7 +4,7 @@ import { HttpClient, HttpHeaders, HttpParams } from '@angular/common/http';
|
||||
import { Observable } from 'rxjs';
|
||||
import { environment } from 'src/environments/environment';
|
||||
import { AuthService } from '../services/auth.service';
|
||||
import { User } from '../models/user.model';
|
||||
import { LoginUserRespose } from '../models/user.model';
|
||||
|
||||
|
||||
@Injectable({
|
||||
@@ -13,7 +13,7 @@ import { User } from '../models/user.model';
|
||||
export class EventsService {
|
||||
|
||||
authheader = {};
|
||||
loggeduser: User;
|
||||
loggeduser: LoginUserRespose;
|
||||
headers: HttpHeaders;
|
||||
|
||||
headersPrOficial: HttpHeaders;
|
||||
|
||||
@@ -29,7 +29,7 @@ export class InativityService {
|
||||
|
||||
function resetTimer() {
|
||||
clearTimeout(t);
|
||||
t = setTimeout(userIsNotActive, 60000); // time is in milliseconds
|
||||
t = setTimeout(userIsNotActive, 60000 * 5); // time is in milliseconds
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ import { HttpClient, HttpHeaders, HttpParams } from '@angular/common/http';
|
||||
import { Observable } from 'rxjs';
|
||||
import { environment } from 'src/environments/environment';
|
||||
import { AuthService } from '../services/auth.service';
|
||||
import { User } from '../models/user.model';
|
||||
import { LoginUserRespose } from '../models/user.model';
|
||||
import { OrganicEntity } from 'src/app/models/organic-entity.model';
|
||||
|
||||
@Injectable({
|
||||
@@ -13,7 +13,7 @@ import { OrganicEntity } from 'src/app/models/organic-entity.model';
|
||||
export class OrganicEntityService {
|
||||
|
||||
authheader = {};
|
||||
loggeduser: User;
|
||||
loggeduser: LoginUserRespose;
|
||||
headers: HttpHeaders;
|
||||
|
||||
constructor(private http: HttpClient, user: AuthService) {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { HttpClient, HttpHeaders, HttpParams } from '@angular/common/http';
|
||||
import { AuthService } from '../services/auth.service';
|
||||
import { User } from '../models/user.model';
|
||||
import { LoginUserRespose } from '../models/user.model';
|
||||
import { environment } from 'src/environments/environment';
|
||||
import { Observable } from 'rxjs';
|
||||
import { DocumentSetUpMeeting } from '../models/CallMeeting';
|
||||
@@ -15,7 +15,7 @@ import { GetTasksListType } from '../models/GetTasksListType';
|
||||
export class ProcessesService {
|
||||
|
||||
authheader = {};
|
||||
loggeduser: User;
|
||||
loggeduser: LoginUserRespose;
|
||||
headers: HttpHeaders;
|
||||
|
||||
constructor(private http: HttpClient, user: AuthService) {
|
||||
|
||||
@@ -2,7 +2,7 @@ import { Injectable } from '@angular/core';
|
||||
import { HttpClient, HttpHeaders, HttpParams } from '@angular/common/http';
|
||||
import { environment } from 'src/environments/environment';
|
||||
import { AuthService } from '../services/auth.service';
|
||||
import { User } from '../models/user.model';
|
||||
import { LoginUserRespose } from '../models/user.model';
|
||||
import { Observable, throwError } from 'rxjs';
|
||||
import { catchError } from 'rxjs/operators'
|
||||
import { Publication } from '../models/publication';
|
||||
@@ -13,7 +13,7 @@ import { Publication } from '../models/publication';
|
||||
export class PublicationsService {
|
||||
|
||||
authheader = {};
|
||||
loggeduser: User;
|
||||
loggeduser: LoginUserRespose;
|
||||
headers: HttpHeaders;
|
||||
|
||||
constructor(private http: HttpClient, user: AuthService) {
|
||||
|
||||
@@ -4,7 +4,7 @@ import { Event } from '../models/event.model';
|
||||
import { from, Observable } from 'rxjs';
|
||||
import { environment } from 'src/environments/environment';
|
||||
import { AuthService } from '../services/auth.service';
|
||||
import { User } from '../models/user.model';
|
||||
import { LoginUserRespose } from '../models/user.model';
|
||||
import { EventSearch } from "src/app/models/event-search";
|
||||
import { TopSearch } from 'src/app/models/top-search';
|
||||
|
||||
@@ -14,7 +14,7 @@ import { TopSearch } from 'src/app/models/top-search';
|
||||
export class SearchService {
|
||||
// state
|
||||
authheader = {};
|
||||
loggeduser: User;
|
||||
loggeduser: LoginUserRespose;
|
||||
headers: HttpHeaders;
|
||||
|
||||
categories= Array;
|
||||
|
||||
@@ -32,10 +32,10 @@ export class WebNotificationsService {
|
||||
webconnection() {
|
||||
|
||||
|
||||
MFPPush.initialize({
|
||||
/* MFPPush.initialize({
|
||||
appId: "com.gpr.gabinetedigital",
|
||||
mfpContextRoot: "/mfp",
|
||||
});
|
||||
}); */
|
||||
|
||||
MFPPush.registerDevice()
|
||||
.then((res) => {
|
||||
@@ -72,7 +72,9 @@ async onReceviNotificationWeb() {
|
||||
|
||||
if(message.actionName){
|
||||
//this.notificatinsRoutes(data);
|
||||
console.log("Web notification")
|
||||
} else {
|
||||
console.log("Web notification")
|
||||
//this.toastService.notificationMessage(message.alert,this.notificatinsRoutes, data);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user