diff --git a/src/app/pages/login/login.page.ts b/src/app/pages/login/login.page.ts index 2f3ae749e..20ae5bdd3 100644 --- a/src/app/pages/login/login.page.ts +++ b/src/app/pages/login/login.page.ts @@ -80,7 +80,7 @@ export class LoginPage implements OnInit { if (await this.authService.login(this.userattempt)){ this.loginRocketChat(); console.log('Log Gabinete Digital OK'); - this.router.navigate(['/home/events']); + this.router.navigate(['/home/events']);this.presentAlert('1'); } else { @@ -93,6 +93,7 @@ export class LoginPage implements OnInit { this.presentAlert('Por favor, insira o seu nome de utilizador e palavra-passe.'); } } catch (error) { + error this.presentAlert('Ocorreu um erro ao fazer login. Contacte o administrador de sistema. '+ error); } } diff --git a/src/app/services/auth.service.ts b/src/app/services/auth.service.ts index bdb4ca88e..f98c62a8d 100644 --- a/src/app/services/auth.service.ts +++ b/src/app/services/auth.service.ts @@ -7,6 +7,7 @@ import { environment } from 'src/environments/environment'; import { HttpService } from './http.service'; import { BehaviorSubject, Observable } from 'rxjs'; import { AuthConnstants } from '../config/auth-constants'; +import { AlertController } from '@ionic/angular'; @Injectable({ providedIn: 'root' @@ -17,24 +18,51 @@ export class AuthService { private http: HttpClient, private httpService: HttpService, private storageService:StorageService, + public alertController: AlertController, private router:Router ) { } public ValidatedUser:User; + async presentAlert(message:string) { + const alert = await this.alertController.create({ + cssClass: 'my-custom-class', + header: 'Mensagem do sistema', + message: message, + buttons: ['OK'] + }); + + await alert.present(); + } + async login(user: User): Promise { + user.BasicAuthKey = 'Basic ' + btoa(user.domainName + '\\' + user.username + ':' + user.password); //conversão em base64 das credenciais inseridas + const options = { headers: {'Authorization': user.BasicAuthKey }}; + + const service = environment.apiURL + "userauthentication/GetValidateAuth"; let result: boolean | PromiseLike; + this.presentAlert(service); - result = await this.http.get(service, options).toPromise(); + try { + result = await this.http.get(service, options).toPromise(); + + } catch (error) { + this.presentAlert('Erro '+error); + } + + if (result) { + this.presentAlert('7'); + this.ValidatedUser = user; + this.presentAlert('8'); } return result;