mirror of
https://github.com/bitwarden/browser.git
synced 2024-12-25 16:59:17 +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:
parent
739c76a24f
commit
f1ac1d44e3
@ -27,6 +27,7 @@
|
||||
bitIconButton="bwi-generate"
|
||||
bitSuffix
|
||||
[appA11yTitle]="'generatePassword' | i18n"
|
||||
(click)="generatePassword()"
|
||||
data-testid="generate-password"
|
||||
></button>
|
||||
<bit-hint>{{ "sendPasswordDescV2" | i18n }}</bit-hint>
|
||||
|
@ -2,7 +2,7 @@ import { CommonModule } from "@angular/common";
|
||||
import { Component, Input, OnInit } from "@angular/core";
|
||||
import { takeUntilDestroyed } from "@angular/core/rxjs-interop";
|
||||
import { FormBuilder, ReactiveFormsModule } from "@angular/forms";
|
||||
import { map } from "rxjs";
|
||||
import { firstValueFrom, map } from "rxjs";
|
||||
|
||||
import { JslibModule } from "@bitwarden/angular/jslib.module";
|
||||
import { PolicyService } from "@bitwarden/common/admin-console/abstractions/policy/policy.service.abstraction";
|
||||
@ -17,6 +17,7 @@ import {
|
||||
SectionHeaderComponent,
|
||||
TypographyModule,
|
||||
} from "@bitwarden/components";
|
||||
import { CredentialGeneratorService, Generators } from "@bitwarden/generator-core";
|
||||
|
||||
import { SendFormConfig } from "../../abstractions/send-form-config.service";
|
||||
import { SendFormContainer } from "../../send-form-container";
|
||||
@ -72,6 +73,7 @@ export class SendOptionsComponent implements OnInit {
|
||||
private sendFormContainer: SendFormContainer,
|
||||
private formBuilder: FormBuilder,
|
||||
private policyService: PolicyService,
|
||||
private generatorService: CredentialGeneratorService,
|
||||
) {
|
||||
this.sendFormContainer.registerChildForm("sendOptionsForm", this.sendOptionsForm);
|
||||
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() {
|
||||
if (this.sendFormContainer.originalSendView) {
|
||||
this.sendOptionsForm.patchValue({
|
||||
|
@ -1,9 +1,22 @@
|
||||
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 { SendFormComponent } from "./components/send-form.component";
|
||||
import { DefaultSendFormService } from "./services/default-send-form.service";
|
||||
|
||||
const RANDOMIZER = new SafeInjectionToken<Randomizer>("Randomizer");
|
||||
|
||||
@NgModule({
|
||||
imports: [SendFormComponent],
|
||||
providers: [
|
||||
@ -11,6 +24,16 @@ import { DefaultSendFormService } from "./services/default-send-form.service";
|
||||
provide: SendFormService,
|
||||
useClass: DefaultSendFormService,
|
||||
},
|
||||
safeProvider({
|
||||
provide: RANDOMIZER,
|
||||
useFactory: createRandomizer,
|
||||
deps: [CryptoService],
|
||||
}),
|
||||
safeProvider({
|
||||
useClass: CredentialGeneratorService,
|
||||
provide: CredentialGeneratorService,
|
||||
deps: [RANDOMIZER, StateProvider, PolicyService],
|
||||
}),
|
||||
],
|
||||
exports: [SendFormComponent],
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user