2020-08-05 15:39:16 +01:00
|
|
|
import { Component, OnInit } from '@angular/core';
|
|
|
|
|
import { Router } from '@angular/router';
|
2020-08-06 14:31:07 +01:00
|
|
|
import { AuthService } from 'src/app/services/auth.service';
|
2020-08-21 00:22:51 +01:00
|
|
|
import { User } from 'src/app/models/user.model';
|
|
|
|
|
|
2020-08-05 15:39:16 +01:00
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
|
selector: 'app-login',
|
|
|
|
|
templateUrl: './login.page.html',
|
|
|
|
|
styleUrls: ['./login.page.scss'],
|
|
|
|
|
})
|
|
|
|
|
export class LoginPage implements OnInit {
|
|
|
|
|
|
2020-08-19 23:47:11 +01:00
|
|
|
logstatus: boolean;
|
2020-08-21 00:22:51 +01:00
|
|
|
username: string = "";
|
|
|
|
|
password: string = "";
|
|
|
|
|
userattempt: User;
|
2020-08-06 14:31:07 +01:00
|
|
|
|
2020-08-11 04:11:42 +01:00
|
|
|
constructor(
|
|
|
|
|
private router: Router,
|
2020-08-21 00:22:51 +01:00
|
|
|
private authService: AuthService) { }
|
2020-08-05 15:39:16 +01:00
|
|
|
|
|
|
|
|
ngOnInit() {
|
2020-08-21 00:22:51 +01:00
|
|
|
|
2020-08-05 15:39:16 +01:00
|
|
|
}
|
2020-08-06 14:31:07 +01:00
|
|
|
/* Function to validade the login inputs */
|
|
|
|
|
validateInput(){
|
2020-08-21 00:22:51 +01:00
|
|
|
this.userattempt = {
|
|
|
|
|
username: this.username,
|
|
|
|
|
password: this.password,
|
|
|
|
|
domainName: "",
|
|
|
|
|
BasicAuthKey: ""
|
|
|
|
|
}
|
2020-08-06 14:31:07 +01:00
|
|
|
|
|
|
|
|
return (
|
2020-08-21 00:22:51 +01:00
|
|
|
this.username.trim().length > 0
|
|
|
|
|
&& this.password.trim().length > 0
|
2020-08-06 14:31:07 +01:00
|
|
|
);
|
2020-08-07 10:31:33 +01:00
|
|
|
}
|
|
|
|
|
|
2020-08-21 00:22:51 +01:00
|
|
|
async Login(){
|
2020-08-07 10:31:33 +01:00
|
|
|
//Go to our home in home/feed.
|
|
|
|
|
if(this.validateInput()){
|
2020-08-21 00:22:51 +01:00
|
|
|
if (await this.authService.login(this.userattempt))
|
2020-08-11 12:07:13 +01:00
|
|
|
{
|
2020-08-21 00:22:51 +01:00
|
|
|
this.router.navigate(['/home/events']);
|
2020-08-11 12:07:13 +01:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
console.log("Não foi possível fazer login");
|
2020-08-21 00:22:51 +01:00
|
|
|
}
|
2020-08-07 10:31:33 +01:00
|
|
|
}
|
|
|
|
|
else{
|
2020-08-11 12:07:13 +01:00
|
|
|
console.log("Preencha todos campos");
|
2020-08-06 14:31:07 +01:00
|
|
|
}
|
2020-08-05 15:39:16 +01:00
|
|
|
}
|
|
|
|
|
}
|