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

104 lines
2.7 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 { StorageService } from 'src/app/services/storage.service';
import { AuthConnstants } from 'src/app/config/auth-constants';
import { ToastController } from '@ionic/angular';
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-06 14:31:07 +01:00
/* Declare variables */
public postData = {
username: '',
password: '',
domainName: ''
}
constructor(
private router: Router,
private authService: AuthService,
private storageService: StorageService,
toastController: ToastController
) { }
2020-08-05 15:39:16 +01:00
ngOnInit() {
}
2020-08-06 14:31:07 +01:00
/* 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();
return (
this.postData.username &&
this.postData.password &&
username.length > 0
&& password.length > 0
);
}
2020-08-05 15:39:16 +01:00
2020-08-07 10:31:33 +01:00
loginRequest(){
/* axios.get('https://gpr-dev-08.gabinetedigital.local/api/v2.0/me/calendarview?startDateTime=2014-10-01T01:00:00&endDateTime=2020-10-31T23:00:00')
.then(response => {
console.log(response.data.url);
console.log(response.data.explanation);
})
.catch(error => {
console.log(error);
}); */
}
loginAction(){/*
2020-08-06 14:31:07 +01:00
if(this.validateInput()){
//Try to login
this.authService.login(this.postData).subscribe((res: any)=> {
2020-08-07 10:31:33 +01:00
//userData must be in the API results as paratemers otherwise change to the param that is in the API
2020-08-06 14:31:07 +01:00
if(res.userData){
2020-08-07 10:31:33 +01:00
//Then we store this information at the staorage service
2020-08-06 14:31:07 +01:00
this.storageService.store(AuthConnstants.AUTH, res.userData);
2020-08-07 10:31:33 +01:00
//Then go to home view
2020-08-06 14:31:07 +01:00
this.router.navigate(['home']);
}
else{
console.log("Os dados inseridos são inválidos");
}
},
2020-08-07 10:31:33 +01:00
///Write a connection error
2020-08-06 14:31:07 +01:00
(error: any)=>{
console.log("Erro de conexão com a API.");
}
);
}
else{
//Display an error message
console.log("Preencha todos campos");
2020-08-07 10:31:33 +01:00
}*/
}
async simpleLogin(){
2020-08-07 10:31:33 +01:00
//Go to our home in home/feed.
2020-08-07 10:31:33 +01:00
if(this.validateInput()){
this.router.navigate(['/home/events']);
/* if (await this.authService.login(this.postData))
{
this.router.navigate(['/home/feed']);
console.log(this.postData);
}
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
}
}