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 {
|
export abstract class UserService {
|
||||||
setInformation: (userId: string, email: string, kdf: KdfType, kdfIterations: number) => Promise<any>;
|
setInformation: (userId: string, email: string, kdf: KdfType, kdfIterations: number) => Promise<any>;
|
||||||
|
setEmailVerified: (emailVerified: boolean) => Promise<any>;
|
||||||
setSecurityStamp: (stamp: string) => Promise<any>;
|
setSecurityStamp: (stamp: string) => Promise<any>;
|
||||||
getUserId: () => Promise<string>;
|
getUserId: () => Promise<string>;
|
||||||
getEmail: () => Promise<string>;
|
getEmail: () => Promise<string>;
|
||||||
getSecurityStamp: () => Promise<string>;
|
getSecurityStamp: () => Promise<string>;
|
||||||
getKdf: () => Promise<KdfType>;
|
getKdf: () => Promise<KdfType>;
|
||||||
getKdfIterations: () => Promise<number>;
|
getKdfIterations: () => Promise<number>;
|
||||||
|
getEmailVerified: () => Promise<boolean>;
|
||||||
clear: () => Promise<any>;
|
clear: () => Promise<any>;
|
||||||
isAuthenticated: () => Promise<boolean>;
|
isAuthenticated: () => Promise<boolean>;
|
||||||
canAccessPremium: () => Promise<boolean>;
|
canAccessPremium: () => Promise<boolean>;
|
||||||
|
|
|
@ -17,7 +17,6 @@ import { MessagingService } from '../../../abstractions/messaging.service';
|
||||||
import { PlatformUtilsService } from '../../../abstractions/platformUtils.service';
|
import { PlatformUtilsService } from '../../../abstractions/platformUtils.service';
|
||||||
import { PolicyService } from '../../../abstractions/policy.service';
|
import { PolicyService } from '../../../abstractions/policy.service';
|
||||||
import { SendService } from '../../../abstractions/send.service';
|
import { SendService } from '../../../abstractions/send.service';
|
||||||
import { TokenService } from '../../../abstractions/token.service';
|
|
||||||
import { UserService } from '../../../abstractions/user.service';
|
import { UserService } from '../../../abstractions/user.service';
|
||||||
|
|
||||||
import { SendFileView } from '../../../models/view/sendFileView';
|
import { SendFileView } from '../../../models/view/sendFileView';
|
||||||
|
@ -83,8 +82,7 @@ export class AddEditComponent implements OnInit {
|
||||||
constructor(protected i18nService: I18nService, protected platformUtilsService: PlatformUtilsService,
|
constructor(protected i18nService: I18nService, protected platformUtilsService: PlatformUtilsService,
|
||||||
protected environmentService: EnvironmentService, protected datePipe: DatePipe,
|
protected environmentService: EnvironmentService, protected datePipe: DatePipe,
|
||||||
protected sendService: SendService, protected userService: UserService,
|
protected sendService: SendService, protected userService: UserService,
|
||||||
protected messagingService: MessagingService, protected policyService: PolicyService,
|
protected messagingService: MessagingService, protected policyService: PolicyService) {
|
||||||
protected tokenService: TokenService) {
|
|
||||||
this.typeOptions = [
|
this.typeOptions = [
|
||||||
{ name: i18nService.t('sendTypeFile'), value: SendType.File },
|
{ name: i18nService.t('sendTypeFile'), value: SendType.File },
|
||||||
{ name: i18nService.t('sendTypeText'), value: SendType.Text },
|
{ name: i18nService.t('sendTypeText'), value: SendType.Text },
|
||||||
|
@ -174,7 +172,7 @@ export class AddEditComponent implements OnInit {
|
||||||
});
|
});
|
||||||
|
|
||||||
this.canAccessPremium = await this.userService.canAccessPremium();
|
this.canAccessPremium = await this.userService.canAccessPremium();
|
||||||
this.emailVerified = this.tokenService.getEmailVerified();
|
this.emailVerified = await this.userService.getEmailVerified();
|
||||||
if (!this.canAccessPremium || !this.emailVerified) {
|
if (!this.canAccessPremium || !this.emailVerified) {
|
||||||
this.type = SendType.Text;
|
this.type = SendType.Text;
|
||||||
}
|
}
|
||||||
|
|
|
@ -288,6 +288,7 @@ export class SyncService implements SyncServiceAbstraction {
|
||||||
await this.cryptoService.setEncPrivateKey(response.privateKey);
|
await this.cryptoService.setEncPrivateKey(response.privateKey);
|
||||||
await this.cryptoService.setOrgKeys(response.organizations);
|
await this.cryptoService.setOrgKeys(response.organizations);
|
||||||
await this.userService.setSecurityStamp(response.securityStamp);
|
await this.userService.setSecurityStamp(response.securityStamp);
|
||||||
|
await this.userService.setEmailVerified(response.emailVerified);
|
||||||
|
|
||||||
const organizations: { [id: string]: OrganizationData; } = {};
|
const organizations: { [id: string]: OrganizationData; } = {};
|
||||||
response.organizations.forEach(o => {
|
response.organizations.forEach(o => {
|
||||||
|
|
|
@ -14,6 +14,7 @@ const Keys = {
|
||||||
kdf: 'kdf',
|
kdf: 'kdf',
|
||||||
kdfIterations: 'kdfIterations',
|
kdfIterations: 'kdfIterations',
|
||||||
organizationsPrefix: 'organizations_',
|
organizationsPrefix: 'organizations_',
|
||||||
|
emailVerified: 'emailVerified',
|
||||||
};
|
};
|
||||||
|
|
||||||
export class UserService implements UserServiceAbstraction {
|
export class UserService implements UserServiceAbstraction {
|
||||||
|
@ -22,6 +23,7 @@ export class UserService implements UserServiceAbstraction {
|
||||||
private stamp: string;
|
private stamp: string;
|
||||||
private kdf: KdfType;
|
private kdf: KdfType;
|
||||||
private kdfIterations: number;
|
private kdfIterations: number;
|
||||||
|
private emailVerified: boolean;
|
||||||
|
|
||||||
constructor(private tokenService: TokenService, private storageService: StorageService) { }
|
constructor(private tokenService: TokenService, private storageService: StorageService) { }
|
||||||
|
|
||||||
|
@ -44,6 +46,11 @@ export class UserService implements UserServiceAbstraction {
|
||||||
return this.storageService.save(Keys.stamp, stamp);
|
return this.storageService.save(Keys.stamp, stamp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setEmailVerified(emailVerified: boolean) {
|
||||||
|
this.emailVerified = emailVerified;
|
||||||
|
return this.storageService.save(Keys.emailVerified, emailVerified);
|
||||||
|
}
|
||||||
|
|
||||||
async getUserId(): Promise<string> {
|
async getUserId(): Promise<string> {
|
||||||
if (this.userId == null) {
|
if (this.userId == null) {
|
||||||
this.userId = await this.storageService.get<string>(Keys.userId);
|
this.userId = await this.storageService.get<string>(Keys.userId);
|
||||||
|
@ -79,6 +86,13 @@ export class UserService implements UserServiceAbstraction {
|
||||||
return this.kdfIterations;
|
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> {
|
async clear(): Promise<any> {
|
||||||
const userId = await this.getUserId();
|
const userId = await this.getUserId();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue