Files
doneit-web/src/app/services/auth.service.ts
T

66 lines
1.8 KiB
TypeScript
Raw Normal View History

2020-08-06 14:31:07 +01:00
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";
2020-08-06 14:31:07 +01:00
@Injectable({
providedIn: 'root'
})
export class AuthService {
constructor(
private httpService: HttpService,
private storageService: StorageService,
private router: Router
) { }
async login(postData: any): Promise<any> {
2020-08-06 14:31:07 +01:00
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;
2020-08-06 14:31:07 +01:00
//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;
}
}
/* logout(){
2020-08-06 14:31:07 +01:00
this.storageService.removeStorageItem(AuthConnstants.AUTH).then(res =>{
this.router.navigate([''])
})
2020-08-07 10:31:33 +01:00
} */
2020-08-06 14:31:07 +01:00
}