This commit is contained in:
tiago.kayaya
2021-02-25 10:25:46 +01:00
parent c507c1cbd6
commit ff953094a9
2 changed files with 13 additions and 55 deletions
+1 -1
View File
@@ -134,7 +134,7 @@
</mfp:windows10>
<mfp:appChecksum>0</mfp:appChecksum>
</mfp:windows>
<mfp:platformVersion>8.0.0.00-20210201-110557</mfp:platformVersion>
<mfp:platformVersion>8.0.0.00-20210214-154410</mfp:platformVersion>
<mfp:clientCustomInit enabled="false" />
<mfp:server runtime="mfp" url="http://10.0.0.1:9080" />
<mfp:serverUri url="" />
+12 -54
View File
@@ -1,5 +1,5 @@
import { Injectable } from '@angular/core';
/* import { StorageService } from './storage.service'; */
import { StorageService } from './storage.service';
import { Router } from '@angular/router';
import { HttpClient, HttpHeaders, HttpParams } from '@angular/common/http';
import { User } from '../models/user.model';
@@ -7,9 +7,6 @@ import { environment } from 'src/environments/environment';
import { HttpService } from './http.service';
import { BehaviorSubject, Observable } from 'rxjs';
import { AuthConnstants } from '../config/auth-constants';
import { AlertService } from './alert.service';
import { map } from 'rxjs/operators';
import { Storage } from '@ionic/storage';
@Injectable({
providedIn: 'root'
@@ -19,22 +16,18 @@ export class AuthService {
userId$ = new BehaviorSubject<any>('');
headers: HttpHeaders;
opts:any;
rs:any;
constructor(
private http: HttpClient,
private httpService: HttpService,
/* private storageService:StorageService, */
private router:Router,
private alertCrontroller: AlertService,
private storage: Storage,
private storageService:StorageService,
private router:Router
) {
this.headers = new HttpHeaders();
}
public ValidatedUser:User;
async login(user: User) {
this.alertCrontroller.presentAlert('1');
async login(user: User): Promise<boolean> {
user.BasicAuthKey = 'Basic ' + btoa(user.username + '@' + user.domainName + ':' + user.password); //conversão em base64 das credenciais inseridas
const options = { headers: {'Authorization': user.BasicAuthKey }};
@@ -47,58 +40,23 @@ export class AuthService {
let result: boolean | PromiseLike<boolean>;
let response: any;
/* this.alertCrontroller.presentAlert('2');
this.http.get('http://jsonplaceholder.typicode.com/todos/1');
this.alertCrontroller.presentAlert('2.1');
this.http.get('https://jsonplaceholder.typicode.com/todos/1');
this.alertCrontroller.presentAlert('2.2');
var that = this; */
await this.http.get<boolean>(service, options).subscribe(res=>{
//this.alertCrontroller.presentAlert('3.1');
result = res;
this.storage.set('login', res);
if (result){
//this.alertCrontroller.presentAlert('4');
this.ValidatedUser = user;
//this.storageService.store(AuthConnstants.USER, response);
}
});
//this.alertCrontroller.presentAlert('3');
result = await this.http.get<boolean>(service, options).toPromise();
response = await this.http.post<any>(environment.apiURL + "UserAuthentication/Login", '', this.opts).toPromise();
console.log(response);
/* this.http.post(environment.apiURL + "UserAuthentication/Login", '', this.opts).subscribe(res=>{
this.storageService.store(AuthConnstants.USER, res);
this.ValidatedUser = user;
response = user;
console.log(user);
}); */
/* this.rs = this.storage.get('name').toPromise()
.then((val) => {
return val;
}); */
if (result)
{
this.ValidatedUser = user;
//this.storageService.store(AuthConnstants.USER, response);
}
return result;
}
async get(key: string): Promise<any> {
try {
const result = await this.storage.get(key);
console.log('storageGET: ' + key + ': ' + result);
if (result != null) {
return result;
}
return null;
} catch (reason) {
console.log(reason);
return null;
}
}
logout(){
this.ValidatedUser = null;
}