mirror of
https://github.com/bitwarden/browser
synced 2025-12-16 16:23:44 +00:00
handle loading email settings
This commit is contained in:
@@ -103,12 +103,14 @@ export class LoginComponent extends CaptchaProtectedComponent implements OnInit,
|
||||
|
||||
const queryParamsEmail = params.email;
|
||||
|
||||
// If there is an email in the query params, set that email as the form field value
|
||||
if (queryParamsEmail != null && queryParamsEmail.indexOf("@") > -1) {
|
||||
this.formGroup.controls.email.setValue(queryParamsEmail);
|
||||
this.paramEmailSet = true;
|
||||
}
|
||||
});
|
||||
|
||||
// if there is no email in the query params, attempt to load email settings from loginEmailService
|
||||
if (!this.paramEmailSet) {
|
||||
await this.loadEmailSettings();
|
||||
}
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
<form [bitSubmit]="submit" [formGroup]="formGroup">
|
||||
<p>New Component</p>
|
||||
<!-------------------------
|
||||
UI STATE 1: Email Entry
|
||||
-------------------------->
|
||||
|
||||
@@ -2,9 +2,10 @@ import { CommonModule } from "@angular/common";
|
||||
import { Component, OnInit } from "@angular/core";
|
||||
import { FormBuilder, ReactiveFormsModule, Validators } from "@angular/forms";
|
||||
import { ActivatedRoute, RouterModule } from "@angular/router";
|
||||
import { Subject, takeUntil } from "rxjs";
|
||||
import { firstValueFrom, Subject, takeUntil } from "rxjs";
|
||||
|
||||
import { JslibModule } from "@bitwarden/angular/jslib.module";
|
||||
import { LoginEmailServiceAbstraction } from "@bitwarden/auth/common";
|
||||
import {
|
||||
AsyncActionsModule,
|
||||
ButtonModule,
|
||||
@@ -27,8 +28,6 @@ import {
|
||||
],
|
||||
})
|
||||
export class LoginComponentV2 implements OnInit {
|
||||
protected paramEmailSet = false;
|
||||
|
||||
protected formGroup = this.formBuilder.group({
|
||||
email: ["", [Validators.required, Validators.email]],
|
||||
rememberEmail: [false],
|
||||
@@ -39,9 +38,12 @@ export class LoginComponentV2 implements OnInit {
|
||||
constructor(
|
||||
private activatedRoute: ActivatedRoute,
|
||||
private formBuilder: FormBuilder,
|
||||
private loginEmailService: LoginEmailServiceAbstraction,
|
||||
) {}
|
||||
|
||||
async ngOnInit(): Promise<void> {
|
||||
let paramEmailIsSet = false;
|
||||
|
||||
this.activatedRoute.queryParams.pipe(takeUntil(this.destroy$)).subscribe((params) => {
|
||||
if (!params) {
|
||||
return;
|
||||
@@ -51,12 +53,11 @@ export class LoginComponentV2 implements OnInit {
|
||||
|
||||
if (qParamsEmail?.indexOf("@") > -1) {
|
||||
this.formGroup.controls.email.setValue(qParamsEmail);
|
||||
|
||||
this.paramEmailSet = true;
|
||||
paramEmailIsSet = true;
|
||||
}
|
||||
});
|
||||
|
||||
if (!this.paramEmailSet) {
|
||||
if (!paramEmailIsSet) {
|
||||
await this.loadEmailSettings();
|
||||
}
|
||||
}
|
||||
@@ -65,5 +66,22 @@ export class LoginComponentV2 implements OnInit {
|
||||
|
||||
async validateEmail() {}
|
||||
|
||||
private async loadEmailSettings() {}
|
||||
private async loadEmailSettings() {
|
||||
// Try to load the email from memory first
|
||||
const email = this.loginEmailService.getEmail();
|
||||
const rememberEmail = this.loginEmailService.getRememberEmail();
|
||||
|
||||
if (email) {
|
||||
this.formGroup.controls.email.setValue(email);
|
||||
this.formGroup.controls.rememberEmail.setValue(rememberEmail);
|
||||
} else {
|
||||
// If there is no email in memory, check for a storedEmail on disk
|
||||
const storedEmail = await firstValueFrom(this.loginEmailService.storedEmail$);
|
||||
|
||||
if (storedEmail) {
|
||||
this.formGroup.controls.email.setValue(storedEmail);
|
||||
this.formGroup.controls.rememberEmail.setValue(true); // If there is a storedEmail, rememberEmail defaults to true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user