mirror of
https://github.com/bitwarden/browser
synced 2025-12-15 07:43:35 +00:00
* create domain settings state provider * replace callsites for defaultUriMatch and neverDomains with DomainSettingsService equivalents * replace callsites for equivalentDomains with DomainSettingsService equivalents and clean up unused AccountSettingsSettings * add migrations for domain settings state * do not use enum for URI match strategy constants and types * add getUrlEquivalentDomains test * PR suggestions/cleanup * refactor getUrlEquivalentDomains to return an observable Co-authored-by: Justin Baur <19896123+justindbaur@users.noreply.github.com> Co-authored-by: ✨ Audrey ✨ <ajensen@bitwarden.com> * update tests * add UriMatchStrategy docs notes * service class renames * use service abstraction at callsites previously using service class directly --------- Co-authored-by: Justin Baur <19896123+justindbaur@users.noreply.github.com> Co-authored-by: ✨ Audrey ✨ <ajensen@bitwarden.com>
97 lines
2.6 KiB
TypeScript
97 lines
2.6 KiB
TypeScript
import { UriMatchStrategySetting } from "../../../models/domain/domain-service";
|
|
import { Utils } from "../../../platform/misc/utils";
|
|
import { DeepJsonify } from "../../../types/deep-jsonify";
|
|
import { LoginLinkedId as LinkedId } from "../../enums";
|
|
import { linkedFieldOption } from "../../linked-field-option.decorator";
|
|
import { Login } from "../domain/login";
|
|
|
|
import { Fido2CredentialView } from "./fido2-credential.view";
|
|
import { ItemView } from "./item.view";
|
|
import { LoginUriView } from "./login-uri.view";
|
|
|
|
export class LoginView extends ItemView {
|
|
@linkedFieldOption(LinkedId.Username)
|
|
username: string = null;
|
|
@linkedFieldOption(LinkedId.Password)
|
|
password: string = null;
|
|
|
|
passwordRevisionDate?: Date = null;
|
|
totp: string = null;
|
|
uris: LoginUriView[] = [];
|
|
autofillOnPageLoad: boolean = null;
|
|
fido2Credentials: Fido2CredentialView[] = null;
|
|
|
|
constructor(l?: Login) {
|
|
super();
|
|
if (!l) {
|
|
return;
|
|
}
|
|
|
|
this.passwordRevisionDate = l.passwordRevisionDate;
|
|
this.autofillOnPageLoad = l.autofillOnPageLoad;
|
|
}
|
|
|
|
get uri(): string {
|
|
return this.hasUris ? this.uris[0].uri : null;
|
|
}
|
|
|
|
get maskedPassword(): string {
|
|
return this.password != null ? "••••••••" : null;
|
|
}
|
|
|
|
get subTitle(): string {
|
|
return this.username;
|
|
}
|
|
|
|
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;
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
|
|
get hasUris(): boolean {
|
|
return this.uris != null && this.uris.length > 0;
|
|
}
|
|
|
|
get hasFido2Credentials(): boolean {
|
|
return this.fido2Credentials != null && this.fido2Credentials.length > 0;
|
|
}
|
|
|
|
matchesUri(
|
|
targetUri: string,
|
|
equivalentDomains: Set<string>,
|
|
defaultUriMatch: UriMatchStrategySetting = null,
|
|
): boolean {
|
|
if (this.uris == null) {
|
|
return false;
|
|
}
|
|
|
|
return this.uris.some((uri) => uri.matchesUri(targetUri, equivalentDomains, defaultUriMatch));
|
|
}
|
|
|
|
static fromJSON(obj: Partial<DeepJsonify<LoginView>>): LoginView {
|
|
const passwordRevisionDate =
|
|
obj.passwordRevisionDate == null ? null : new Date(obj.passwordRevisionDate);
|
|
const uris = obj.uris.map((uri) => LoginUriView.fromJSON(uri));
|
|
const fido2Credentials = obj.fido2Credentials?.map((key) => Fido2CredentialView.fromJSON(key));
|
|
|
|
return Object.assign(new LoginView(), obj, {
|
|
passwordRevisionDate,
|
|
uris,
|
|
fido2Credentials,
|
|
});
|
|
}
|
|
}
|