Prefill email field when "create account" is clicked.

This commit is contained in:
Alec Rippberger 2024-09-24 16:35:43 -05:00
parent 9bb84094ae
commit d9f930d7cb
No known key found for this signature in database
GPG Key ID: 9DD8DA583B28154A
3 changed files with 15 additions and 0 deletions

View File

@ -21,10 +21,12 @@ import { DialogService, ToastService } from "@bitwarden/components";
import { PasswordGenerationServiceAbstraction } from "@bitwarden/generator-legacy"; import { PasswordGenerationServiceAbstraction } from "@bitwarden/generator-legacy";
import { AcceptOrganizationInviteService } from "../organization-invite/accept-organization.service"; import { AcceptOrganizationInviteService } from "../organization-invite/accept-organization.service";
import { LoginEmailService } from "../../../../../../libs/auth/src/common/services/login-email/login-email.service";
@Component({ @Component({
selector: "app-register-form", selector: "app-register-form",
templateUrl: "./register-form.component.html", templateUrl: "./register-form.component.html",
providers: [LoginEmailService],
}) })
export class RegisterFormComponent extends BaseRegisterComponent implements OnInit { export class RegisterFormComponent extends BaseRegisterComponent implements OnInit {
@Input() queryParamEmail: string; @Input() queryParamEmail: string;
@ -53,6 +55,7 @@ export class RegisterFormComponent extends BaseRegisterComponent implements OnIn
dialogService: DialogService, dialogService: DialogService,
acceptOrgInviteService: AcceptOrganizationInviteService, acceptOrgInviteService: AcceptOrganizationInviteService,
toastService: ToastService, toastService: ToastService,
private loginEmailService: LoginEmailService,
) { ) {
super( super(
formValidationErrorService, formValidationErrorService,
@ -95,6 +98,15 @@ export class RegisterFormComponent extends BaseRegisterComponent implements OnIn
} else { } else {
this.characterMinimumMessage = this.i18nService.t("characterMinimum", this.minimumLength); this.characterMinimumMessage = this.i18nService.t("characterMinimum", this.minimumLength);
} }
/**
* If the user has a login email, set the email field to the login email.
*/
this.loginEmailService.loginEmail$.subscribe((email) => {
if (email) {
this.formGroup.patchValue({ email });
}
});
} }
async submit() { async submit() {

View File

@ -383,6 +383,7 @@ export class LoginComponent implements OnInit, OnDestroy {
onEmailBlur(event: Event) { onEmailBlur(event: Event) {
const emailInput = event.target as HTMLInputElement; const emailInput = event.target as HTMLInputElement;
this.formGroup.controls.email.setValue(emailInput.value); this.formGroup.controls.email.setValue(emailInput.value);
this.loginEmailService.setLoginEmail(this.formGroup.value.email);
} }
protected async goToHint(): Promise<void> { protected async goToHint(): Promise<void> {

View File

@ -12,6 +12,7 @@ import {
StateProvider, StateProvider,
} from "../../../../../common/src/platform/state"; } from "../../../../../common/src/platform/state";
import { LoginEmailServiceAbstraction } from "../../abstractions/login-email.service"; import { LoginEmailServiceAbstraction } from "../../abstractions/login-email.service";
import { Injectable } from "@angular/core";
export const LOGIN_EMAIL = new KeyDefinition<string>(LOGIN_EMAIL_MEMORY, "loginEmail", { export const LOGIN_EMAIL = new KeyDefinition<string>(LOGIN_EMAIL_MEMORY, "loginEmail", {
deserializer: (value: string) => value, deserializer: (value: string) => value,
@ -21,6 +22,7 @@ export const STORED_EMAIL = new KeyDefinition<string>(LOGIN_EMAIL_DISK, "storedE
deserializer: (value: string) => value, deserializer: (value: string) => value,
}); });
@Injectable()
export class LoginEmailService implements LoginEmailServiceAbstraction { export class LoginEmailService implements LoginEmailServiceAbstraction {
private rememberEmail: boolean; private rememberEmail: boolean;