mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-19 04:57:52 +00:00
made some changes
This commit is contained in:
@@ -6,18 +6,18 @@
|
||||
<ion-list>
|
||||
<ion-item>
|
||||
<ion-label position="stacked">Username</ion-label>
|
||||
<ion-input type="text"></ion-input>
|
||||
<ion-input type="text" name="username" [(ngModel)]="postData.username"></ion-input>
|
||||
</ion-item>
|
||||
<ion-item>
|
||||
<ion-label position="stacked">Password</ion-label>
|
||||
<ion-input type="password"></ion-input>
|
||||
<ion-input type="password" name="password" [(ngModel)]="postData.password"></ion-input>
|
||||
</ion-item>
|
||||
<ion-item>
|
||||
<ion-label position="stacked">Domínio</ion-label>
|
||||
<ion-input type="text"></ion-input>
|
||||
<ion-input type="text" name="domainName" [(ngModel)]="postData.domainName"></ion-input>
|
||||
</ion-item>
|
||||
|
||||
<ion-button expand="block" shape="round" color="primary" (click)="login()">Entrar</ion-button>
|
||||
<ion-button expand="block" shape="round" color="primary" (click)="loginAction()">Entrar</ion-button>
|
||||
|
||||
<ion-item lines="none">
|
||||
<a routerLink="/signup">Criar conta</a>
|
||||
|
||||
@@ -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");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user