mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-18 12:37:53 +00:00
save
This commit is contained in:
+1
-1
@@ -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="" />
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user