1
0
mirror of https://github.com/bitwarden/browser synced 2026-02-23 16:13:21 +00:00

feat(change-password-component): Change Password Update [18720] - Very close to complete.

This commit is contained in:
Patrick Pimentel
2025-05-21 14:55:31 -04:00
parent 27884d9ffe
commit f45e2d7d8a
12 changed files with 121 additions and 25 deletions

View File

@@ -1,14 +1,18 @@
import { Component, Input, OnInit } from "@angular/core";
import { Router } from "@angular/router";
import { firstValueFrom } from "rxjs";
import { PolicyService } from "@bitwarden/common/admin-console/abstractions/policy/policy.service.abstraction";
import { MasterPasswordPolicyOptions } from "@bitwarden/common/admin-console/models/domain/master-password-policy-options";
import { Account, AccountService } from "@bitwarden/common/auth/abstractions/account.service";
import { ForceSetPasswordReason } from "@bitwarden/common/auth/models/domain/force-set-password-reason";
import { InternalMasterPasswordServiceAbstraction } from "@bitwarden/common/key-management/master-password/abstractions/master-password.service.abstraction";
import { ConfigService } from "@bitwarden/common/platform/abstractions/config/config.service";
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
import { MessagingService } from "@bitwarden/common/platform/abstractions/messaging.service";
import { SyncService } from "@bitwarden/common/platform/sync";
import { UserId } from "@bitwarden/common/types/guid";
import { ToastService } from "@bitwarden/components";
import { DialogService, ToastService, Translation } from "@bitwarden/components";
import { I18nPipe } from "@bitwarden/ui-common";
import {
@@ -30,35 +34,65 @@ export class ChangePasswordComponent implements OnInit {
activeAccount: Account | null = null;
email?: string;
userId?: UserId;
activeUserId?: UserId;
masterPasswordPolicyOptions?: MasterPasswordPolicyOptions;
initializing = true;
submitting = false;
formPromise?: Promise<any>;
forceSetPasswordReason: ForceSetPasswordReason = ForceSetPasswordReason.None;
warningText?: Translation;
constructor(
private accountService: AccountService,
private changePasswordService: ChangePasswordService,
private configService: ConfigService,
private i18nService: I18nService,
private masterPasswordService: InternalMasterPasswordServiceAbstraction,
private messagingService: MessagingService,
private policyService: PolicyService,
private toastService: ToastService,
private syncService: SyncService,
// private routerService: RouterService,
// private acceptOrganizationInviteService: AcceptOrganizationInviteService,
private dialogService: DialogService,
private router: Router,
) {}
async ngOnInit() {
this.activeAccount = await firstValueFrom(this.accountService.activeAccount$);
this.userId = this.activeAccount?.id;
this.activeUserId = this.activeAccount?.id;
this.email = this.activeAccount?.email;
if (!this.userId) {
if (!this.activeUserId) {
throw new Error("userId not found");
}
this.masterPasswordPolicyOptions = await firstValueFrom(
this.policyService.masterPasswordPolicyOptions$(this.userId),
this.policyService.masterPasswordPolicyOptions$(this.activeUserId),
);
this.forceSetPasswordReason = await firstValueFrom(
this.masterPasswordService.forceSetPasswordReason$(this.activeUserId),
);
this.initializing = false;
if (this.masterPasswordPolicyOptions?.enforceOnLogin) {
this.warningText = { key: "masterPasswordInvalidWarning" };
}
}
async logOut() {
const confirmed = await this.dialogService.openSimpleDialog({
title: { key: "logOut" },
content: { key: "logOutConfirmation" },
acceptButtonText: { key: "logOut" },
type: "warning",
});
if (confirmed) {
this.messagingService.send("logout");
}
}
async handlePasswordFormSubmit(passwordInputResult: PasswordInputResult) {
@@ -83,11 +117,11 @@ export class ChangePasswordComponent implements OnInit {
passwordInputResult.newPasswordHint,
);
} else {
if (!this.userId) {
if (!this.activeUserId) {
throw new Error("userId not found");
}
await this.changePasswordService.changePassword(passwordInputResult, this.userId);
await this.changePasswordService.changePassword(passwordInputResult, this.activeUserId);
this.toastService.showToast({
variant: "success",