Skip to content

Commit

Permalink
[SG-781] Remove extra login page and remove rememberEmail code (#3902)
Browse files Browse the repository at this point in the history
* Remove browser home guard

* Always remember email for browser

* Remove login landing page button
  • Loading branch information
differsthecat authored Oct 27, 2022
1 parent 24c2fc8 commit 484fd2d
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 105 deletions.
2 changes: 1 addition & 1 deletion apps/browser/src/popup/accounts/hint.component.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<form #form (ngSubmit)="submit()" [appApiAction]="formPromise">
<header>
<div class="left">
<button type="button" routerLink="/login" [queryParams]="{ email: emailSent }">
<button type="button" routerLink="/login">
{{ "cancel" | i18n }}
</button>
</div>
Expand Down
5 changes: 2 additions & 3 deletions apps/browser/src/popup/accounts/hint.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import { PlatformUtilsService } from "@bitwarden/common/abstractions/platformUti
templateUrl: "hint.component.html",
})
export class HintComponent extends BaseHintComponent implements OnInit {
emailSent: string;
private destroy$ = new Subject<void>();

constructor(
Expand All @@ -27,15 +26,15 @@ export class HintComponent extends BaseHintComponent implements OnInit {
super(router, i18nService, apiService, platformUtilsService, logService);

super.onSuccessfulSubmit = async () => {
this.router.navigate([this.successRoute], { queryParams: { email: this.emailSent } });
this.router.navigate([this.successRoute]);
};
}
ngOnInit() {
this.route?.queryParams.pipe(takeUntil(this.destroy$)).subscribe((params) => {
if (params) {
const queryParamsEmail = params["email"];
if (queryParamsEmail != null && queryParamsEmail.indexOf("@") > -1) {
this.emailSent = this.email = queryParamsEmail;
this.email = queryParamsEmail;
}
}
});
Expand Down
46 changes: 15 additions & 31 deletions apps/browser/src/popup/accounts/home.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,40 +2,24 @@
<div class="content">
<div class="logo-image"></div>
<p class="lead text-center">{{ "loginOrCreateNewAccount" | i18n }}</p>
<ng-container *ngIf="!loginInitiated; else loginForm">
<button type="button" class="btn primary block" (click)="initiateLogin()">
<b>{{ "login" | i18n }}</b>
</button>
</ng-container>
<ng-template #loginForm>
<form #form [formGroup]="formGroup" (ngSubmit)="submit()">
<div class="box">
<div class="box-content">
<div class="box-content-row" appBoxRow>
<label for="email">{{ "emailAddress" | i18n }}</label>
<input id="email" type="email" formControlName="email" appInputVerbatim="false" />
</div>
<form #form [formGroup]="formGroup" (ngSubmit)="submit()">
<div class="box">
<div class="box-content">
<div class="box-content-row" appBoxRow>
<label for="email">{{ "emailAddress" | i18n }}</label>
<input id="email" type="email" formControlName="email" appInputVerbatim="false" />
</div>
<div class="box-footer no-margin" *ngIf="selfHostedDomain">
{{ "loggingInTo" | i18n: selfHostedDomain }}
</div>
</div>
<div>
<input
id="rememberEmail"
type="checkbox"
name="rememberEmail"
formControlName="rememberEmail"
/>
<label for="rememberEmail">{{ "rememberEmail" | i18n }}</label>
</div>
<div class="box">
<button type="submit" class="btn primary block">
<b>{{ "continue" | i18n }}</b>
</button>
<div class="box-footer no-margin" *ngIf="selfHostedDomain">
{{ "loggingInTo" | i18n: selfHostedDomain }}
</div>
</form>
</ng-template>
</div>
<div class="box">
<button type="submit" class="btn primary block">
<b>{{ "continue" | i18n }}</b>
</button>
</div>
</form>
<p class="createAccountLink">
{{ "newAroundHere" | i18n }}
<a routerLink="/register">{{ "createAccount" | i18n }}</a>
Expand Down
44 changes: 8 additions & 36 deletions apps/browser/src/popup/accounts/home.component.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { Component, OnInit } from "@angular/core";
import { FormBuilder, Validators } from "@angular/forms";
import { ActivatedRoute, Router } from "@angular/router";
import { Subject, takeUntil } from "rxjs";

import { EnvironmentService } from "@bitwarden/common/abstractions/environment.service";
import { I18nService } from "@bitwarden/common/abstractions/i18n.service";
Expand All @@ -14,11 +13,9 @@ import { StateService } from "@bitwarden/common/abstractions/state.service";
})
export class HomeComponent implements OnInit {
loginInitiated = false;
private destroy$ = new Subject<void>();

formGroup = this.formBuilder.group({
email: ["", [Validators.required, Validators.email]],
rememberEmail: [false],
});

constructor(
Expand All @@ -30,31 +27,11 @@ export class HomeComponent implements OnInit {
private environmentService: EnvironmentService,
private route: ActivatedRoute
) {}

ngOnInit() {
this.route?.queryParams.pipe(takeUntil(this.destroy$)).subscribe((params) => {
if (params) {
const queryParamsEmail = params["email"];
const queryParamsRememberEmail = params["rememberEmail"];
if (
queryParamsEmail != null &&
queryParamsEmail.indexOf("@") > -1 &&
queryParamsRememberEmail != null
) {
this.setFormGroupValues(queryParamsEmail, JSON.parse(queryParamsRememberEmail));
}
}
});
}

ngOnDestroy(): void {
this.destroy$.next();
this.destroy$.complete();
}

async initiateLogin(): Promise<void> {
this.formGroup.patchValue({ email: await this.stateService.getRememberedEmail() });
this.loginInitiated = true;
async ngOnInit(): Promise<void> {
const rememberedEmail = await this.stateService.getRememberedEmail();
if (rememberedEmail != null) {
this.formGroup.patchValue({ email: await this.stateService.getRememberedEmail() });
}
}

submit() {
Expand All @@ -67,18 +44,13 @@ export class HomeComponent implements OnInit {
);
return;
}
if (this.formGroup.value.rememberEmail) {
this.stateService.setRememberedEmail(this.formGroup.value.email);
}

this.stateService.setRememberedEmail(this.formGroup.value.email);

this.router.navigate(["login"], { queryParams: { email: this.formGroup.value.email } });
}

get selfHostedDomain() {
return this.environmentService.hasBaseUrl() ? this.environmentService.getWebVaultUrl() : null;
}

async setFormGroupValues(email: string, rememberEmail: boolean) {
this.formGroup.patchValue({ email: email, rememberEmail: rememberEmail });
this.loginInitiated = true;
}
}
2 changes: 1 addition & 1 deletion apps/browser/src/popup/accounts/login.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ <h1 class="login-center">
</button>
<div class="small">
<p class="no-margin">{{ "loggingInAs" | i18n }} {{ loggedEmail }}</p>
<a (click)="goBackToHome()">{{ "notYou" | i18n }}</a>
<a routerLink="/home">{{ "notYou" | i18n }}</a>
</div>
</div>
</main>
Expand Down
10 changes: 0 additions & 10 deletions apps/browser/src/popup/accounts/login.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,14 +109,4 @@ export class LoginComponent extends BaseLoginComponent {
codeChallenge
);
}

async goBackToHome() {
await this.stateService.setRememberedEmail(null);
this.router.navigate(["home"], {
queryParams: {
email: this.formGroup.value.email,
rememberEmail: this.formGroup.value.rememberEmail,
},
});
}
}
3 changes: 1 addition & 2 deletions apps/browser/src/popup/app-routing.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import { SendAddEditComponent } from "./send/send-add-edit.component";
import { SendGroupingsComponent } from "./send/send-groupings.component";
import { SendTypeComponent } from "./send/send-type.component";
import { DebounceNavigationService } from "./services/debounceNavigationService";
import { HomeGuard } from "./services/home.guard";
import { ExcludedDomainsComponent } from "./settings/excluded-domains.component";
import { ExportComponent } from "./settings/export.component";
import { FolderAddEditComponent } from "./settings/folder-add-edit.component";
Expand Down Expand Up @@ -57,7 +56,7 @@ const routes: Routes = [
{
path: "home",
component: HomeComponent,
canActivate: [UnauthGuard, HomeGuard],
canActivate: [UnauthGuard],
data: { state: "home" },
},
{
Expand Down
19 changes: 0 additions & 19 deletions apps/browser/src/popup/services/home.guard.ts

This file was deleted.

2 changes: 0 additions & 2 deletions apps/browser/src/popup/services/services.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ import BrowserMessagingPrivateModePopupService from "../../services/browserMessa
import { VaultFilterService } from "../../services/vaultFilter.service";

import { DebounceNavigationService } from "./debounceNavigationService";
import { HomeGuard } from "./home.guard";
import { InitService } from "./init.service";
import { LockGuardService } from "./lock-guard.service";
import { PasswordRepromptService } from "./password-reprompt.service";
Expand Down Expand Up @@ -324,7 +323,6 @@ function getBgService<T>(service: keyof MainBackground) {
);
},
},
HomeGuard,
],
})
export class ServicesModule {}

0 comments on commit 484fd2d

Please sign in to comment.