mirror of
https://github.com/bitwarden/browser.git
synced 2024-11-09 09:51:02 +01:00
Use sync instead of token to manage emailVerified (#344)
This commit is contained in:
parent
92df633040
commit
66eec2b022
@ -5,12 +5,14 @@ import { KdfType } from '../enums/kdfType';
|
||||
|
||||
export abstract class UserService {
|
||||
setInformation: (userId: string, email: string, kdf: KdfType, kdfIterations: number) => Promise<any>;
|
||||
setEmailVerified: (emailVerified: boolean) => Promise<any>;
|
||||
setSecurityStamp: (stamp: string) => Promise<any>;
|
||||
getUserId: () => Promise<string>;
|
||||
getEmail: () => Promise<string>;
|
||||
getSecurityStamp: () => Promise<string>;
|
||||
getKdf: () => Promise<KdfType>;
|
||||
getKdfIterations: () => Promise<number>;
|
||||
getEmailVerified: () => Promise<boolean>;
|
||||
clear: () => Promise<any>;
|
||||
isAuthenticated: () => Promise<boolean>;
|
||||
canAccessPremium: () => Promise<boolean>;
|
||||
|
@ -17,7 +17,6 @@ import { MessagingService } from '../../../abstractions/messaging.service';
|
||||
import { PlatformUtilsService } from '../../../abstractions/platformUtils.service';
|
||||
import { PolicyService } from '../../../abstractions/policy.service';
|
||||
import { SendService } from '../../../abstractions/send.service';
|
||||
import { TokenService } from '../../../abstractions/token.service';
|
||||
import { UserService } from '../../../abstractions/user.service';
|
||||
|
||||
import { SendFileView } from '../../../models/view/sendFileView';
|
||||
@ -83,8 +82,7 @@ export class AddEditComponent implements OnInit {
|
||||
constructor(protected i18nService: I18nService, protected platformUtilsService: PlatformUtilsService,
|
||||
protected environmentService: EnvironmentService, protected datePipe: DatePipe,
|
||||
protected sendService: SendService, protected userService: UserService,
|
||||
protected messagingService: MessagingService, protected policyService: PolicyService,
|
||||
protected tokenService: TokenService) {
|
||||
protected messagingService: MessagingService, protected policyService: PolicyService) {
|
||||
this.typeOptions = [
|
||||
{ name: i18nService.t('sendTypeFile'), value: SendType.File },
|
||||
{ name: i18nService.t('sendTypeText'), value: SendType.Text },
|
||||
@ -174,7 +172,7 @@ export class AddEditComponent implements OnInit {
|
||||
});
|
||||
|
||||
this.canAccessPremium = await this.userService.canAccessPremium();
|
||||
this.emailVerified = this.tokenService.getEmailVerified();
|
||||
this.emailVerified = await this.userService.getEmailVerified();
|
||||
if (!this.canAccessPremium || !this.emailVerified) {
|
||||
this.type = SendType.Text;
|
||||
}
|
||||
|
@ -288,6 +288,7 @@ export class SyncService implements SyncServiceAbstraction {
|
||||
await this.cryptoService.setEncPrivateKey(response.privateKey);
|
||||
await this.cryptoService.setOrgKeys(response.organizations);
|
||||
await this.userService.setSecurityStamp(response.securityStamp);
|
||||
await this.userService.setEmailVerified(response.emailVerified);
|
||||
|
||||
const organizations: { [id: string]: OrganizationData; } = {};
|
||||
response.organizations.forEach(o => {
|
||||
|
@ -14,6 +14,7 @@ const Keys = {
|
||||
kdf: 'kdf',
|
||||
kdfIterations: 'kdfIterations',
|
||||
organizationsPrefix: 'organizations_',
|
||||
emailVerified: 'emailVerified',
|
||||
};
|
||||
|
||||
export class UserService implements UserServiceAbstraction {
|
||||
@ -22,6 +23,7 @@ export class UserService implements UserServiceAbstraction {
|
||||
private stamp: string;
|
||||
private kdf: KdfType;
|
||||
private kdfIterations: number;
|
||||
private emailVerified: boolean;
|
||||
|
||||
constructor(private tokenService: TokenService, private storageService: StorageService) { }
|
||||
|
||||
@ -44,6 +46,11 @@ export class UserService implements UserServiceAbstraction {
|
||||
return this.storageService.save(Keys.stamp, stamp);
|
||||
}
|
||||
|
||||
setEmailVerified(emailVerified: boolean) {
|
||||
this.emailVerified = emailVerified;
|
||||
return this.storageService.save(Keys.emailVerified, emailVerified);
|
||||
}
|
||||
|
||||
async getUserId(): Promise<string> {
|
||||
if (this.userId == null) {
|
||||
this.userId = await this.storageService.get<string>(Keys.userId);
|
||||
@ -79,6 +86,13 @@ export class UserService implements UserServiceAbstraction {
|
||||
return this.kdfIterations;
|
||||
}
|
||||
|
||||
async getEmailVerified(): Promise<boolean> {
|
||||
if (this.emailVerified == null) {
|
||||
this.emailVerified = await this.storageService.get<boolean>(Keys.emailVerified);
|
||||
}
|
||||
return this.emailVerified;
|
||||
}
|
||||
|
||||
async clear(): Promise<any> {
|
||||
const userId = await this.getUserId();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user