1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-16 16:23:44 +00:00

handle submit routing (web)

This commit is contained in:
rr-bw
2024-09-02 09:31:10 -07:00
parent 19acf12900
commit 48ffd0b5d6
4 changed files with 48 additions and 6 deletions

View File

@@ -57,6 +57,7 @@ import {
ThemeStateService, ThemeStateService,
} from "@bitwarden/common/platform/theming/theme-state.service"; } from "@bitwarden/common/platform/theming/theme-state.service";
import { VaultTimeout, VaultTimeoutStringType } from "@bitwarden/common/types/vault-timeout.type"; import { VaultTimeout, VaultTimeoutStringType } from "@bitwarden/common/types/vault-timeout.type";
import { ToastService } from "@bitwarden/components";
import { PolicyListService } from "../admin-console/core/policy-list.service"; import { PolicyListService } from "../admin-console/core/policy-list.service";
import { WebSetPasswordJitService, WebRegistrationFinishService, WebLoginService } from "../auth"; import { WebSetPasswordJitService, WebRegistrationFinishService, WebLoginService } from "../auth";
@@ -211,7 +212,7 @@ const safeProviders: SafeProvider[] = [
safeProvider({ safeProvider({
provide: LoginService, provide: LoginService,
useClass: WebLoginService, useClass: WebLoginService,
deps: [], deps: [I18nServiceAbstraction, ToastService],
}), }),
]; ];

View File

@@ -193,6 +193,7 @@ export class LoginComponent extends CaptchaProtectedComponent implements OnInit,
// eslint-disable-next-line @typescript-eslint/no-floating-promises // eslint-disable-next-line @typescript-eslint/no-floating-promises
this.onSuccessfulLogin(); this.onSuccessfulLogin();
} }
if (this.onSuccessfulLoginNavigate != null) { if (this.onSuccessfulLoginNavigate != null) {
// FIXME: Verify that this floating promise is intentional. If it is, add an explanatory comment and ensure there is proper error handling. // FIXME: Verify that this floating promise is intentional. If it is, add an explanatory comment and ensure there is proper error handling.
// eslint-disable-next-line @typescript-eslint/no-floating-promises // eslint-disable-next-line @typescript-eslint/no-floating-promises

View File

@@ -1302,7 +1302,7 @@ const safeProviders: SafeProvider[] = [
safeProvider({ safeProvider({
provide: LoginService, provide: LoginService,
useClass: DefaultLoginService, useClass: DefaultLoginService,
deps: [], deps: [I18nServiceAbstraction, ToastService],
}), }),
]; ];

View File

@@ -11,6 +11,8 @@ import {
PasswordLoginCredentials, PasswordLoginCredentials,
RegisterRouteService, RegisterRouteService,
} from "@bitwarden/auth/common"; } from "@bitwarden/auth/common";
import { InternalPolicyService } from "@bitwarden/common/admin-console/abstractions/policy/policy.service.abstraction";
import { PolicyData } from "@bitwarden/common/admin-console/models/data/policy.data";
import { MasterPasswordPolicyOptions } from "@bitwarden/common/admin-console/models/domain/master-password-policy-options"; import { MasterPasswordPolicyOptions } from "@bitwarden/common/admin-console/models/domain/master-password-policy-options";
import { Policy } from "@bitwarden/common/admin-console/models/domain/policy"; import { Policy } from "@bitwarden/common/admin-console/models/domain/policy";
import { DevicesApiServiceAbstraction } from "@bitwarden/common/auth/abstractions/devices-api.service.abstraction"; import { DevicesApiServiceAbstraction } from "@bitwarden/common/auth/abstractions/devices-api.service.abstraction";
@@ -22,6 +24,8 @@ import { EnvironmentService } from "@bitwarden/common/platform/abstractions/envi
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service"; import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service"; import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service";
import { Utils } from "@bitwarden/common/platform/misc/utils"; import { Utils } from "@bitwarden/common/platform/misc/utils";
import { PasswordStrengthServiceAbstraction } from "@bitwarden/common/tools/password-strength";
import { UserId } from "@bitwarden/common/types/guid";
import { import {
AsyncActionsModule, AsyncActionsModule,
ButtonModule, ButtonModule,
@@ -93,7 +97,9 @@ export class LoginComponentV2 implements OnInit, OnDestroy {
private loginService: LoginService, private loginService: LoginService,
private loginStrategyService: LoginStrategyServiceAbstraction, private loginStrategyService: LoginStrategyServiceAbstraction,
private ngZone: NgZone, private ngZone: NgZone,
private passwordStrengthService: PasswordStrengthServiceAbstraction,
private platformUtilsService: PlatformUtilsService, private platformUtilsService: PlatformUtilsService,
private policyService: InternalPolicyService,
private registerRouteService: RegisterRouteService, private registerRouteService: RegisterRouteService,
private router: Router, private router: Router,
private toastService: ToastService, private toastService: ToastService,
@@ -170,17 +176,51 @@ export class LoginComponentV2 implements OnInit, OnDestroy {
if (this.handleCaptchaRequired(response)) { if (this.handleCaptchaRequired(response)) {
return; return;
} else if (await this.handleMigrateEncryptionKey(response)) { } else if (await this.loginService.handleMigrateEncryptionKey(response)) {
return; return;
} else if (response.requiresTwoFactor) { } else if (response.requiresTwoFactor) {
// code ... await this.router.navigate(["2fa"]);
} else if (response.forcePasswordReset != ForceSetPasswordReason.None) { } else if (response.forcePasswordReset != ForceSetPasswordReason.None) {
// code ... this.loginEmailService.clearValues();
await this.router.navigate(["update-temp-password"]);
} else { } else {
// code ... // Web specific (start)
await this.goAfterLogIn(response.userId);
// Web specific (end)
} }
}; };
protected async goAfterLogIn(userId: UserId) {
const masterPassword = this.formGroup.value.masterPassword;
// Check master password against policy
if (this.enforcedPasswordPolicyOptions != null) {
const strengthResult = this.passwordStrengthService.getPasswordStrength(
masterPassword,
this.formGroup.value.email,
);
const masterPasswordScore = strengthResult == null ? null : strengthResult.score;
// If invalid, save policies and require update
if (
!this.policyService.evaluateMasterPassword(
masterPasswordScore,
masterPassword,
this.enforcedPasswordPolicyOptions,
)
) {
const policiesData: { [id: string]: PolicyData } = {};
this.policies.map((p) => (policiesData[p.id] = PolicyData.fromPolicy(p)));
await this.policyService.replace(policiesData, userId);
await this.router.navigate(["update-password"]);
return;
}
}
this.loginEmailService.clearValues();
await this.router.navigate(["vault"]);
}
protected async setupCaptcha() { protected async setupCaptcha() {
const env = await firstValueFrom(this.environmentService.environment$); const env = await firstValueFrom(this.environmentService.environment$);
const webVaultUrl = env.getWebVaultUrl(); const webVaultUrl = env.getWebVaultUrl();