1
0
mirror of https://github.com/bitwarden/browser synced 2026-02-09 13:10:17 +00:00

create a ChangePasswordService

This commit is contained in:
rr-bw
2025-03-29 20:37:04 -07:00
parent 0e6ad93371
commit d2fd834a38
6 changed files with 62 additions and 8 deletions

View File

@@ -0,0 +1,26 @@
import { inject } from "@angular/core";
import { ChangePasswordService, DefaultChangePasswordService } from "@bitwarden/auth/common";
import { Account } from "@bitwarden/common/auth/abstractions/account.service";
import { UserKeyRotationService } from "@bitwarden/web-vault/app/key-management/key-rotation/user-key-rotation.service";
export class WebChangePasswordComponent
extends DefaultChangePasswordService
implements ChangePasswordService
{
userKeyRotationService = inject(UserKeyRotationService);
async rotateUserKeyMasterPasswordAndEncryptedData(
currentPassword: string,
newPassword: string,
user: Account,
hint: string,
): Promise<void | null> {
await this.userKeyRotationService.rotateUserKeyMasterPasswordAndEncryptedData(
currentPassword,
newPassword,
user,
hint,
);
}
}

View File

@@ -1,6 +1,7 @@
import { Component, Input, OnInit } from "@angular/core";
import { firstValueFrom, map } from "rxjs";
import { ChangePasswordService } from "@bitwarden/auth/common";
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 { AccountService } from "@bitwarden/common/auth/abstractions/account.service";
@@ -36,6 +37,7 @@ export class ChangeExistingPasswordComponent implements OnInit {
constructor(
private accountService: AccountService,
private changePasswordService: ChangePasswordService,
private configService: ConfigService,
private i18nService: I18nService,
private kdfConfigService: KdfConfigService,
@@ -74,14 +76,14 @@ export class ChangeExistingPasswordComponent implements OnInit {
try {
if (passwordInputResult.rotateUserKey) {
await this.syncService.fullSync(true);
// const user = await firstValueFrom(this.accountService.activeAccount$);
// // TODO-rr-bw: make a ChangeExistingPasswordService with Default & Web implementations
// // await this.changeExistingPasswordService.rotateUserKeyMasterPasswordAndEncryptedData(
// // passwordInputResult.currentPassword,
// // passwordInputResult.newPassword,
// // user,
// // passwordInputResult.hint,
// // );
const user = await firstValueFrom(this.accountService.activeAccount$);
await this.changePasswordService.rotateUserKeyMasterPasswordAndEncryptedData(
passwordInputResult.currentPassword,
passwordInputResult.newPassword,
user,
passwordInputResult.hint,
);
} else {
await this.updatePassword(
passwordInputResult.currentPassword,

View File

@@ -0,0 +1,10 @@
import { Account } from "@bitwarden/common/auth/abstractions/account.service";
export abstract class ChangePasswordService {
abstract rotateUserKeyMasterPasswordAndEncryptedData(
currentPassword: string,
newPassword: string,
user: Account,
hint: string,
): Promise<void | null>;
}

View File

@@ -1,4 +1,5 @@
export * from "./auth-request-api.service";
export * from "./change-password.service.abstraction";
export * from "./pin.service.abstraction";
export * from "./login-email.service";
export * from "./login-strategy.service";

View File

@@ -0,0 +1,14 @@
import { Account } from "@bitwarden/common/auth/abstractions/account.service";
import { ChangePasswordService } from "../../abstractions";
export class DefaultChangePasswordService implements ChangePasswordService {
async rotateUserKeyMasterPasswordAndEncryptedData(
currentPassword: string,
newPassword: string,
user: Account,
hint: string,
): Promise<void | null> {
return null;
}
}

View File

@@ -1,3 +1,4 @@
export * from "./change-password/default-change-password.service";
export * from "./pin/pin.service.implementation";
export * from "./login-email/login-email.service";
export * from "./login-strategies/login-strategy.service";