mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-18 20:47:54 +00:00
Autenticação com Basic Auth na classe authservice no método login().
This commit is contained in:
@@ -4,6 +4,7 @@ import { HttpService } from './http.service';
|
||||
import { Router } from '@angular/router';
|
||||
import { Observable } from 'rxjs';
|
||||
import { AuthConnstants } from '../config/auth-constants';
|
||||
import axios from "axios";
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
@@ -16,15 +17,45 @@ export class AuthService {
|
||||
private router: Router
|
||||
) { }
|
||||
|
||||
/* login(postData: any): Observable<any> {
|
||||
return this.httpService.post('login', postData);
|
||||
}
|
||||
async login(postData: any): Promise<any> {
|
||||
|
||||
signup(postData: any): Observable<any> {
|
||||
return this.httpService.post('signup', postData);
|
||||
}
|
||||
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;
|
||||
|
||||
logout(){
|
||||
//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(){
|
||||
this.storageService.removeStorageItem(AuthConnstants.AUTH).then(res =>{
|
||||
this.router.navigate([''])
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user