2021-05-27 16:21:04 +01:00
|
|
|
import { Component, OnInit } from '@angular/core';
|
2021-06-08 15:59:06 +01:00
|
|
|
import { AnimationController, ModalController } from '@ionic/angular';
|
2021-05-28 14:41:56 +01:00
|
|
|
import crypto from 'crypto-js'
|
2021-06-15 15:09:20 +01:00
|
|
|
import { ToastService } from 'src/app/services/toast.service';
|
2021-07-18 20:20:30 +01:00
|
|
|
import { LocalstoreService } from 'src/app/store/localstore.service';
|
2021-05-27 16:21:04 +01:00
|
|
|
@Component({
|
|
|
|
|
selector: 'app-pin',
|
|
|
|
|
templateUrl: './pin.page.html',
|
|
|
|
|
styleUrls: ['./pin.page.scss'],
|
|
|
|
|
})
|
|
|
|
|
export class PinPage implements OnInit {
|
|
|
|
|
|
2021-05-27 21:44:18 +01:00
|
|
|
code = []
|
2021-06-08 15:59:06 +01:00
|
|
|
constructor( private modalController: ModalController,
|
2021-06-15 15:09:20 +01:00
|
|
|
private animationController: AnimationController,
|
2021-07-18 20:20:30 +01:00
|
|
|
private toastService: ToastService,
|
|
|
|
|
private localstoreService: LocalstoreService) { }
|
2021-05-27 16:21:04 +01:00
|
|
|
|
|
|
|
|
ngOnInit() {
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-27 21:44:18 +01:00
|
|
|
setCode(code: string) {
|
|
|
|
|
if(this.code.length < 4) {
|
|
|
|
|
this.code.push(code)
|
2021-05-28 14:41:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(this.code.length == 4) {
|
|
|
|
|
this.save()
|
2021-05-27 21:44:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-28 06:33:30 +01:00
|
|
|
clearCode() {
|
2021-05-27 21:44:18 +01:00
|
|
|
this.code =[]
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-27 22:09:41 +01:00
|
|
|
close() {
|
|
|
|
|
this.modalController.dismiss();
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-28 14:41:56 +01:00
|
|
|
async save() {
|
2021-05-27 22:09:41 +01:00
|
|
|
if(this.code.length == 4) {
|
2021-05-28 16:13:44 +01:00
|
|
|
|
|
|
|
|
this.close()
|
2021-06-15 15:09:20 +01:00
|
|
|
//this.toastService.successMessage()
|
2021-05-28 14:41:56 +01:00
|
|
|
|
|
|
|
|
const code = this.code.join('')
|
|
|
|
|
const encrypted = crypto.SHA1(code)
|
|
|
|
|
|
|
|
|
|
localStorage.setItem('PIN', encrypted)
|
2021-07-18 20:20:30 +01:00
|
|
|
this.localstoreService.set('PIN', encrypted)
|
2021-05-28 14:41:56 +01:00
|
|
|
|
2021-05-27 22:09:41 +01:00
|
|
|
} else {
|
2021-06-15 15:09:20 +01:00
|
|
|
this.toastService.badRequest()
|
2021-05-27 22:09:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-08 15:59:06 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2021-05-27 22:09:41 +01:00
|
|
|
|
2021-05-28 16:53:42 +01:00
|
|
|
}
|