diff --git a/src/app/pages/login/login.page.ts b/src/app/pages/login/login.page.ts index e8d57231e..639dfef51 100644 --- a/src/app/pages/login/login.page.ts +++ b/src/app/pages/login/login.page.ts @@ -12,6 +12,7 @@ import { NotificationsService } from 'src/app/services/notifications.service'; import { HttpClient, HttpHeaders, HttpParams } from '@angular/common/http'; import { Token } from '../../models/token.model'; import { AlertService } from 'src/app/services/alert.service'; +import { Storage } from '@ionic/storage'; /* import { Plugins, PushNotification, PushNotificationToken, PushNotificationActionPerformed } from '@capacitor/core'; @@ -40,7 +41,8 @@ export class LoginPage implements OnInit { private toastService: ToastService, private photoService: PhotoService, public alertController: AlertController, - private alertService: AlertService,) { } + private alertService: AlertService, + private storage: Storage,) { } ngOnInit() { @@ -125,7 +127,23 @@ export class LoginPage implements OnInit { domainName: environment.domain, BasicAuthKey: "" } - if (await this.authService.login(this.userattempt)) { + await this.authService.login(this.userattempt); + this.storage.get('login').then((login)=>{ + if (login) { + this.alertService.presentAlert('5'); + this.loginRocketChat(); + //this.storeUserIdANdToken(); + + this.router.navigate(['/home/events']); + } + else { + //this.toastService.presentToast('Não foi possível fazer login"'); + this.presentAlert('O nome de utilizador e palavra-passe estão incorretas ou verifique a sua conexão com a internet e volte a tentar.'); + } + + }); + + /* if (await this.authService.login(this.userattempt)) { this.alertService.presentAlert('5'); this.loginRocketChat(); //this.storeUserIdANdToken(); @@ -135,7 +153,7 @@ export class LoginPage implements OnInit { else { //this.toastService.presentToast('Não foi possível fazer login"'); this.presentAlert('O nome de utilizador e palavra-passe estão incorretas ou verifique a sua conexão com a internet e volte a tentar.'); - } + } */ } else { //this.toastService.presentToast('Preencha todos campos'); diff --git a/src/app/services/auth.service.ts b/src/app/services/auth.service.ts index 8f4003ba9..948d36328 100644 --- a/src/app/services/auth.service.ts +++ b/src/app/services/auth.service.ts @@ -32,9 +32,8 @@ export class AuthService { } public ValidatedUser:User; - public ValidatedUser2:any; - async login(user: User): Promise { + async login(user: User) { this.alertCrontroller.presentAlert('1'); user.BasicAuthKey = 'Basic ' + btoa(user.username + '@' + user.domainName + ':' + user.password); //conversão em base64 das credenciais inseridas @@ -48,34 +47,27 @@ export class AuthService { let result: boolean | PromiseLike; let response: any; - this.alertCrontroller.presentAlert('2'); + /* 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; + var that = this; */ await this.http.get(service, options).subscribe(res=>{ - this.alertCrontroller.presentAlert('3.1'); + //this.alertCrontroller.presentAlert('3.1'); result = res; this.storage.set('login', res); - - - return result; - if (result) - { - this.alertCrontroller.presentAlert('4'); + if (result){ + //this.alertCrontroller.presentAlert('4'); this.ValidatedUser = user; //this.storageService.store(AuthConnstants.USER, response); } }); - this.storage.get('name').then((val) => { - console.log('Your age is', val); - }); - this.alertCrontroller.presentAlert('3'); + //this.alertCrontroller.presentAlert('3'); response = await this.http.post(environment.apiURL + "UserAuthentication/Login", '', this.opts).toPromise(); console.log(response); @@ -90,17 +82,7 @@ export class AuthService { .then((val) => { return val; }); */ - - let t = this.get('name'); - - console.log(this.ValidatedUser2); - - - - console.log(this.rs.map(responce=>responce.json()).toPromise()); - - return false; } async get(key: string): Promise { @@ -108,8 +90,7 @@ export class AuthService { const result = await this.storage.get(key); console.log('storageGET: ' + key + ': ' + result); if (result != null) { - this.ValidatedUser2 = result; - return result; + return result; } return null; } catch (reason) {