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';
|
2020-08-11 12:08:15 +01:00
|
|
|
import axios from "axios";
|
2020-08-19 23:47:11 +01:00
|
|
|
import { HttpClient } from '@angular/common/http';
|
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(
|
|
|
|
|
private httpService: HttpService,
|
|
|
|
|
private storageService: StorageService,
|
2020-08-19 23:47:11 +01:00
|
|
|
private router: Router,
|
|
|
|
|
private http: HttpClient
|
2020-08-06 14:31:07 +01:00
|
|
|
) { }
|
|
|
|
|
|
2020-08-11 12:08:15 +01:00
|
|
|
async login(postData: any): Promise<any> {
|
2020-08-06 14:31:07 +01:00
|
|
|
|
2020-08-11 12:08:15 +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
|
|
|
|
2020-08-11 12:08:15 +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;
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-08-19 14:21:42 +01:00
|
|
|
|
2020-08-11 12:08:15 +01:00
|
|
|
|
|
|
|
|
/* 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-19 23:47:11 +01:00
|
|
|
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);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-06 14:31:07 +01:00
|
|
|
}
|