mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-20 21:35:50 +00:00
Add Pin
This commit is contained in:
@@ -4,20 +4,22 @@ import { AuthService } from 'src/app/services/auth.service';
|
||||
import { User, UserForm } from 'src/app/models/user.model';
|
||||
import { ToastService } from 'src/app/services/toast.service';
|
||||
import { environment } from 'src/environments/environment';
|
||||
import { AlertController } from '@ionic/angular';
|
||||
import { AlertController, ModalController } from '@ionic/angular';
|
||||
import { StorageService } from 'src/app/services/storage.service';
|
||||
import { AuthConnstants } from 'src/app/config/auth-constants';
|
||||
import { PhotoService } from 'src/app/services/photo.service';
|
||||
import { NotificationsService } from 'src/app/services/notifications.service';
|
||||
import { HttpClient, HttpHeaders, HttpParams } from '@angular/common/http';
|
||||
import crypto from 'crypto-js'
|
||||
import { SuccessMessageComponent } from 'src/app/shared/popover/success-message/success-message.component';
|
||||
import { BadRequestComponent } from 'src/app/shared/popover/bad-request/bad-request.component';
|
||||
|
||||
//import { Token } from '../../models/token.model';
|
||||
//import { FCM } from 'cordova-plugin-fcm-with-dependecy-updated/ionic/ngx';
|
||||
|
||||
/* import { Plugins, PushNotification, PushNotificationToken, PushNotificationActionPerformed } from '@capacitor/core';
|
||||
|
||||
const { PushNotifications } = Plugins;
|
||||
*/
|
||||
|
||||
*/
|
||||
|
||||
@Component({
|
||||
selector: 'app-login',
|
||||
@@ -30,6 +32,9 @@ export class LoginPage implements OnInit {
|
||||
username: string = environment.defaultuser;
|
||||
password: string = environment.defaultuserpwd;
|
||||
userattempt: UserForm;
|
||||
code = []
|
||||
|
||||
pin = true
|
||||
|
||||
constructor(
|
||||
private http: HttpClient,
|
||||
@@ -40,14 +45,16 @@ export class LoginPage implements OnInit {
|
||||
private toastService: ToastService,
|
||||
private photoService: PhotoService,
|
||||
public alertController: AlertController,
|
||||
private modalController: ModalController
|
||||
//private fcm: FCM
|
||||
) { }
|
||||
|
||||
ngOnInit() {
|
||||
|
||||
}
|
||||
|
||||
//Function to validade the login inputs
|
||||
validateInput(){
|
||||
validateInput() {
|
||||
return (
|
||||
this.username.trim().length > 0
|
||||
&& this.password.trim().length > 0
|
||||
@@ -71,6 +78,7 @@ export class LoginPage implements OnInit {
|
||||
"user": this.username,
|
||||
"password": this.password,
|
||||
}
|
||||
|
||||
this.authService.loginChat(postData).subscribe((res: any) => {
|
||||
console.log(res.data);
|
||||
this.storageService.store(AuthConnstants.AUTH, res.data);
|
||||
@@ -85,7 +93,6 @@ export class LoginPage implements OnInit {
|
||||
// this.notificatinsservice.getAndpostToken(this.username);
|
||||
}
|
||||
|
||||
|
||||
async Login() {
|
||||
/* try { */
|
||||
//Go to our home in home/feed.
|
||||
@@ -113,4 +120,69 @@ export class LoginPage implements OnInit {
|
||||
this.presentAlert('Por favor, insira o seu nome de utilizador e palavra-passe.');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
setCode(code: string) {
|
||||
if(this.code.length < 4) {
|
||||
this.code.push(code)
|
||||
}
|
||||
|
||||
if(this.code.length == 4) {
|
||||
this.pinLogin()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
clearCode() {
|
||||
this.code =[]
|
||||
}
|
||||
|
||||
pinLogin() {
|
||||
|
||||
const code = this.code.join('')
|
||||
const encrypted = crypto.SHA1(code)
|
||||
|
||||
if( encrypted == localStorage.getItem('PIN')) {
|
||||
this.successMessage()
|
||||
} else {
|
||||
this.badRequest()
|
||||
this.code = []
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
async successMessage(message?: string) {
|
||||
|
||||
const modal = await this.modalController.create({
|
||||
component: SuccessMessageComponent,
|
||||
componentProps: {
|
||||
message: message || 'Processo efetuado' ,
|
||||
},
|
||||
cssClass: 'modal modal-desktop'
|
||||
});
|
||||
|
||||
modal.present()
|
||||
|
||||
setTimeout(()=>{
|
||||
this.router.navigate(['/home/events']);
|
||||
modal.dismiss()
|
||||
},3000)
|
||||
|
||||
}
|
||||
|
||||
async badRequest(message?: string) {
|
||||
const modal = await this.modalController.create({
|
||||
component: BadRequestComponent,
|
||||
componentProps: {
|
||||
message: message || 'Processo não efetuado' ,
|
||||
},
|
||||
cssClass: 'modal modal-desktop'
|
||||
});
|
||||
|
||||
modal.present()
|
||||
|
||||
setTimeout(()=>{
|
||||
modal.dismiss()
|
||||
},3000)
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user