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

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

78 lines
1.9 KiB
TypeScript
Raw Normal View History

2022-02-22 15:39:11 +01:00
import { LoginLinkedId as LinkedId } from "../../enums/linkedIdType";
import { linkedFieldOption } from "../../misc/linkedFieldOption.decorator";
import { Utils } from "../../misc/utils";
import { Login } from "../domain/login";
2018-01-24 17:33:15 +01:00
2022-02-22 15:39:11 +01:00
import { ItemView } from "./itemView";
import { LoginUriView } from "./loginUriView";
export class LoginView extends ItemView {
@linkedFieldOption(LinkedId.Username)
2019-01-25 15:30:21 +01:00
username: string = null;
@linkedFieldOption(LinkedId.Password)
2019-01-25 15:30:21 +01:00
password: string = null;
2019-01-25 15:30:21 +01:00
passwordRevisionDate?: Date = null;
totp: string = null;
uris: LoginUriView[] = null;
autofillOnPageLoad: boolean = null;
2018-01-24 17:33:15 +01:00
constructor(l?: Login) {
super();
if (!l) {
return;
2018-01-24 17:33:15 +01:00
}
this.passwordRevisionDate = l.passwordRevisionDate;
this.autofillOnPageLoad = l.autofillOnPageLoad;
2018-01-24 17:33:15 +01:00
}
2018-01-24 22:58:34 +01:00
get uri(): string {
2018-03-06 13:44:32 +01:00
return this.hasUris ? this.uris[0].uri : null;
2018-01-24 22:58:34 +01:00
}
get maskedPassword(): string {
return this.password != null ? "••••••••" : null;
}
2018-01-25 05:27:04 +01:00
get subTitle(): string {
return this.username;
2018-01-25 05:27:04 +01:00
}
get canLaunch(): boolean {
return this.hasUris && this.uris.some((u) => u.canLaunch);
}
get hasTotp(): boolean {
return !Utils.isNullOrWhitespace(this.totp);
}
get launchUri(): string {
if (this.hasUris) {
const uri = this.uris.find((u) => u.canLaunch);
if (uri != null) {
return uri.launchUri;
2021-12-16 13:36:21 +01:00
}
2018-01-25 05:27:04 +01:00
}
return null;
2021-12-16 13:36:21 +01:00
}
get hasUris(): boolean {
return this.uris != null && this.uris.length > 0;
2021-12-16 13:36:21 +01:00
}
2022-06-29 06:00:05 +02:00
static fromJSON(obj: Partial<LoginView>): LoginView {
2022-06-29 02:23:01 +02:00
const view = new LoginView();
view.username = obj.username;
view.password = obj.password;
view.totp = obj.totp;
view.autofillOnPageLoad = obj.autofillOnPageLoad;
view.passwordRevisionDate =
obj.passwordRevisionDate == null ? null : new Date(obj.passwordRevisionDate);
view.uris = obj.uris?.map((uri: any) => LoginUriView.fromJSON(uri));
2022-06-29 02:23:01 +02:00
return view;
}
2018-01-24 17:33:15 +01:00
}