1
0
mirror of https://github.com/bitwarden/browser synced 2026-02-21 03:43:58 +00:00

Add new identity autofill to browser extension

This commit is contained in:
Jeffrey Holland
2025-03-11 15:41:57 +01:00
parent d8e8ef42cc
commit 4a3ff8e6ad
3 changed files with 128 additions and 0 deletions

View File

@@ -488,5 +488,79 @@ const mapAddEditCipherInfoToInitialValues = (
initialValues.username = cipher.identity.username;
}
if (cipher.type == CipherType.Identity) {
const identity = cipher.identity;
if (identity != null) {
if (identity.title != null) {
initialValues.title = identity.title;
}
if (identity.firstName != null) {
initialValues.firstName = identity.firstName;
}
if (identity.middleName != null) {
initialValues.middleName = identity.middleName;
}
if (identity.lastName != null) {
initialValues.lastName = identity.lastName;
}
if (identity.company != null) {
initialValues.company = identity.company;
}
if (identity.ssn != null) {
initialValues.ssn = identity.ssn;
}
if (identity.passportNumber != null) {
initialValues.passportNumber = identity.passportNumber;
}
if (identity.licenseNumber != null) {
initialValues.licenseNumber = identity.licenseNumber;
}
if (identity.email != null) {
initialValues.email = identity.email;
}
if (identity.phone != null) {
initialValues.phone = identity.phone;
}
if (identity.address1 != null) {
initialValues.address1 = identity.address1;
}
if (identity.address2 != null) {
initialValues.address2 = identity.address2;
}
if (identity.address3 != null) {
initialValues.address3 = identity.address3;
}
if (identity.city != null) {
initialValues.city = identity.city;
}
if (identity.state != null) {
initialValues.state = identity.state;
}
if (identity.postalCode != null) {
initialValues.postalCode = identity.postalCode;
}
if (identity.country != null) {
initialValues.country = identity.country;
}
}
}
return initialValues;
};

View File

@@ -25,11 +25,30 @@ export type OptionalInitialValues = {
username?: string;
password?: string;
name?: string;
// Credit Card Information
cardholderName?: string;
number?: string;
expMonth?: string;
expYear?: string;
code?: string;
// Identity Information
title?: string;
firstName?: string;
middleName?: string;
lastName?: string;
company?: string;
ssn?: string;
passportNumber?: string;
licenseNumber?: string;
email?: string;
phone?: string;
address1?: string;
address2?: string;
address3?: string;
city?: string;
state?: string;
postalCode?: string;
country?: string;
};
/**

View File

@@ -73,6 +73,10 @@ export class IdentitySectionComponent implements OnInit {
country: [""],
});
get initialValues() {
return this.cipherFormContainer.config.initialValues;
}
constructor(
private cipherFormContainer: CipherFormContainer,
private formBuilder: FormBuilder,
@@ -116,14 +120,45 @@ export class IdentitySectionComponent implements OnInit {
const prefillCipher = this.cipherFormContainer.getInitialCipherView();
if (prefillCipher) {
this.initFromExistingCipher(prefillCipher.identity);
this.populateFormData(prefillCipher);
} else {
this.initNewCipher();
this.identityForm.patchValue({
username: this.cipherFormContainer.config.initialValues?.username || "",
});
}
}
private initFromExistingCipher(existingIdentity: IdentityView) {
this.identityForm.patchValue({
firstName: this.initialValues.firstName ?? existingIdentity.firstName,
middleName: this.initialValues.middleName ?? existingIdentity.middleName,
lastName: this.initialValues.lastName ?? existingIdentity.lastName,
company: this.initialValues.company ?? existingIdentity.company,
ssn: this.initialValues.ssn ?? existingIdentity.ssn,
passportNumber: this.initialValues.passportNumber ?? existingIdentity.passportNumber,
licenseNumber: this.initialValues.licenseNumber ?? existingIdentity.licenseNumber,
email: this.initialValues.email ?? existingIdentity.email,
phone: this.initialValues.phone ?? existingIdentity.phone,
address1: this.initialValues.address1 ?? existingIdentity.address1,
address2: this.initialValues.address2 ?? existingIdentity.address2,
address3: this.initialValues.address3 ?? existingIdentity.address3,
city: this.initialValues.city ?? existingIdentity.city,
state: this.initialValues.state ?? existingIdentity.state,
postalCode: this.initialValues.postalCode ?? existingIdentity.postalCode,
country: this.initialValues.country ?? existingIdentity.country,
});
}
private initNewCipher() {
this.identityForm.patchValue({
firstName: this.initialValues?.firstName || "",
middleName: this.initialValues?.middleName || "",
lastName: this.initialValues?.lastName || "",
});
}
populateFormData(cipherView: CipherView) {
const { identity } = cipherView;