mirror of
https://github.com/bitwarden/browser
synced 2026-02-09 05:00:10 +00:00
make userId a component property on ChangePasswordComponent, and pass userId down to child InputPasswordComponent
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
<auth-input-password
|
||||
[inputPasswordFlow]="inputPasswordFlow"
|
||||
[email]="email"
|
||||
[userId]="userId"
|
||||
[masterPasswordPolicyOptions]="masterPasswordPolicyOptions"
|
||||
[inlineButtons]="true"
|
||||
[primaryButtonText]="{ key: 'changeMasterPassword' }"
|
||||
|
||||
@@ -7,7 +7,6 @@ import { MasterPasswordPolicyOptions } from "@bitwarden/common/admin-console/mod
|
||||
import { AccountService } from "@bitwarden/common/auth/abstractions/account.service";
|
||||
import { MasterPasswordApiService } from "@bitwarden/common/auth/abstractions/master-password-api.service.abstraction";
|
||||
import { PasswordRequest } from "@bitwarden/common/auth/models/request/password.request";
|
||||
import { getUserId } from "@bitwarden/common/auth/services/account.service";
|
||||
import { FeatureFlag } from "@bitwarden/common/enums/feature-flag.enum";
|
||||
import { InternalMasterPasswordServiceAbstraction } from "@bitwarden/common/key-management/master-password/abstractions/master-password.service.abstraction";
|
||||
import { ConfigService } from "@bitwarden/common/platform/abstractions/config/config.service";
|
||||
@@ -36,6 +35,7 @@ export class ChangePasswordComponent implements OnInit {
|
||||
@Input() inputPasswordFlow: InputPasswordFlow = InputPasswordFlow.ChangePassword;
|
||||
|
||||
email?: string;
|
||||
userId?: UserId;
|
||||
masterPasswordPolicyOptions?: MasterPasswordPolicyOptions;
|
||||
userkeyRotationV2 = false;
|
||||
formPromise?: Promise<any>;
|
||||
@@ -58,11 +58,11 @@ export class ChangePasswordComponent implements OnInit {
|
||||
this.userkeyRotationV2 = await this.configService.getFeatureFlag(FeatureFlag.UserKeyRotationV2);
|
||||
|
||||
const activeAccount = await firstValueFrom(this.accountService.activeAccount$);
|
||||
const userId = activeAccount.id;
|
||||
this.email = activeAccount.email;
|
||||
this.userId = activeAccount?.id;
|
||||
this.email = activeAccount?.email;
|
||||
|
||||
this.masterPasswordPolicyOptions = await firstValueFrom(
|
||||
this.policyService.masterPasswordPolicyOptions$(userId),
|
||||
this.policyService.masterPasswordPolicyOptions$(this.userId),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -133,8 +133,6 @@ export class ChangePasswordComponent implements OnInit {
|
||||
await this.syncService.fullSync(true);
|
||||
}
|
||||
|
||||
const userId = await firstValueFrom(getUserId(this.accountService.activeAccount$));
|
||||
|
||||
let newMasterKeyEncryptedUserKey: [UserKey, EncString] | null = null;
|
||||
|
||||
const userKey = await this.keyService.getUserKey();
|
||||
@@ -160,11 +158,11 @@ export class ChangePasswordComponent implements OnInit {
|
||||
// we need to save this for local masterkey verification during rotation
|
||||
await this.masterPasswordService.setMasterKeyHash(
|
||||
passwordInputResult.newLocalMasterKeyHash,
|
||||
userId as UserId,
|
||||
this.userId as UserId,
|
||||
);
|
||||
await this.masterPasswordService.setMasterKey(
|
||||
passwordInputResult.newMasterKey,
|
||||
userId as UserId,
|
||||
this.userId as UserId,
|
||||
);
|
||||
return this.updateKey(passwordInputResult.newPassword);
|
||||
});
|
||||
|
||||
@@ -6,7 +6,6 @@ import {
|
||||
FormGroup,
|
||||
FormControl,
|
||||
} from "@angular/forms";
|
||||
import { firstValueFrom } from "rxjs";
|
||||
|
||||
import { JslibModule } from "@bitwarden/angular/jslib.module";
|
||||
import {
|
||||
@@ -17,12 +16,12 @@ import { AuditService } from "@bitwarden/common/abstractions/audit.service";
|
||||
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";
|
||||
import { getUserId } from "@bitwarden/common/auth/services/account.service";
|
||||
import { MasterPasswordServiceAbstraction } from "@bitwarden/common/key-management/master-password/abstractions/master-password.service.abstraction";
|
||||
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
|
||||
import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service";
|
||||
import { HashPurpose } from "@bitwarden/common/platform/enums";
|
||||
import { Utils } from "@bitwarden/common/platform/misc/utils";
|
||||
import { UserId } from "@bitwarden/common/types/guid";
|
||||
import { CipherService } from "@bitwarden/common/vault/abstractions/cipher.service";
|
||||
import {
|
||||
AsyncActionsModule,
|
||||
@@ -97,6 +96,7 @@ export class InputPasswordComponent implements OnInit {
|
||||
|
||||
@Input({ required: true }) inputPasswordFlow!: InputPasswordFlow;
|
||||
@Input({ required: true }) email!: string;
|
||||
@Input({ required: true }) userId!: UserId;
|
||||
|
||||
@Input() loading = false;
|
||||
@Input() masterPasswordPolicyOptions: MasterPasswordPolicyOptions | null = null;
|
||||
@@ -235,7 +235,10 @@ export class InputPasswordComponent implements OnInit {
|
||||
this.inputPasswordFlow ===
|
||||
InputPasswordFlow.ChangeExistingPasswordAndOptionallyRotateAccountEncryptionKey
|
||||
) {
|
||||
const currentPasswordIsCorrect = await this.verifyCurrentPassword(currentPassword);
|
||||
const currentPasswordIsCorrect = await this.verifyCurrentPassword(
|
||||
currentPassword,
|
||||
this.userId,
|
||||
);
|
||||
if (!currentPasswordIsCorrect) {
|
||||
return;
|
||||
}
|
||||
@@ -321,9 +324,7 @@ export class InputPasswordComponent implements OnInit {
|
||||
/**
|
||||
* Returns true if the current password is correct, false otherwise
|
||||
*/
|
||||
private async verifyCurrentPassword(currentPassword: string): Promise<boolean> {
|
||||
const userId = await firstValueFrom(getUserId(this.accountService.activeAccount$));
|
||||
|
||||
private async verifyCurrentPassword(currentPassword: string, userId: UserId): Promise<boolean> {
|
||||
const currentMasterKey = await this.keyService.makeMasterKey(
|
||||
currentPassword,
|
||||
this.email.trim().toLowerCase(),
|
||||
@@ -423,9 +424,7 @@ export class InputPasswordComponent implements OnInit {
|
||||
const rotateUserKey = rotateUserKeyCtrl?.value;
|
||||
|
||||
if (rotateUserKey) {
|
||||
const activeUserId = await firstValueFrom(this.accountService.activeAccount$.pipe(getUserId));
|
||||
|
||||
const ciphers = await this.cipherService.getAllDecrypted(activeUserId);
|
||||
const ciphers = await this.cipherService.getAllDecrypted(this.userId);
|
||||
let hasOldAttachments = false;
|
||||
if (ciphers != null) {
|
||||
for (let i = 0; i < ciphers.length; i++) {
|
||||
|
||||
Reference in New Issue
Block a user