1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-11-28 12:45:45 +01:00

[PM-12716] - add missing password generation function to send form password (#11273)

* add generatePassword function to send options

* add generatePassword function
This commit is contained in:
Jordan Aasen 2024-09-27 04:42:14 -07:00 committed by GitHub
parent 739c76a24f
commit f1ac1d44e3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 37 additions and 1 deletions

View File

@ -27,6 +27,7 @@
bitIconButton="bwi-generate" bitIconButton="bwi-generate"
bitSuffix bitSuffix
[appA11yTitle]="'generatePassword' | i18n" [appA11yTitle]="'generatePassword' | i18n"
(click)="generatePassword()"
data-testid="generate-password" data-testid="generate-password"
></button> ></button>
<bit-hint>{{ "sendPasswordDescV2" | i18n }}</bit-hint> <bit-hint>{{ "sendPasswordDescV2" | i18n }}</bit-hint>

View File

@ -2,7 +2,7 @@ import { CommonModule } from "@angular/common";
import { Component, Input, OnInit } from "@angular/core"; import { Component, Input, OnInit } from "@angular/core";
import { takeUntilDestroyed } from "@angular/core/rxjs-interop"; import { takeUntilDestroyed } from "@angular/core/rxjs-interop";
import { FormBuilder, ReactiveFormsModule } from "@angular/forms"; import { FormBuilder, ReactiveFormsModule } from "@angular/forms";
import { map } from "rxjs"; import { firstValueFrom, map } from "rxjs";
import { JslibModule } from "@bitwarden/angular/jslib.module"; import { JslibModule } from "@bitwarden/angular/jslib.module";
import { PolicyService } from "@bitwarden/common/admin-console/abstractions/policy/policy.service.abstraction"; import { PolicyService } from "@bitwarden/common/admin-console/abstractions/policy/policy.service.abstraction";
@ -17,6 +17,7 @@ import {
SectionHeaderComponent, SectionHeaderComponent,
TypographyModule, TypographyModule,
} from "@bitwarden/components"; } from "@bitwarden/components";
import { CredentialGeneratorService, Generators } from "@bitwarden/generator-core";
import { SendFormConfig } from "../../abstractions/send-form-config.service"; import { SendFormConfig } from "../../abstractions/send-form-config.service";
import { SendFormContainer } from "../../send-form-container"; import { SendFormContainer } from "../../send-form-container";
@ -72,6 +73,7 @@ export class SendOptionsComponent implements OnInit {
private sendFormContainer: SendFormContainer, private sendFormContainer: SendFormContainer,
private formBuilder: FormBuilder, private formBuilder: FormBuilder,
private policyService: PolicyService, private policyService: PolicyService,
private generatorService: CredentialGeneratorService,
) { ) {
this.sendFormContainer.registerChildForm("sendOptionsForm", this.sendOptionsForm); this.sendFormContainer.registerChildForm("sendOptionsForm", this.sendOptionsForm);
this.policyService this.policyService
@ -98,6 +100,16 @@ export class SendOptionsComponent implements OnInit {
}); });
} }
generatePassword = async () => {
const generatedCredential = await firstValueFrom(
this.generatorService.generate$(Generators.Password),
);
this.sendOptionsForm.patchValue({
password: generatedCredential.credential,
});
};
ngOnInit() { ngOnInit() {
if (this.sendFormContainer.originalSendView) { if (this.sendFormContainer.originalSendView) {
this.sendOptionsForm.patchValue({ this.sendOptionsForm.patchValue({

View File

@ -1,9 +1,22 @@
import { NgModule } from "@angular/core"; import { NgModule } from "@angular/core";
import { safeProvider } from "@bitwarden/angular/platform/utils/safe-provider";
import { SafeInjectionToken } from "@bitwarden/angular/services/injection-tokens";
import { PolicyService } from "@bitwarden/common/admin-console/abstractions/policy/policy.service.abstraction";
import { CryptoService } from "@bitwarden/common/platform/abstractions/crypto.service";
import { StateProvider } from "@bitwarden/common/platform/state";
import {
createRandomizer,
CredentialGeneratorService,
Randomizer,
} from "@bitwarden/generator-core";
import { SendFormService } from "./abstractions/send-form.service"; import { SendFormService } from "./abstractions/send-form.service";
import { SendFormComponent } from "./components/send-form.component"; import { SendFormComponent } from "./components/send-form.component";
import { DefaultSendFormService } from "./services/default-send-form.service"; import { DefaultSendFormService } from "./services/default-send-form.service";
const RANDOMIZER = new SafeInjectionToken<Randomizer>("Randomizer");
@NgModule({ @NgModule({
imports: [SendFormComponent], imports: [SendFormComponent],
providers: [ providers: [
@ -11,6 +24,16 @@ import { DefaultSendFormService } from "./services/default-send-form.service";
provide: SendFormService, provide: SendFormService,
useClass: DefaultSendFormService, useClass: DefaultSendFormService,
}, },
safeProvider({
provide: RANDOMIZER,
useFactory: createRandomizer,
deps: [CryptoService],
}),
safeProvider({
useClass: CredentialGeneratorService,
provide: CredentialGeneratorService,
deps: [RANDOMIZER, StateProvider, PolicyService],
}),
], ],
exports: [SendFormComponent], exports: [SendFormComponent],
}) })