1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-11-27 12:36:14 +01:00

user canAccessPremium checks

This commit is contained in:
Kyle Spearrin 2018-08-28 23:17:30 -04:00
parent a72843af3e
commit 81c21418ec
3 changed files with 21 additions and 2 deletions

View File

@ -13,6 +13,7 @@ export abstract class UserService {
getKdfIterations: () => Promise<number>;
clear: () => Promise<any>;
isAuthenticated: () => Promise<boolean>;
canAccessPremium: () => Promise<boolean>;
getOrganization: (id: string) => Promise<Organization>;
getAllOrganizations: () => Promise<Organization[]>;
replaceOrganizations: (organizations: { [id: string]: OrganizationData; }) => Promise<any>;

View File

@ -21,6 +21,7 @@ import { I18nService } from '../../abstractions/i18n.service';
import { PlatformUtilsService } from '../../abstractions/platformUtils.service';
import { TokenService } from '../../abstractions/token.service';
import { TotpService } from '../../abstractions/totp.service';
import { UserService } from '../../abstractions/user.service';
import { AttachmentView } from '../../models/view/attachmentView';
import { CipherView } from '../../models/view/cipherView';
@ -38,6 +39,7 @@ export class ViewComponent implements OnDestroy, OnInit {
showPassword: boolean;
showCardCode: boolean;
isPremium: boolean;
canAccessPremium: boolean;
totpCode: string;
totpCodeFormatted: string;
totpDash: number;
@ -54,7 +56,7 @@ export class ViewComponent implements OnDestroy, OnInit {
protected i18nService: I18nService, protected analytics: Angulartics2,
protected auditService: AuditService, protected win: Window,
protected broadcasterService: BroadcasterService, protected ngZone: NgZone,
protected changeDetectorRef: ChangeDetectorRef) { }
protected changeDetectorRef: ChangeDetectorRef, protected userService: UserService) { }
ngOnInit() {
this.broadcasterService.subscribe(BroadcasterSubscriptionId, (message: any) => {
@ -83,9 +85,10 @@ export class ViewComponent implements OnDestroy, OnInit {
this.cipher = await cipher.decrypt();
this.isPremium = this.tokenService.getPremium();
this.canAccessPremium = await this.userService.canAccessPremium();
if (this.cipher.type === CipherType.Login && this.cipher.login.totp &&
(cipher.organizationUseTotp || this.isPremium)) {
(cipher.organizationUseTotp || this.canAccessPremium)) {
await this.totpUpdateCode();
const interval = this.totpService.getTimeInterval(this.cipher.login.totp);
await this.totpTick(interval);

View File

@ -116,6 +116,21 @@ export class UserService implements UserServiceAbstraction {
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> {
const userId = await this.getUserId();
const organizations = await this.storageService.get<{ [id: string]: OrganizationData; }>(