mirror of
https://github.com/bitwarden/browser.git
synced 2024-09-18 02:41:15 +02:00
user canAccessPremium checks
This commit is contained in:
parent
a72843af3e
commit
81c21418ec
@ -13,6 +13,7 @@ export abstract class UserService {
|
|||||||
getKdfIterations: () => Promise<number>;
|
getKdfIterations: () => Promise<number>;
|
||||||
clear: () => Promise<any>;
|
clear: () => Promise<any>;
|
||||||
isAuthenticated: () => Promise<boolean>;
|
isAuthenticated: () => Promise<boolean>;
|
||||||
|
canAccessPremium: () => Promise<boolean>;
|
||||||
getOrganization: (id: string) => Promise<Organization>;
|
getOrganization: (id: string) => Promise<Organization>;
|
||||||
getAllOrganizations: () => Promise<Organization[]>;
|
getAllOrganizations: () => Promise<Organization[]>;
|
||||||
replaceOrganizations: (organizations: { [id: string]: OrganizationData; }) => Promise<any>;
|
replaceOrganizations: (organizations: { [id: string]: OrganizationData; }) => Promise<any>;
|
||||||
|
@ -21,6 +21,7 @@ import { I18nService } from '../../abstractions/i18n.service';
|
|||||||
import { PlatformUtilsService } from '../../abstractions/platformUtils.service';
|
import { PlatformUtilsService } from '../../abstractions/platformUtils.service';
|
||||||
import { TokenService } from '../../abstractions/token.service';
|
import { TokenService } from '../../abstractions/token.service';
|
||||||
import { TotpService } from '../../abstractions/totp.service';
|
import { TotpService } from '../../abstractions/totp.service';
|
||||||
|
import { UserService } from '../../abstractions/user.service';
|
||||||
|
|
||||||
import { AttachmentView } from '../../models/view/attachmentView';
|
import { AttachmentView } from '../../models/view/attachmentView';
|
||||||
import { CipherView } from '../../models/view/cipherView';
|
import { CipherView } from '../../models/view/cipherView';
|
||||||
@ -38,6 +39,7 @@ export class ViewComponent implements OnDestroy, OnInit {
|
|||||||
showPassword: boolean;
|
showPassword: boolean;
|
||||||
showCardCode: boolean;
|
showCardCode: boolean;
|
||||||
isPremium: boolean;
|
isPremium: boolean;
|
||||||
|
canAccessPremium: boolean;
|
||||||
totpCode: string;
|
totpCode: string;
|
||||||
totpCodeFormatted: string;
|
totpCodeFormatted: string;
|
||||||
totpDash: number;
|
totpDash: number;
|
||||||
@ -54,7 +56,7 @@ export class ViewComponent implements OnDestroy, OnInit {
|
|||||||
protected i18nService: I18nService, protected analytics: Angulartics2,
|
protected i18nService: I18nService, protected analytics: Angulartics2,
|
||||||
protected auditService: AuditService, protected win: Window,
|
protected auditService: AuditService, protected win: Window,
|
||||||
protected broadcasterService: BroadcasterService, protected ngZone: NgZone,
|
protected broadcasterService: BroadcasterService, protected ngZone: NgZone,
|
||||||
protected changeDetectorRef: ChangeDetectorRef) { }
|
protected changeDetectorRef: ChangeDetectorRef, protected userService: UserService) { }
|
||||||
|
|
||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
this.broadcasterService.subscribe(BroadcasterSubscriptionId, (message: any) => {
|
this.broadcasterService.subscribe(BroadcasterSubscriptionId, (message: any) => {
|
||||||
@ -83,9 +85,10 @@ export class ViewComponent implements OnDestroy, OnInit {
|
|||||||
this.cipher = await cipher.decrypt();
|
this.cipher = await cipher.decrypt();
|
||||||
|
|
||||||
this.isPremium = this.tokenService.getPremium();
|
this.isPremium = this.tokenService.getPremium();
|
||||||
|
this.canAccessPremium = await this.userService.canAccessPremium();
|
||||||
|
|
||||||
if (this.cipher.type === CipherType.Login && this.cipher.login.totp &&
|
if (this.cipher.type === CipherType.Login && this.cipher.login.totp &&
|
||||||
(cipher.organizationUseTotp || this.isPremium)) {
|
(cipher.organizationUseTotp || this.canAccessPremium)) {
|
||||||
await this.totpUpdateCode();
|
await this.totpUpdateCode();
|
||||||
const interval = this.totpService.getTimeInterval(this.cipher.login.totp);
|
const interval = this.totpService.getTimeInterval(this.cipher.login.totp);
|
||||||
await this.totpTick(interval);
|
await this.totpTick(interval);
|
||||||
|
@ -116,6 +116,21 @@ export class UserService implements UserServiceAbstraction {
|
|||||||
return userId != null;
|
return userId != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async canAccessPremium(): Promise<boolean> {
|
||||||
|
const tokenPremium = await this.tokenService.getPremium();
|
||||||
|
if (tokenPremium) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
const orgs = await this.getAllOrganizations();
|
||||||
|
for (let i = 0; i < orgs.length; i++) {
|
||||||
|
if (orgs[i].usersGetPremium) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
async getOrganization(id: string): Promise<Organization> {
|
async getOrganization(id: string): Promise<Organization> {
|
||||||
const userId = await this.getUserId();
|
const userId = await this.getUserId();
|
||||||
const organizations = await this.storageService.get<{ [id: string]: OrganizationData; }>(
|
const organizations = await this.storageService.get<{ [id: string]: OrganizationData; }>(
|
||||||
|
Loading…
Reference in New Issue
Block a user