mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-18 20:47:54 +00:00
Revisão: Autenticação, Page Events, Page Expediente.
This commit is contained in:
@@ -2,10 +2,10 @@ import { Injectable } from '@angular/core';
|
||||
import { StorageService } from './storage.service';
|
||||
import { HttpService } from './http.service';
|
||||
import { Router } from '@angular/router';
|
||||
import { Observable } from 'rxjs';
|
||||
import { AuthConnstants } from '../config/auth-constants';
|
||||
import axios from "axios";
|
||||
import { HttpClient } from '@angular/common/http';
|
||||
import { User } from '../models/user.model';
|
||||
import { environment } from 'src/environments/environment';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
@@ -15,70 +15,38 @@ export class AuthService {
|
||||
|
||||
|
||||
constructor(
|
||||
private httpService: HttpService,
|
||||
private storageService: StorageService,
|
||||
private router: Router,
|
||||
private http: HttpClient
|
||||
) { }
|
||||
|
||||
async login(postData: any): Promise<any> {
|
||||
public ValidatedUser:User;
|
||||
|
||||
var session_url = 'https://gpr-dev-08.gabinetedigital.local/api/v2.0/me';
|
||||
var credentials = btoa(postData.domainName + '\\' + postData.username + ':' + postData.password); //conversão em base64 das credenciais inseridas
|
||||
var statusresult = -1;
|
||||
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
|
||||
|
||||
//configuração dos headers para autênticação básica, passando as credenciais convertidas em base64
|
||||
var config = {
|
||||
headers: {
|
||||
'Authorization': 'Basic ' + credentials,
|
||||
},
|
||||
};
|
||||
|
||||
await axios.get(session_url, config)
|
||||
.then(function (response) {
|
||||
statusresult = response.status;
|
||||
})
|
||||
.catch(function (error) {
|
||||
if (error.response) {
|
||||
statusresult = error.response.status;
|
||||
}
|
||||
});
|
||||
|
||||
if (statusresult == 200)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
if (statusresult == 401)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
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) {
|
||||
console.log(e);
|
||||
result = false;
|
||||
}
|
||||
|
||||
if (result)
|
||||
{
|
||||
this.ValidatedUser = user;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/* logout(){
|
||||
this.storageService.removeStorageItem(AuthConnstants.AUTH).then(res =>{
|
||||
this.router.navigate([''])
|
||||
})
|
||||
|
||||
} */
|
||||
validateLogin(){
|
||||
const options = { headers: {'Authorization': 'Basic cGF1bG8ucGludG86dGFidGVzdGVAMDA2'}};
|
||||
const url = 'http://gpr-dev-01.gabinetedigital.local/GabineteDigital.Services/api/calendar/ValidateAuth';
|
||||
/* return this.http.get(`${url}`, options); */
|
||||
axios.get(url, options)
|
||||
.then(resp => {
|
||||
if(resp.data)
|
||||
console.log(resp.data);
|
||||
})
|
||||
.catch(err => {
|
||||
// Handle Error Here
|
||||
console.error(err);
|
||||
});
|
||||
logout(){
|
||||
this.ValidatedUser = null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user