mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-19 21:06:06 +00:00
add inactivity page
This commit is contained in:
@@ -0,0 +1,94 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { localstoreService } from './localstore.service'
|
||||
import { SHA1 } from 'crypto-js'
|
||||
import { UserSession } from '../models/user.model';
|
||||
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class SessionService {
|
||||
|
||||
// main data
|
||||
private _user = new UserSession()
|
||||
// local storage keyName
|
||||
private keyName: string;
|
||||
private _needTovalidateUser = false
|
||||
|
||||
constructor() {
|
||||
|
||||
this.keyName = (SHA1(this.constructor.name)).toString()
|
||||
let restore = localstoreService.get(this.keyName, {})
|
||||
this._user = restore.user || new UserSession()
|
||||
|
||||
}
|
||||
|
||||
get user(): UserSession {
|
||||
return this._user || new UserSession()
|
||||
}
|
||||
|
||||
get exist() {
|
||||
let restore = localstoreService.get(this.keyName, {})
|
||||
let user: UserSession = restore.user
|
||||
if(user) {
|
||||
if(user.Profile) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
setLoginPreference(loginPreference: 'None' | 'Password' | 'Pin' | null) {
|
||||
this._user.LoginPreference = loginPreference
|
||||
this.save()
|
||||
}
|
||||
|
||||
setPin(pin: string) {
|
||||
this._user.PIN = SHA1(pin).toString()
|
||||
this.save()
|
||||
}
|
||||
|
||||
validatePin(pin: string) {
|
||||
return this._user.PIN == SHA1(pin).toString()
|
||||
}
|
||||
|
||||
needTovalidateUser() {
|
||||
return this._user.Inativity
|
||||
}
|
||||
|
||||
setInativity(value: boolean) {
|
||||
this._user.Inativity = value
|
||||
this.save()
|
||||
}
|
||||
|
||||
get hasPin() {
|
||||
|
||||
if(!this._user.PIN) {
|
||||
return false
|
||||
}
|
||||
return this._user.PIN.length >= 2
|
||||
}
|
||||
|
||||
reset(user) {
|
||||
this._user = user
|
||||
|
||||
this.setInativity(true)
|
||||
this.save()
|
||||
}
|
||||
|
||||
delete() {
|
||||
localstoreService.delete(this.keyName)
|
||||
}
|
||||
|
||||
private save() {
|
||||
|
||||
localstoreService.set(this.keyName, {
|
||||
user: this._user
|
||||
})
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
export const SessionStore = new SessionService()
|
||||
Reference in New Issue
Block a user