2019-11-12 12:14:05 +00:00
|
|
|
// Copyright (C) 2019 Storj Labs, Inc.
|
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
2020-02-14 15:35:10 +00:00
|
|
|
/**
|
|
|
|
* LocalData exposes methods to manage local storage.
|
|
|
|
*/
|
2019-11-12 12:14:05 +00:00
|
|
|
export class LocalData {
|
|
|
|
private static userId: string = 'userId';
|
|
|
|
private static selectedProjectId: string = 'selectedProjectId';
|
2021-02-24 23:56:25 +00:00
|
|
|
private static userIdPassSalt: string = 'userIdPassSalt';
|
2019-11-12 12:14:05 +00:00
|
|
|
|
|
|
|
public static getUserId(): string | null {
|
|
|
|
return localStorage.getItem(LocalData.userId);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static setUserId(id: string): void {
|
|
|
|
localStorage.setItem(LocalData.userId, id);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static removeUserId(): void {
|
|
|
|
localStorage.removeItem(LocalData.userId);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static getSelectedProjectId(): string | null {
|
|
|
|
return localStorage.getItem(LocalData.selectedProjectId);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static setSelectedProjectId(id: string): void {
|
|
|
|
localStorage.setItem(LocalData.selectedProjectId, id);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static removeSelectedProjectId(): void {
|
|
|
|
localStorage.removeItem(LocalData.selectedProjectId);
|
|
|
|
}
|
2021-02-24 23:56:25 +00:00
|
|
|
|
|
|
|
public static getUserIDPassSalt(): UserIDPassSalt | null {
|
|
|
|
const data: string | null = localStorage.getItem(LocalData.userIdPassSalt);
|
|
|
|
if (data) {
|
|
|
|
const parsed = JSON.parse(data);
|
|
|
|
|
|
|
|
return new UserIDPassSalt(parsed.userId, parsed.passwordHash, parsed.salt);
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static setUserIDPassSalt(id: string, passwordHash: string, salt: string): void {
|
|
|
|
const data = new UserIDPassSalt(id, passwordHash, salt);
|
|
|
|
|
|
|
|
localStorage.setItem(LocalData.userIdPassSalt, JSON.stringify(data));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* UserIDPassSalt is an entity holding user id, password hash and salt to be stored in local storage.
|
|
|
|
*/
|
|
|
|
export class UserIDPassSalt {
|
|
|
|
public constructor(
|
|
|
|
public userId: string = '',
|
|
|
|
public passwordHash: string = '',
|
|
|
|
public salt: string = '',
|
|
|
|
) {}
|
2019-11-12 12:14:05 +00:00
|
|
|
}
|