bitwarden-estensione-browser/src/models/view/loginView.ts

83 lines
2.1 KiB
TypeScript
Raw Normal View History

2018-01-24 17:33:15 +01:00
import { View } from './view';
2018-02-19 18:33:32 +01:00
import { Login } from '../domain';
2018-01-24 17:33:15 +01:00
2018-02-19 18:33:32 +01:00
import { PlatformUtilsService } from '../../abstractions';
2018-01-24 17:33:15 +01:00
export class LoginView implements View {
username: string;
totp: string;
2018-01-24 22:58:34 +01:00
// tslint:disable
private _uri: string;
private _username: string;
private _password: string;
2018-01-24 17:33:15 +01:00
private _domain: string;
2018-01-24 22:58:34 +01:00
private _maskedPassword: string;
// tslint:enable
2018-01-24 17:33:15 +01:00
constructor(l?: Login) {
// ctor
}
2018-01-24 22:58:34 +01:00
get uri(): string {
return this._uri;
}
set uri(value: string) {
this._uri = value;
this._domain = null;
}
get password(): string {
return this._password;
}
set password(value: string) {
this._password = value;
this._maskedPassword = null;
}
2018-01-24 17:33:15 +01:00
get domain(): string {
if (this._domain == null && this.uri != null) {
const containerService = (window as any).bitwardenContainerService;
if (containerService) {
const platformUtilsService: PlatformUtilsService = containerService.getPlatformUtilsService();
this._domain = platformUtilsService.getDomain(this.uri);
2018-01-30 19:13:12 +01:00
if (this._domain === '') {
this._domain = null;
}
2018-01-24 17:33:15 +01:00
} else {
throw new Error('window.bitwardenContainerService not initialized.');
}
}
return this._domain;
}
2018-01-24 22:58:34 +01:00
get maskedPassword(): string {
if (this._maskedPassword == null && this.password != null) {
this._maskedPassword = '';
2018-01-25 05:27:04 +01:00
for (let i = 0; i < this.password.length; i++) {
2018-01-24 22:58:34 +01:00
this._maskedPassword += '•';
}
}
return this._maskedPassword;
}
get subTitle(): string {
return this.username;
}
2018-01-25 05:27:04 +01:00
get domainOrUri(): string {
return this.domain != null ? this.domain : this.uri;
}
get isWebsite(): boolean {
2018-01-30 19:13:12 +01:00
return this.uri != null && (this.uri.indexOf('http://') === 0 || this.uri.indexOf('https://') === 0);
2018-01-25 05:27:04 +01:00
}
get canLaunch(): boolean {
return this.uri != null && this.uri.indexOf('://') > -1;
}
2018-01-24 17:33:15 +01:00
}