2021-07-26 15:19:03 +01:00
|
|
|
import { Component, OnInit } from '@angular/core';
|
|
|
|
|
import { Router } from '@angular/router';
|
|
|
|
|
import { AuthService } from 'src/app/services/auth.service';
|
|
|
|
|
import { 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 { NotificationsService } from 'src/app/services/notifications.service';
|
|
|
|
|
import crypto from 'crypto-js'
|
|
|
|
|
import { LocalstoreService } from 'src/app/store/localstore.service';
|
|
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
|
selector: 'app-inactivity',
|
|
|
|
|
templateUrl: './inactivity.page.html',
|
|
|
|
|
styleUrls: ['./inactivity.page.scss'],
|
|
|
|
|
})
|
|
|
|
|
export class InactivityPage implements OnInit {
|
|
|
|
|
|
|
|
|
|
logstatus: boolean;
|
|
|
|
|
username: string = environment.defaultuser;
|
|
|
|
|
password: string = environment.defaultuserpwd;
|
|
|
|
|
userattempt: UserForm;
|
|
|
|
|
code = []
|
|
|
|
|
|
|
|
|
|
hasPin: boolean
|
|
|
|
|
loginPreference: string
|
|
|
|
|
hasSession = false
|
|
|
|
|
setPin = false
|
|
|
|
|
|
|
|
|
|
constructor(
|
|
|
|
|
private notificatinsservice: NotificationsService,
|
|
|
|
|
private router: Router,
|
|
|
|
|
private authService: AuthService,
|
|
|
|
|
private toastService: ToastService,
|
|
|
|
|
public alertController: AlertController,
|
|
|
|
|
private localstoreService: LocalstoreService
|
|
|
|
|
) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ngOnInit() {
|
|
|
|
|
|
|
|
|
|
let userData = this.localstoreService.get('UserData', {})
|
|
|
|
|
|
|
|
|
|
const loginPreference = userData?.loginPreference
|
|
|
|
|
const pin = userData?.PIN
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async presentAlert(message: string) {
|
|
|
|
|
const alert = await this.alertController.create({
|
|
|
|
|
cssClass: 'my-custom-class',
|
|
|
|
|
header: 'Mensagem do sistema',
|
|
|
|
|
message: message,
|
|
|
|
|
buttons: ['OK']
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
await alert.present();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
getToken() {
|
|
|
|
|
this.notificatinsservice.getAndpostToken(this.username);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async Login() {
|
|
|
|
|
|
2021-08-27 09:48:51 +01:00
|
|
|
|
2021-07-26 15:19:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
setCode(code: string) {
|
|
|
|
|
|
|
|
|
|
if(this.code.length < 4) {
|
|
|
|
|
this.code.push(code)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(this.code.length == 4) {
|
|
|
|
|
|
|
|
|
|
const code = this.code.join('')
|
|
|
|
|
const encrypted = crypto.SHA1(code)
|
|
|
|
|
|
|
|
|
|
if(!this.hasPin) {
|
2021-08-18 15:57:19 +01:00
|
|
|
// console.log('storePin')
|
2021-07-26 15:19:03 +01:00
|
|
|
this.storePin()
|
|
|
|
|
} else {
|
2021-08-18 15:57:19 +01:00
|
|
|
// console.log('pinLogin')
|
2021-07-26 15:19:03 +01:00
|
|
|
this.pinLogin()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
clearCode() {
|
|
|
|
|
this.code =[]
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pinLogin() {
|
|
|
|
|
|
|
|
|
|
const code = this.code.join('')
|
|
|
|
|
const encrypted = crypto.SHA1(code)
|
|
|
|
|
|
|
|
|
|
let userData = this.localstoreService.get('UserData', {})
|
|
|
|
|
const pin = userData?.PIN
|
|
|
|
|
|
|
|
|
|
//if( encrypted == pin) {
|
|
|
|
|
|
|
|
|
|
if( encrypted == this.localstoreService.get('UserData', false)) {
|
|
|
|
|
|
|
|
|
|
//this.toastService.successMessage()
|
|
|
|
|
this.router.navigate(['/home/events']);
|
|
|
|
|
} else {
|
|
|
|
|
this.toastService.badRequest('Pin incorreto')
|
|
|
|
|
this.code = []
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
storePin() {
|
|
|
|
|
|
|
|
|
|
const code = this.code.join('')
|
|
|
|
|
const encrypted = crypto.SHA1(code).toString()
|
|
|
|
|
let userData: Object = this.localstoreService.get('UserData', {})
|
|
|
|
|
|
|
|
|
|
userData['PIN'] = encrypted
|
|
|
|
|
userData['loginPreference'] = 'none'
|
|
|
|
|
|
|
|
|
|
this.localstoreService.set('UserData', userData)
|
|
|
|
|
|
|
|
|
|
this.localstoreService.set('PIN', encrypted)
|
|
|
|
|
|
|
|
|
|
this.router.navigate(['/home/events']);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|