Files
doneit-web/src/app/pages/login/login.page.ts
T

58 lines
1.2 KiB
TypeScript
Raw Normal View History

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';
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 {
logstatus: boolean;
username: string = "";
password: string = "";
userattempt: User;
2020-08-06 14:31:07 +01:00
constructor(
private router: Router,
private authService: AuthService) { }
2020-08-05 15:39:16 +01:00
ngOnInit() {
2020-08-05 15:39:16 +01:00
}
2020-08-06 14:31:07 +01:00
/* Function to validade the login inputs */
validateInput(){
this.userattempt = {
username: this.username,
password: this.password,
domainName: "",
BasicAuthKey: ""
}
2020-08-06 14:31:07 +01:00
return (
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
}
async Login(){
2020-08-07 10:31:33 +01:00
//Go to our home in home/feed.
if(this.validateInput()){
if (await this.authService.login(this.userattempt))
{
this.router.navigate(['/home/events']);
}
else
{
console.log("Não foi possível fazer login");
}
2020-08-07 10:31:33 +01:00
}
else{
console.log("Preencha todos campos");
2020-08-06 14:31:07 +01:00
}
2020-08-05 15:39:16 +01:00
}
}