1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-16 08:13:42 +00:00

two-step login pages

This commit is contained in:
Kyle Spearrin
2018-06-11 11:43:10 -04:00
parent 4df4f57de3
commit a6aef345d5
17 changed files with 233 additions and 151 deletions

View File

@@ -5,10 +5,11 @@ export class HtmlStorageService implements StorageService {
private localStorageKeys = new Set(['appId', 'anonymousAppId', 'rememberedEmail',
ConstantsService.disableFaviconKey, ConstantsService.lockOptionKey, ConstantsService.localeKey,
ConstantsService.lockOptionKey]);
private localStorageStartsWithKeys = ['twoFactorToken_'];
get<T>(key: string): Promise<T> {
let json: string = null;
if (this.localStorageKeys.has(key)) {
if (this.isLocalStorage(key)) {
json = window.localStorage.getItem(key);
} else {
json = window.sessionStorage.getItem(key);
@@ -26,7 +27,7 @@ export class HtmlStorageService implements StorageService {
}
const json = JSON.stringify(obj);
if (this.localStorageKeys.has(key)) {
if (this.isLocalStorage(key)) {
window.localStorage.setItem(key, json);
} else {
window.sessionStorage.setItem(key, json);
@@ -35,11 +36,23 @@ export class HtmlStorageService implements StorageService {
}
remove(key: string): Promise<any> {
if (this.localStorageKeys.has(key)) {
if (this.isLocalStorage(key)) {
window.localStorage.removeItem(key);
} else {
window.sessionStorage.removeItem(key);
}
return Promise.resolve();
}
private isLocalStorage(key: string): boolean {
if (this.localStorageKeys.has(key)) {
return true;
}
for (const swKey of this.localStorageStartsWithKeys) {
if (key.startsWith(swKey)) {
return true;
}
}
return false;
}
}