mirror of
https://github.com/bitwarden/browser.git
synced 2024-11-15 10:35:20 +01:00
Refactored components to make the redirectUrl more generic, fixed code review comments
This commit is contained in:
parent
ef4a1d9b7b
commit
6a05ba3ad0
@ -82,14 +82,15 @@ export class HomeComponent implements OnInit, OnDestroy {
|
|||||||
this.loginService.setEmail(this.formGroup.value.email);
|
this.loginService.setEmail(this.formGroup.value.email);
|
||||||
this.loginService.setRememberEmail(this.formGroup.value.rememberEmail);
|
this.loginService.setRememberEmail(this.formGroup.value.rememberEmail);
|
||||||
|
|
||||||
// const decodedRedirectUrl = decodeURIComponent(this.route.snapshot.queryParams.redirectUrl);
|
const queryParams: { email: string; redirectUrl?: string } = {
|
||||||
// console.log(decodedRedirectUrl, this.route);
|
|
||||||
this.router.navigate(["login"], {
|
|
||||||
queryParams: {
|
|
||||||
email: this.formGroup.value.email,
|
email: this.formGroup.value.email,
|
||||||
redirectUrl: this.route.snapshot.queryParams.redirectUrl,
|
};
|
||||||
},
|
|
||||||
});
|
if (this.route.snapshot.queryParams.redirectUrl) {
|
||||||
|
queryParams.redirectUrl = decodeURIComponent(this.route.snapshot.queryParams.redirectUrl);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.router.navigate(["login"], { queryParams });
|
||||||
}
|
}
|
||||||
|
|
||||||
get selfHostedDomain() {
|
get selfHostedDomain() {
|
||||||
|
@ -50,8 +50,8 @@ export class LockComponent extends BaseLockComponent {
|
|||||||
policyService: InternalPolicyService,
|
policyService: InternalPolicyService,
|
||||||
passwordStrengthService: PasswordStrengthServiceAbstraction,
|
passwordStrengthService: PasswordStrengthServiceAbstraction,
|
||||||
private authService: AuthService,
|
private authService: AuthService,
|
||||||
dialogService: DialogServiceAbstraction,
|
route: ActivatedRoute,
|
||||||
route: ActivatedRoute
|
dialogService: DialogServiceAbstraction
|
||||||
) {
|
) {
|
||||||
super(
|
super(
|
||||||
router,
|
router,
|
||||||
@ -70,8 +70,8 @@ export class LockComponent extends BaseLockComponent {
|
|||||||
policyApiService,
|
policyApiService,
|
||||||
policyService,
|
policyService,
|
||||||
passwordStrengthService,
|
passwordStrengthService,
|
||||||
dialogService,
|
route,
|
||||||
route
|
dialogService
|
||||||
);
|
);
|
||||||
this.successRoute = "/tabs/current";
|
this.successRoute = "/tabs/current";
|
||||||
this.isInitialLockScreen = (window as any).previousPopupUrl == null;
|
this.isInitialLockScreen = (window as any).previousPopupUrl == null;
|
||||||
|
@ -63,8 +63,8 @@ export class LockComponent extends BaseLockComponent {
|
|||||||
policyApiService,
|
policyApiService,
|
||||||
policyService,
|
policyService,
|
||||||
passwordStrengthService,
|
passwordStrengthService,
|
||||||
dialogService,
|
route,
|
||||||
route
|
dialogService
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -41,8 +41,7 @@ export class LockComponent implements OnInit, OnDestroy {
|
|||||||
biometricLock: boolean;
|
biometricLock: boolean;
|
||||||
biometricText: string;
|
biometricText: string;
|
||||||
hideInput: boolean;
|
hideInput: boolean;
|
||||||
redirectPath: string;
|
redirectUrl: string;
|
||||||
sessionId: string;
|
|
||||||
|
|
||||||
protected successRoute = "vault";
|
protected successRoute = "vault";
|
||||||
protected forcePasswordResetRoute = "update-temp-password";
|
protected forcePasswordResetRoute = "update-temp-password";
|
||||||
@ -72,21 +71,11 @@ export class LockComponent implements OnInit, OnDestroy {
|
|||||||
protected policyApiService: PolicyApiServiceAbstraction,
|
protected policyApiService: PolicyApiServiceAbstraction,
|
||||||
protected policyService: InternalPolicyService,
|
protected policyService: InternalPolicyService,
|
||||||
protected passwordStrengthService: PasswordStrengthServiceAbstraction,
|
protected passwordStrengthService: PasswordStrengthServiceAbstraction,
|
||||||
protected dialogService: DialogServiceAbstraction,
|
protected route: ActivatedRoute,
|
||||||
protected route: ActivatedRoute
|
protected dialogService: DialogServiceAbstraction
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
async ngOnInit() {
|
async ngOnInit() {
|
||||||
this.route?.queryParams.subscribe((params) => {
|
|
||||||
this.redirectPath = params?.redirectPath;
|
|
||||||
this.sessionId = params?.sessionId;
|
|
||||||
});
|
|
||||||
|
|
||||||
//use redirectPath to redirect to a specific page after successful login
|
|
||||||
if (this.redirectPath) {
|
|
||||||
this.successRoute = this.redirectPath;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.stateService.activeAccount$
|
this.stateService.activeAccount$
|
||||||
.pipe(
|
.pipe(
|
||||||
concatMap(async () => {
|
concatMap(async () => {
|
||||||
@ -279,6 +268,13 @@ export class LockComponent implements OnInit, OnDestroy {
|
|||||||
await this.stateService.setEverBeenUnlocked(true);
|
await this.stateService.setEverBeenUnlocked(true);
|
||||||
this.messagingService.send("unlocked");
|
this.messagingService.send("unlocked");
|
||||||
|
|
||||||
|
// The `redirectUrl` parameter determines the target route after a successful login.
|
||||||
|
// If provided in the URL's query parameters, the user will be redirected
|
||||||
|
// to the specified path once they are authenticated.
|
||||||
|
if (this.route.snapshot.queryParams.redirectUrl) {
|
||||||
|
this.successRoute = decodeURIComponent(this.route.snapshot.queryParams.redirectUrl);
|
||||||
|
}
|
||||||
|
|
||||||
if (evaluatePasswordAfterUnlock) {
|
if (evaluatePasswordAfterUnlock) {
|
||||||
try {
|
try {
|
||||||
// If we do not have any saved policies, attempt to load them from the service
|
// If we do not have any saved policies, attempt to load them from the service
|
||||||
@ -304,11 +300,7 @@ export class LockComponent implements OnInit, OnDestroy {
|
|||||||
if (this.onSuccessfulSubmit != null) {
|
if (this.onSuccessfulSubmit != null) {
|
||||||
await this.onSuccessfulSubmit();
|
await this.onSuccessfulSubmit();
|
||||||
} else if (this.router != null) {
|
} else if (this.router != null) {
|
||||||
this.router.navigate([this.successRoute], {
|
this.router.navigateByUrl(this.successRoute);
|
||||||
queryParams: {
|
|
||||||
sessionId: this.sessionId,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,7 +1,8 @@
|
|||||||
import { Directive, ElementRef, NgZone, OnInit, ViewChild } from "@angular/core";
|
import { Directive, ElementRef, NgZone, OnInit, ViewChild } from "@angular/core";
|
||||||
import { FormBuilder, Validators } from "@angular/forms";
|
import { FormBuilder, Validators } from "@angular/forms";
|
||||||
import { ActivatedRoute, Router } from "@angular/router";
|
import { ActivatedRoute, Router } from "@angular/router";
|
||||||
import { take } from "rxjs/operators";
|
import { Subject } from "rxjs";
|
||||||
|
import { take, takeUntil } from "rxjs/operators";
|
||||||
|
|
||||||
import { DevicesApiServiceAbstraction } from "@bitwarden/common/abstractions/devices/devices-api.service.abstraction";
|
import { DevicesApiServiceAbstraction } from "@bitwarden/common/abstractions/devices/devices-api.service.abstraction";
|
||||||
import { AuthService } from "@bitwarden/common/auth/abstractions/auth.service";
|
import { AuthService } from "@bitwarden/common/auth/abstractions/auth.service";
|
||||||
@ -39,8 +40,7 @@ export class LoginComponent extends CaptchaProtectedComponent implements OnInit
|
|||||||
showLoginWithDevice: boolean;
|
showLoginWithDevice: boolean;
|
||||||
validatedEmail = false;
|
validatedEmail = false;
|
||||||
paramEmailSet = false;
|
paramEmailSet = false;
|
||||||
redirectPath: string;
|
redirectUrl: string;
|
||||||
sessionId: string;
|
|
||||||
|
|
||||||
formGroup = this.formBuilder.group({
|
formGroup = this.formBuilder.group({
|
||||||
email: ["", [Validators.required, Validators.email]],
|
email: ["", [Validators.required, Validators.email]],
|
||||||
@ -52,6 +52,8 @@ export class LoginComponent extends CaptchaProtectedComponent implements OnInit
|
|||||||
protected successRoute = "vault";
|
protected successRoute = "vault";
|
||||||
protected forcePasswordResetRoute = "update-temp-password";
|
protected forcePasswordResetRoute = "update-temp-password";
|
||||||
|
|
||||||
|
private destroy$ = new Subject<void>();
|
||||||
|
|
||||||
get loggedEmail() {
|
get loggedEmail() {
|
||||||
return this.formGroup.value.email;
|
return this.formGroup.value.email;
|
||||||
}
|
}
|
||||||
@ -82,21 +84,18 @@ export class LoginComponent extends CaptchaProtectedComponent implements OnInit
|
|||||||
}
|
}
|
||||||
|
|
||||||
async ngOnInit() {
|
async ngOnInit() {
|
||||||
this.route?.queryParams.subscribe((params) => {
|
this.route?.queryParams.pipe(takeUntil(this.destroy$)).subscribe((params) => {
|
||||||
if (params != null) {
|
if (!params) {
|
||||||
const queryParamsEmail = params["email"];
|
return;
|
||||||
this.redirectPath = params?.["redirectPath"];
|
}
|
||||||
this.sessionId = params?.["sessionId"];
|
|
||||||
|
const queryParamsEmail = params.email;
|
||||||
|
|
||||||
if (queryParamsEmail != null && queryParamsEmail.indexOf("@") > -1) {
|
if (queryParamsEmail != null && queryParamsEmail.indexOf("@") > -1) {
|
||||||
this.formGroup.get("email").setValue(queryParamsEmail);
|
this.formGroup.get("email").setValue(queryParamsEmail);
|
||||||
this.loginService.setEmail(queryParamsEmail);
|
this.loginService.setEmail(queryParamsEmail);
|
||||||
this.paramEmailSet = true;
|
this.paramEmailSet = true;
|
||||||
}
|
}
|
||||||
//use redirectPath to redirect to a specific page after successful login
|
|
||||||
if (this.redirectPath) {
|
|
||||||
this.successRoute = this.redirectPath;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
let email = this.loginService.getEmail();
|
let email = this.loginService.getEmail();
|
||||||
|
|
||||||
@ -114,7 +113,20 @@ export class LoginComponent extends CaptchaProtectedComponent implements OnInit
|
|||||||
this.formGroup.get("rememberEmail")?.setValue(rememberEmail);
|
this.formGroup.get("rememberEmail")?.setValue(rememberEmail);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ngOnDestroy() {
|
||||||
|
this.destroy$.next();
|
||||||
|
this.destroy$.complete();
|
||||||
|
}
|
||||||
|
|
||||||
async submit(showToast = true) {
|
async submit(showToast = true) {
|
||||||
|
// The `redirectUrl` parameter determines the target route after a successful login.
|
||||||
|
// If provided in the URL's query parameters, the user will be redirected
|
||||||
|
// to the specified path once they are authenticated.
|
||||||
|
if (this.route.snapshot.queryParams.redirectUrl) {
|
||||||
|
this.redirectUrl = decodeURIComponent(this.route.snapshot.queryParams.redirectUrl);
|
||||||
|
this.successRoute = this.redirectUrl;
|
||||||
|
}
|
||||||
|
|
||||||
const data = this.formGroup.value;
|
const data = this.formGroup.value;
|
||||||
|
|
||||||
await this.setupCaptcha();
|
await this.setupCaptcha();
|
||||||
@ -152,8 +164,7 @@ export class LoginComponent extends CaptchaProtectedComponent implements OnInit
|
|||||||
} else {
|
} else {
|
||||||
this.router.navigate([this.twoFactorRoute], {
|
this.router.navigate([this.twoFactorRoute], {
|
||||||
queryParams: {
|
queryParams: {
|
||||||
redirectPath: this.redirectPath,
|
redirectUrl: this.redirectUrl,
|
||||||
sessionId: this.sessionId,
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -170,11 +181,7 @@ export class LoginComponent extends CaptchaProtectedComponent implements OnInit
|
|||||||
if (this.onSuccessfulLoginNavigate != null) {
|
if (this.onSuccessfulLoginNavigate != null) {
|
||||||
this.onSuccessfulLoginNavigate();
|
this.onSuccessfulLoginNavigate();
|
||||||
} else {
|
} else {
|
||||||
this.router.navigate([this.successRoute], {
|
this.router.navigateByUrl(this.successRoute);
|
||||||
queryParams: {
|
|
||||||
sessionId: this.sessionId,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
@ -39,8 +39,7 @@ export class TwoFactorComponent extends CaptchaProtectedComponent implements OnI
|
|||||||
formPromise: Promise<any>;
|
formPromise: Promise<any>;
|
||||||
emailPromise: Promise<any>;
|
emailPromise: Promise<any>;
|
||||||
identifier: string = null;
|
identifier: string = null;
|
||||||
redirectPath: string;
|
redirectUrl: string;
|
||||||
sessionId: string;
|
|
||||||
onSuccessfulLogin: () => Promise<any>;
|
onSuccessfulLogin: () => Promise<any>;
|
||||||
onSuccessfulLoginNavigate: () => Promise<any>;
|
onSuccessfulLoginNavigate: () => Promise<any>;
|
||||||
|
|
||||||
@ -76,15 +75,6 @@ export class TwoFactorComponent extends CaptchaProtectedComponent implements OnI
|
|||||||
if (qParams.identifier != null) {
|
if (qParams.identifier != null) {
|
||||||
this.identifier = qParams.identifier;
|
this.identifier = qParams.identifier;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (qParams.redirectPath != null) {
|
|
||||||
this.redirectPath = qParams.redirectPath;
|
|
||||||
this.successRoute = this.redirectPath;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (qParams.sessionId != null) {
|
|
||||||
this.sessionId = qParams.sessionId;
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
if (this.needsLock) {
|
if (this.needsLock) {
|
||||||
@ -203,6 +193,13 @@ export class TwoFactorComponent extends CaptchaProtectedComponent implements OnI
|
|||||||
}
|
}
|
||||||
|
|
||||||
async doSubmit() {
|
async doSubmit() {
|
||||||
|
// The `redirectUrl` parameter determines the target route after a successful login.
|
||||||
|
// If provided in the URL's query parameters, the user will be redirected
|
||||||
|
// to the specified path once they are authenticated.
|
||||||
|
if (this.route.snapshot.queryParams.redirectUrl) {
|
||||||
|
this.successRoute = decodeURIComponent(this.route.snapshot.queryParams.redirectUrl);
|
||||||
|
}
|
||||||
|
|
||||||
this.formPromise = this.authService.logInTwoFactor(
|
this.formPromise = this.authService.logInTwoFactor(
|
||||||
new TokenTwoFactorRequest(this.selectedProviderType, this.token, this.remember),
|
new TokenTwoFactorRequest(this.selectedProviderType, this.token, this.remember),
|
||||||
this.captchaToken
|
this.captchaToken
|
||||||
@ -228,12 +225,7 @@ export class TwoFactorComponent extends CaptchaProtectedComponent implements OnI
|
|||||||
await this.onSuccessfulLoginNavigate();
|
await this.onSuccessfulLoginNavigate();
|
||||||
} else {
|
} else {
|
||||||
this.loginService.clearValues();
|
this.loginService.clearValues();
|
||||||
this.router.navigate([this.successRoute], {
|
this.router.navigateByUrl(this.successRoute);
|
||||||
queryParams: {
|
|
||||||
identifier: this.identifier,
|
|
||||||
sessionId: this.sessionId,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user