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

103 lines
2.7 KiB
TypeScript

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';
import { ToastController } from '@ionic/angular';
@Component({
selector: 'app-login',
templateUrl: './login.page.html',
styleUrls: ['./login.page.scss'],
})
export class LoginPage implements OnInit {
/* Declare variables */
public postData = {
username: '',
password: '',
domainName: ''
}
constructor(
private router: Router,
private authService: AuthService,
private storageService: StorageService,
toastController: ToastController
) { }
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();
return (
this.postData.username &&
this.postData.password &&
username.length > 0
&& password.length > 0
);
}
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(){/*
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");
}*/
}
async simpleLogin(){
//Go to our home in home/feed.
if(this.validateInput()){
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");
}
}
else{
console.log("Preencha todos campos");
}
}
}