2020-08-06 14:31:07 +01:00
|
|
|
import { Injectable } from '@angular/core';
|
|
|
|
|
import { StorageService } from './storage.service';
|
|
|
|
|
import { Router } from '@angular/router';
|
2020-08-19 23:47:11 +01:00
|
|
|
import { HttpClient } from '@angular/common/http';
|
2020-08-21 00:22:51 +01:00
|
|
|
import { User } from '../models/user.model';
|
|
|
|
|
import { environment } from 'src/environments/environment';
|
2020-08-06 14:31:07 +01:00
|
|
|
|
|
|
|
|
@Injectable({
|
|
|
|
|
providedIn: 'root'
|
|
|
|
|
})
|
|
|
|
|
export class AuthService {
|
|
|
|
|
|
2020-08-19 23:47:11 +01:00
|
|
|
|
|
|
|
|
|
2020-08-06 14:31:07 +01:00
|
|
|
constructor(
|
2020-08-19 23:47:11 +01:00
|
|
|
private http: HttpClient
|
2020-08-06 14:31:07 +01:00
|
|
|
) { }
|
|
|
|
|
|
2020-08-21 00:22:51 +01:00
|
|
|
public ValidatedUser:User;
|
2020-08-06 14:31:07 +01:00
|
|
|
|
2020-08-21 00:22:51 +01:00
|
|
|
async login(user: User): Promise<boolean> {
|
|
|
|
|
user.BasicAuthKey = 'Basic ' + btoa(user.domainName + '\\' + user.username + ':' + user.password); //conversão em base64 das credenciais inseridas
|
2020-08-06 14:31:07 +01:00
|
|
|
|
2020-08-21 00:22:51 +01:00
|
|
|
const options = { headers: {'Authorization': user.BasicAuthKey }};
|
|
|
|
|
const service = environment.apiURL + "userauthentication/GetValidateAuth";
|
|
|
|
|
|
|
|
|
|
let result: boolean | PromiseLike<boolean>;
|
|
|
|
|
|
2020-08-27 10:23:23 +01:00
|
|
|
result = await this.http.get<boolean>(service, options).toPromise();
|
2020-08-11 12:08:15 +01:00
|
|
|
|
2020-08-21 00:22:51 +01:00
|
|
|
if (result)
|
|
|
|
|
{
|
|
|
|
|
this.ValidatedUser = user;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
2020-08-06 14:31:07 +01:00
|
|
|
|
2020-08-21 00:22:51 +01:00
|
|
|
logout(){
|
|
|
|
|
this.ValidatedUser = null;
|
2020-08-19 23:47:11 +01:00
|
|
|
}
|
2020-08-06 14:31:07 +01:00
|
|
|
}
|