1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-12-29 17:38:04 +01:00

convert user service to jslib

This commit is contained in:
Kyle Spearrin 2018-01-09 17:37:40 -05:00
parent 56bde82b41
commit cfbd67060a
7 changed files with 11 additions and 89 deletions

View File

@ -5,6 +5,7 @@ import {
AppIdService,
CryptoService,
TokenService,
UserService,
UtilsService,
} from 'jslib/services';
@ -16,6 +17,7 @@ import {
PlatformUtilsService as PlatformUtilsServiceAbstraction,
StorageService as StorageServiceAbstraction,
TokenService as TokenServiceAbstraction,
UserService as UserServiceAbstraction,
UtilsService as UtilsServiceAbstraction,
} from 'jslib/abstractions';
@ -45,7 +47,6 @@ import PasswordGenerationService from '../services/passwordGeneration.service';
import SettingsService from '../services/settings.service';
import SyncService from '../services/sync.service';
import TotpService from '../services/totp.service';
import UserService from '../services/user.service';
export default class MainBackground {
messagingService: MessagingServiceAbstraction;
@ -59,7 +60,7 @@ export default class MainBackground {
appIdService: AppIdServiceAbstraction;
apiService: ApiServiceAbstraction;
environmentService: EnvironmentService;
userService: UserService;
userService: UserServiceAbstraction;
settingsService: SettingsService;
cipherService: CipherService;
folderService: FolderService;

View File

@ -20,11 +20,11 @@ import {
ApiService,
CryptoService,
StorageService,
UserService,
} from 'jslib/abstractions';
import ConstantsService from './constants.service';
import SettingsService from './settings.service';
import UserService from './user.service';
const Keys = {
ciphersPrefix: 'ciphers_',

View File

@ -1,8 +1,7 @@
import UserService from './user.service';
import {
CryptoService,
StorageService,
UserService,
} from 'jslib/abstractions';
import { CollectionData } from 'jslib/models/data';

View File

@ -1,5 +1,3 @@
import UserService from './user.service';
import { FolderData } from 'jslib/models/data';
import { Folder } from 'jslib/models/domain';
@ -12,6 +10,7 @@ import {
ApiService,
CryptoService,
StorageService,
UserService,
} from 'jslib/abstractions';
const Keys = {

View File

@ -1,6 +1,7 @@
import UserService from './user.service';
import { StorageService } from 'jslib/abstractions';
import {
StorageService,
UserService,
} from 'jslib/abstractions';
const Keys = {
settingsPrefix: 'settings_',

View File

@ -2,13 +2,13 @@ import CipherService from './cipher.service';
import CollectionService from './collection.service';
import FolderService from './folder.service';
import SettingsService from './settings.service';
import UserService from './user.service';
import {
ApiService,
CryptoService,
MessagingService,
StorageService,
UserService,
} from 'jslib/abstractions';
import {

View File

@ -1,78 +0,0 @@
import { StorageService, TokenService } from 'jslib/abstractions';
const Keys = {
userId: 'userId',
userEmail: 'userEmail',
stamp: 'securityStamp',
};
export default class UserService {
userId: string;
email: string;
stamp: string;
constructor(private tokenService: TokenService, private storageService: StorageService) {
}
setUserIdAndEmail(userId: string, email: string): Promise<any> {
this.email = email;
this.userId = userId;
return Promise.all([
this.storageService.save(Keys.userEmail, email),
this.storageService.save(Keys.userId, userId),
]);
}
setSecurityStamp(stamp: string): Promise<any> {
this.stamp = stamp;
return this.storageService.save(Keys.stamp, stamp);
}
async getUserId(): Promise<string> {
if (this.userId != null) {
return this.userId;
}
this.userId = await this.storageService.get<string>(Keys.userId);
return this.userId;
}
async getEmail(): Promise<string> {
if (this.email != null) {
return this.email;
}
this.email = await this.storageService.get<string>(Keys.userEmail);
return this.email;
}
async getSecurityStamp(): Promise<string> {
if (this.stamp != null) {
return this.stamp;
}
this.stamp = await this.storageService.get<string>(Keys.stamp);
return this.stamp;
}
async clear(): Promise<any> {
await Promise.all([
this.storageService.remove(Keys.userId),
this.storageService.remove(Keys.userEmail),
this.storageService.remove(Keys.stamp),
]);
this.userId = this.email = this.stamp = null;
}
async isAuthenticated(): Promise<boolean> {
const token = await this.tokenService.getToken();
if (token == null) {
return false;
}
const userId = await this.getUserId();
return userId != null;
}
}