Last active
August 26, 2020 09:02
-
-
Save bioyeneye/953a52d396fc0880923f5fe98430fd1f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@IonicPage() | |
@Component({ | |
selector: 'page-dashboard-design', | |
templateUrl: 'dashboard-design.html', | |
}) | |
export class DashboardDesignPage { | |
constructor( | |
private userSessionManager: UserSessionManager | |
} | |
ionViewDidLoad() { | |
this.userSessionManager.getFingerForLogin().then((result) => { | |
let message = "You can change this later in Settings"; | |
let subTitle = "Enable fingerprint for login and authorizing transactions."; | |
this.showFingerPrintAlert(subTitle, message); | |
}); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export interface IStorageProvider { | |
get(key: string) : Promise<string>; | |
set(key: string, value: string): boolean; | |
clearKey(key: string) : boolean; | |
clear():void; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import {Injectable} from '@angular/core'; | |
import {Storage} from "@ionic/storage"; | |
import {IStorageProvider} from "../interface/istorage-provider"; | |
export const StorageProviderName = 'IStorageProvider'; | |
export const StorageParameters = { | |
HAS_FINGERPRINT: "hasFingerprint", | |
}; | |
@Injectable() | |
export class StorageProvider implements IStorageProvider { | |
keys: string[] = ['ExtraData', 'IsUserLoggedIn', 'Local_dp_part', 'LoggedInName', 'LoggedInNumber', 'refresh_token', 'token', 'UserPprogress', 'maybelater']; | |
constructor(private storage: Storage) { | |
// this.storage.keys().then((data) => { | |
// this.keys = data; | |
// }); | |
} | |
clear(): void { | |
this.storage.clear(); | |
} | |
clearKey(key: string): boolean { | |
this.storage.remove(key); | |
// if (this.giveKey().indexOf(key) > -1) { | |
// this.storage.remove(key).then((data) => { | |
// return true; | |
// }).catch((error) => { | |
// return false | |
// }) | |
// } | |
// return false; | |
return true; | |
} | |
async get(key: string): Promise<string> { | |
let result; | |
try { | |
result = await this.storage.get(key); | |
} catch (e) { | |
throw e; | |
} | |
return result; | |
} | |
set(key: string, value: string): boolean { | |
this.storage.set(key, value).then((onloadeddata) => { | |
return true; | |
}, () => { | |
}).catch((error) => { | |
//log | |
return false; | |
}); | |
return false; | |
} | |
setPromise(key: string, value: string) { | |
return this.storage.set(key, value); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Injectable() | |
export class UserSessionManager implements IUserSessionManager { | |
constructor(private storageProvider: StorageProvider | |
) { | |
this.storageProvider.get(StorageParameters.LOGGED_IN_USER).then((data) => { | |
this.loggedInUser = JSON.parse(data) as User; | |
}); | |
} | |
async getFingerForLogin(): Promise<any> { | |
return await this.storageProvider.get(StorageParameters.FINGERPRINT_FOR_LOGIN); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment