mirror of
https://github.com/bitwarden/browser.git
synced 2025-01-16 20:21:31 +01:00
convert user service to jslib
This commit is contained in:
parent
56bde82b41
commit
cfbd67060a
@ -5,6 +5,7 @@ import {
|
|||||||
AppIdService,
|
AppIdService,
|
||||||
CryptoService,
|
CryptoService,
|
||||||
TokenService,
|
TokenService,
|
||||||
|
UserService,
|
||||||
UtilsService,
|
UtilsService,
|
||||||
} from 'jslib/services';
|
} from 'jslib/services';
|
||||||
|
|
||||||
@ -16,6 +17,7 @@ import {
|
|||||||
PlatformUtilsService as PlatformUtilsServiceAbstraction,
|
PlatformUtilsService as PlatformUtilsServiceAbstraction,
|
||||||
StorageService as StorageServiceAbstraction,
|
StorageService as StorageServiceAbstraction,
|
||||||
TokenService as TokenServiceAbstraction,
|
TokenService as TokenServiceAbstraction,
|
||||||
|
UserService as UserServiceAbstraction,
|
||||||
UtilsService as UtilsServiceAbstraction,
|
UtilsService as UtilsServiceAbstraction,
|
||||||
} from 'jslib/abstractions';
|
} from 'jslib/abstractions';
|
||||||
|
|
||||||
@ -45,7 +47,6 @@ import PasswordGenerationService from '../services/passwordGeneration.service';
|
|||||||
import SettingsService from '../services/settings.service';
|
import SettingsService from '../services/settings.service';
|
||||||
import SyncService from '../services/sync.service';
|
import SyncService from '../services/sync.service';
|
||||||
import TotpService from '../services/totp.service';
|
import TotpService from '../services/totp.service';
|
||||||
import UserService from '../services/user.service';
|
|
||||||
|
|
||||||
export default class MainBackground {
|
export default class MainBackground {
|
||||||
messagingService: MessagingServiceAbstraction;
|
messagingService: MessagingServiceAbstraction;
|
||||||
@ -59,7 +60,7 @@ export default class MainBackground {
|
|||||||
appIdService: AppIdServiceAbstraction;
|
appIdService: AppIdServiceAbstraction;
|
||||||
apiService: ApiServiceAbstraction;
|
apiService: ApiServiceAbstraction;
|
||||||
environmentService: EnvironmentService;
|
environmentService: EnvironmentService;
|
||||||
userService: UserService;
|
userService: UserServiceAbstraction;
|
||||||
settingsService: SettingsService;
|
settingsService: SettingsService;
|
||||||
cipherService: CipherService;
|
cipherService: CipherService;
|
||||||
folderService: FolderService;
|
folderService: FolderService;
|
||||||
|
@ -20,11 +20,11 @@ import {
|
|||||||
ApiService,
|
ApiService,
|
||||||
CryptoService,
|
CryptoService,
|
||||||
StorageService,
|
StorageService,
|
||||||
|
UserService,
|
||||||
} from 'jslib/abstractions';
|
} from 'jslib/abstractions';
|
||||||
|
|
||||||
import ConstantsService from './constants.service';
|
import ConstantsService from './constants.service';
|
||||||
import SettingsService from './settings.service';
|
import SettingsService from './settings.service';
|
||||||
import UserService from './user.service';
|
|
||||||
|
|
||||||
const Keys = {
|
const Keys = {
|
||||||
ciphersPrefix: 'ciphers_',
|
ciphersPrefix: 'ciphers_',
|
||||||
|
@ -1,8 +1,7 @@
|
|||||||
import UserService from './user.service';
|
|
||||||
|
|
||||||
import {
|
import {
|
||||||
CryptoService,
|
CryptoService,
|
||||||
StorageService,
|
StorageService,
|
||||||
|
UserService,
|
||||||
} from 'jslib/abstractions';
|
} from 'jslib/abstractions';
|
||||||
|
|
||||||
import { CollectionData } from 'jslib/models/data';
|
import { CollectionData } from 'jslib/models/data';
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
import UserService from './user.service';
|
|
||||||
|
|
||||||
import { FolderData } from 'jslib/models/data';
|
import { FolderData } from 'jslib/models/data';
|
||||||
|
|
||||||
import { Folder } from 'jslib/models/domain';
|
import { Folder } from 'jslib/models/domain';
|
||||||
@ -12,6 +10,7 @@ import {
|
|||||||
ApiService,
|
ApiService,
|
||||||
CryptoService,
|
CryptoService,
|
||||||
StorageService,
|
StorageService,
|
||||||
|
UserService,
|
||||||
} from 'jslib/abstractions';
|
} from 'jslib/abstractions';
|
||||||
|
|
||||||
const Keys = {
|
const Keys = {
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import UserService from './user.service';
|
import {
|
||||||
|
StorageService,
|
||||||
import { StorageService } from 'jslib/abstractions';
|
UserService,
|
||||||
|
} from 'jslib/abstractions';
|
||||||
|
|
||||||
const Keys = {
|
const Keys = {
|
||||||
settingsPrefix: 'settings_',
|
settingsPrefix: 'settings_',
|
||||||
|
@ -2,13 +2,13 @@ import CipherService from './cipher.service';
|
|||||||
import CollectionService from './collection.service';
|
import CollectionService from './collection.service';
|
||||||
import FolderService from './folder.service';
|
import FolderService from './folder.service';
|
||||||
import SettingsService from './settings.service';
|
import SettingsService from './settings.service';
|
||||||
import UserService from './user.service';
|
|
||||||
|
|
||||||
import {
|
import {
|
||||||
ApiService,
|
ApiService,
|
||||||
CryptoService,
|
CryptoService,
|
||||||
MessagingService,
|
MessagingService,
|
||||||
StorageService,
|
StorageService,
|
||||||
|
UserService,
|
||||||
} from 'jslib/abstractions';
|
} from 'jslib/abstractions';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
|
@ -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;
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user