mirror of
https://github.com/bitwarden/browser
synced 2025-12-19 01:33:33 +00:00
refactor for login uris and response model changes
This commit is contained in:
@@ -69,8 +69,4 @@ export class CipherView implements View {
|
||||
get login_username(): string {
|
||||
return this.login != null ? this.login.username : null;
|
||||
}
|
||||
|
||||
get login_uri(): string {
|
||||
return this.login != null ? this.login.uri : null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ export { CardView } from './cardView';
|
||||
export { CipherView } from './cipherView';
|
||||
export { FieldView } from './fieldView';
|
||||
export { IdentityView } from './identityView';
|
||||
export { LoginUriView } from './loginUriView';
|
||||
export { LoginView } from './loginView';
|
||||
export { SecureNoteView } from './secureNoteView';
|
||||
export { View } from './view';
|
||||
|
||||
61
src/models/view/loginUriView.ts
Normal file
61
src/models/view/loginUriView.ts
Normal file
@@ -0,0 +1,61 @@
|
||||
import { UriMatchType } from '../../enums/uriMatchType';
|
||||
|
||||
import { View } from './view';
|
||||
|
||||
import { LoginUri } from '../domain/loginUri';
|
||||
|
||||
import { PlatformUtilsService } from '../../abstractions/platformUtils.service';
|
||||
|
||||
export class LoginUriView implements View {
|
||||
match: UriMatchType = null;
|
||||
|
||||
// tslint:disable
|
||||
private _uri: string;
|
||||
private _domain: string;
|
||||
// tslint:enable
|
||||
|
||||
constructor(u?: LoginUri) {
|
||||
if (!u) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.match = u.match;
|
||||
}
|
||||
|
||||
get uri(): string {
|
||||
return this._uri;
|
||||
}
|
||||
set uri(value: string) {
|
||||
this._uri = value;
|
||||
this._domain = null;
|
||||
}
|
||||
|
||||
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);
|
||||
if (this._domain === '') {
|
||||
this._domain = null;
|
||||
}
|
||||
} else {
|
||||
throw new Error('window.bitwardenContainerService not initialized.');
|
||||
}
|
||||
}
|
||||
|
||||
return this._domain;
|
||||
}
|
||||
|
||||
get domainOrUri(): string {
|
||||
return this.domain != null ? this.domain : this.uri;
|
||||
}
|
||||
|
||||
get isWebsite(): boolean {
|
||||
return this.uri != null && (this.uri.indexOf('http://') === 0 || this.uri.indexOf('https://') === 0);
|
||||
}
|
||||
|
||||
get canLaunch(): boolean {
|
||||
return this.uri != null && this.uri.indexOf('://') > -1;
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
import { LoginUriView } from './loginUriView';
|
||||
import { View } from './view';
|
||||
|
||||
import { Login } from '../domain/login';
|
||||
@@ -7,12 +8,11 @@ import { PlatformUtilsService } from '../../abstractions/platformUtils.service';
|
||||
export class LoginView implements View {
|
||||
username: string;
|
||||
totp: string;
|
||||
uris: LoginUriView[];
|
||||
|
||||
// tslint:disable
|
||||
private _uri: string;
|
||||
private _username: string;
|
||||
private _password: string;
|
||||
private _domain: string;
|
||||
private _maskedPassword: string;
|
||||
// tslint:enable
|
||||
|
||||
@@ -20,14 +20,6 @@ export class LoginView implements View {
|
||||
// ctor
|
||||
}
|
||||
|
||||
get uri(): string {
|
||||
return this._uri;
|
||||
}
|
||||
set uri(value: string) {
|
||||
this._uri = value;
|
||||
this._domain = null;
|
||||
}
|
||||
|
||||
get password(): string {
|
||||
return this._password;
|
||||
}
|
||||
@@ -36,21 +28,8 @@ export class LoginView implements View {
|
||||
this._maskedPassword = null;
|
||||
}
|
||||
|
||||
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);
|
||||
if (this._domain === '') {
|
||||
this._domain = null;
|
||||
}
|
||||
} else {
|
||||
throw new Error('window.bitwardenContainerService not initialized.');
|
||||
}
|
||||
}
|
||||
|
||||
return this._domain;
|
||||
get uri(): string {
|
||||
return this.hasUris ? this.uris[0].uri : null;
|
||||
}
|
||||
|
||||
get maskedPassword(): string {
|
||||
@@ -68,15 +47,11 @@ export class LoginView implements View {
|
||||
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://') === 0 || this.uri.indexOf('https://') === 0);
|
||||
}
|
||||
|
||||
get canLaunch(): boolean {
|
||||
return this.uri != null && this.uri.indexOf('://') > -1;
|
||||
return this.hasUris && this.uris[0].canLaunch;
|
||||
}
|
||||
|
||||
get hasUris(): boolean {
|
||||
return this.uris != null && this.uris.length > 0;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user