mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-18 20:47:54 +00:00
52 lines
1.4 KiB
TypeScript
52 lines
1.4 KiB
TypeScript
import { Injectable } from '@angular/core';
|
|
import { StorageService } from './storage.service';
|
|
import { HttpService } from './http.service';
|
|
import { Router } from '@angular/router';
|
|
import { AuthConnstants } from '../config/auth-constants';
|
|
import { HttpClient } from '@angular/common/http';
|
|
import { User } from '../models/user.model';
|
|
import { environment } from 'src/environments/environment';
|
|
|
|
@Injectable({
|
|
providedIn: 'root'
|
|
})
|
|
export class AuthService {
|
|
|
|
|
|
|
|
constructor(
|
|
private storageService: StorageService,
|
|
private router: Router,
|
|
private http: HttpClient
|
|
) { }
|
|
|
|
public ValidatedUser:User;
|
|
|
|
async login(user: User): Promise<boolean> {
|
|
user.domainName = environment.domain;
|
|
user.BasicAuthKey = 'Basic ' + btoa(user.domainName + '\\' + user.username + ':' + user.password); //conversão em base64 das credenciais inseridas
|
|
|
|
const options = { headers: {'Authorization': user.BasicAuthKey }};
|
|
const service = environment.apiURL + "userauthentication/GetValidateAuth";
|
|
|
|
let result: boolean | PromiseLike<boolean>;
|
|
|
|
try {
|
|
result = await this.http.get<boolean>(service, options).toPromise();
|
|
} catch(e) {
|
|
result = false;
|
|
}
|
|
|
|
if (result)
|
|
{
|
|
this.ValidatedUser = user;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
logout(){
|
|
this.ValidatedUser = null;
|
|
}
|
|
}
|