From e5c1adedffff0197a736e068977bd1237bf6590e Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Wed, 24 Jan 2018 23:27:04 -0500 Subject: [PATCH] lib updates for login view on desktop --- src/abstractions/token.service.ts | 38 +++++++++++++++---------------- src/abstractions/totp.service.ts | 6 ++--- src/models/view/cipherView.ts | 8 +++++++ src/models/view/loginView.ts | 14 +++++++++++- src/services/token.service.ts | 4 ++-- src/services/totp.service.ts | 4 ++-- 6 files changed, 47 insertions(+), 27 deletions(-) diff --git a/src/abstractions/token.service.ts b/src/abstractions/token.service.ts index 03f2434c9a..939b96f90f 100644 --- a/src/abstractions/token.service.ts +++ b/src/abstractions/token.service.ts @@ -1,23 +1,23 @@ -export interface TokenService { +export abstract class TokenService { token: string; decodedToken: any; refreshToken: string; - setTokens(accessToken: string, refreshToken: string): Promise; - setToken(token: string): Promise; - getToken(): Promise; - setRefreshToken(refreshToken: string): Promise; - getRefreshToken(): Promise; - setTwoFactorToken(token: string, email: string): Promise; - getTwoFactorToken(email: string): Promise; - clearTwoFactorToken(email: string): Promise; - clearToken(): Promise; - decodeToken(): any; - getTokenExpirationDate(): Date; - tokenSecondsRemaining(offsetSeconds?: number): number; - tokenNeedsRefresh(minutes?: number): boolean; - getUserId(): string; - getEmail(): string; - getName(): string; - getPremium(): boolean; - getIssuer(): string; + setTokens: (accessToken: string, refreshToken: string) => Promise; + setToken: (token: string) => Promise; + getToken: () => Promise; + setRefreshToken: (refreshToken: string) => Promise; + getRefreshToken: () => Promise; + setTwoFactorToken: (token: string, email: string) => Promise; + getTwoFactorToken: (email: string) => Promise; + clearTwoFactorToken: (email: string) => Promise; + clearToken: () => Promise; + decodeToken: () => any; + getTokenExpirationDate: () => Date; + tokenSecondsRemaining: (offsetSeconds?: number) => number; + tokenNeedsRefresh: (minutes?: number) => boolean; + getUserId: () => string; + getEmail: () => string; + getName: () => string; + getPremium: () => boolean; + getIssuer: () => string; } diff --git a/src/abstractions/totp.service.ts b/src/abstractions/totp.service.ts index 2e8fa79aa7..1155d3c2f7 100644 --- a/src/abstractions/totp.service.ts +++ b/src/abstractions/totp.service.ts @@ -1,4 +1,4 @@ -export interface TotpService { - getCode(keyb32: string): Promise; - isAutoCopyEnabled(): Promise; +export abstract class TotpService { + getCode: (keyb32: string) => Promise; + isAutoCopyEnabled: () => Promise; } diff --git a/src/models/view/cipherView.ts b/src/models/view/cipherView.ts index e7ca481e7c..b3f232bcbc 100644 --- a/src/models/view/cipherView.ts +++ b/src/models/view/cipherView.ts @@ -57,4 +57,12 @@ export class CipherView implements View { return null; } + + get hasAttachments(): boolean { + return this.attachments && this.attachments.length > 0; + } + + get hasFields(): boolean { + return this.fields && this.fields.length > 0; + } } diff --git a/src/models/view/loginView.ts b/src/models/view/loginView.ts index 874bd5e494..5bfa4318e6 100644 --- a/src/models/view/loginView.ts +++ b/src/models/view/loginView.ts @@ -53,7 +53,7 @@ export class LoginView implements View { get maskedPassword(): string { if (this._maskedPassword == null && this.password != null) { this._maskedPassword = ''; - for (var i = 0; i < this.password.length; i++) { + for (let i = 0; i < this.password.length; i++) { this._maskedPassword += '•'; } } @@ -64,4 +64,16 @@ export class LoginView implements View { get subTitle(): string { return this.username; } + + get domainOrUri(): string { + return this.domain != null ? this.domain : this.uri; + } + + get isWebsite(): boolean { + return this.uri != null && (this.uri.indexOf('http://') > -1 || this.uri.indexOf('https://') > -1); + } + + get canLaunch(): boolean { + return this.uri != null && this.uri.indexOf('://') > -1; + } } diff --git a/src/services/token.service.ts b/src/services/token.service.ts index 552767e5e0..94dbfa10fd 100644 --- a/src/services/token.service.ts +++ b/src/services/token.service.ts @@ -2,7 +2,7 @@ import { ConstantsService } from './constants.service'; import { UtilsService } from './utils.service'; import { StorageService } from '../abstractions/storage.service'; -import { TokenService as TokenServiceInterface } from '../abstractions/token.service'; +import { TokenService as TokenServiceAbstraction } from '../abstractions/token.service'; const Keys = { accessToken: 'accessToken', @@ -10,7 +10,7 @@ const Keys = { twoFactorTokenPrefix: 'twoFactorToken_', }; -export class TokenService implements TokenServiceInterface { +export class TokenService implements TokenServiceAbstraction { token: string; decodedToken: any; refreshToken: string; diff --git a/src/services/totp.service.ts b/src/services/totp.service.ts index ac6cc4cb78..e52c11e48c 100644 --- a/src/services/totp.service.ts +++ b/src/services/totp.service.ts @@ -1,7 +1,7 @@ import { ConstantsService } from './constants.service'; import { StorageService } from '../abstractions/storage.service'; -import { TotpService as TotpServiceInterface } from '../abstractions/totp.service'; +import { TotpService as TotpServiceAbstraction } from '../abstractions/totp.service'; const b32Chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ234567'; @@ -10,7 +10,7 @@ const TotpAlgorithm = { hash: { name: 'SHA-1' }, }; -export class TotpService implements TotpServiceInterface { +export class TotpService implements TotpServiceAbstraction { constructor(private storageService: StorageService) { }