made some changes

This commit is contained in:
Kayaya
2020-08-06 14:31:07 +01:00
parent d25ebc0d28
commit 4e143a55a4
12 changed files with 142 additions and 115 deletions
+51 -3
View File
@@ -1,5 +1,8 @@
import { Component, OnInit } from '@angular/core';
import { Router } from '@angular/router';
import { AuthService } from 'src/app/services/auth.service';
import { StorageService } from 'src/app/services/storage.service';
import { AuthConnstants } from 'src/app/config/auth-constants';
@Component({
selector: 'app-login',
@@ -8,14 +11,59 @@ import { Router } from '@angular/router';
})
export class LoginPage implements OnInit {
constructor(private router: Router) { }
/* Declare variables */
public postData = {
username: '',
password: '',
domainName: ''
}
constructor(private router: Router, private authService: AuthService, private storageService: StorageService) { }
ngOnInit() {
}
/* Function to validade the login inputs */
validateInput(){
let username = this.postData.username.trim();
let password = this.postData.password.trim();
let domainName = this.postData.domainName.trim();
login(){
return (
this.postData.username &&
this.postData.password &&
username.length > 0
&& password.length > 0
);
}
loginAction(){
//Go to our home in home/feed.
this.router.navigate(['/home/feed']);
/* this.router.navigate(['/home/feed']); */
/* console.log(this.postData); */
if(this.validateInput()){
//Try to login
this.authService.login(this.postData).subscribe((res: any)=> {
/* userData must be in the API results as paratemers otherwise change to the param that is in the API */
if(res.userData){
/* Then we store this information at the staorage service */
this.storageService.store(AuthConnstants.AUTH, res.userData);
/* Then go to home view */
this.router.navigate(['home']);
}
else{
console.log("Os dados inseridos são inválidos");
}
},
/* Write a connection error */
(error: any)=>{
console.log("Erro de conexão com a API.");
}
);
}
else{
//Display an error message
console.log("Preencha todos campos");
}
}
}