mirror of
https://github.com/bitwarden/browser
synced 2025-12-17 08:43:33 +00:00
[PM-5611] username generator panel (#11201)
* add username and email engines to generators * introduce username and email settings components * introduce generator algorithm metadata * inline generator policies * wait until settings are available during generation
This commit is contained in:
@@ -3,8 +3,12 @@ import { BehaviorSubject, distinctUntilChanged, map, Subject, switchMap, takeUnt
|
||||
|
||||
import { AccountService } from "@bitwarden/common/auth/abstractions/account.service";
|
||||
import { UserId } from "@bitwarden/common/types/guid";
|
||||
import { CredentialGeneratorService, Generators, GeneratorType } from "@bitwarden/generator-core";
|
||||
import { GeneratedCredential } from "@bitwarden/generator-history";
|
||||
import {
|
||||
CredentialGeneratorService,
|
||||
Generators,
|
||||
PasswordAlgorithm,
|
||||
GeneratedCredential,
|
||||
} from "@bitwarden/generator-core";
|
||||
|
||||
import { DependenciesModule } from "./dependencies";
|
||||
import { PassphraseSettingsComponent } from "./passphrase-settings.component";
|
||||
@@ -24,7 +28,7 @@ export class PasswordGeneratorComponent implements OnInit, OnDestroy {
|
||||
private zone: NgZone,
|
||||
) {}
|
||||
|
||||
/** Binds the passphrase component to a specific user's settings.
|
||||
/** Binds the component to a specific user's settings.
|
||||
* When this input is not provided, the form binds to the active
|
||||
* user
|
||||
*/
|
||||
@@ -32,7 +36,7 @@ export class PasswordGeneratorComponent implements OnInit, OnDestroy {
|
||||
userId: UserId | null;
|
||||
|
||||
/** tracks the currently selected credential type */
|
||||
protected credentialType$ = new BehaviorSubject<GeneratorType>("password");
|
||||
protected credentialType$ = new BehaviorSubject<PasswordAlgorithm>("password");
|
||||
|
||||
/** Emits the last generated value. */
|
||||
protected readonly value$ = new BehaviorSubject<string>("");
|
||||
@@ -46,7 +50,7 @@ export class PasswordGeneratorComponent implements OnInit, OnDestroy {
|
||||
/** Tracks changes to the selected credential type
|
||||
* @param type the new credential type
|
||||
*/
|
||||
protected onCredentialTypeChanged(type: GeneratorType) {
|
||||
protected onCredentialTypeChanged(type: PasswordAlgorithm) {
|
||||
if (this.credentialType$.value !== type) {
|
||||
this.credentialType$.next(type);
|
||||
this.generate$.next();
|
||||
@@ -85,7 +89,7 @@ export class PasswordGeneratorComponent implements OnInit, OnDestroy {
|
||||
});
|
||||
}
|
||||
|
||||
private typeToGenerator$(type: GeneratorType) {
|
||||
private typeToGenerator$(type: PasswordAlgorithm) {
|
||||
const dependencies = {
|
||||
on$: this.generate$,
|
||||
userId$: this.userId$,
|
||||
@@ -93,10 +97,10 @@ export class PasswordGeneratorComponent implements OnInit, OnDestroy {
|
||||
|
||||
switch (type) {
|
||||
case "password":
|
||||
return this.generatorService.generate$(Generators.Password, dependencies);
|
||||
return this.generatorService.generate$(Generators.password, dependencies);
|
||||
|
||||
case "passphrase":
|
||||
return this.generatorService.generate$(Generators.Passphrase, dependencies);
|
||||
return this.generatorService.generate$(Generators.passphrase, dependencies);
|
||||
default:
|
||||
throw new Error(`Invalid generator type: "${type}"`);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user