Generator cleanup (#753)
* type is null by default * rename generator component * remove showWebsiteOption * shorthand if check
This commit is contained in:
parent
e0da3116f1
commit
4d58200ee9
|
@ -10,9 +10,9 @@ import { UsernameGenerationService } from "jslib-common/abstractions/usernameGen
|
||||||
import { PasswordGeneratorPolicyOptions } from "jslib-common/models/domain/passwordGeneratorPolicyOptions";
|
import { PasswordGeneratorPolicyOptions } from "jslib-common/models/domain/passwordGeneratorPolicyOptions";
|
||||||
|
|
||||||
@Directive()
|
@Directive()
|
||||||
export class PasswordGeneratorComponent implements OnInit {
|
export class GeneratorComponent implements OnInit {
|
||||||
@Input() showSelect = false;
|
@Input() comingFromAddEdit = false;
|
||||||
@Input() type = "password";
|
@Input() type: string;
|
||||||
@Output() onSelected = new EventEmitter<string>();
|
@Output() onSelected = new EventEmitter<string>();
|
||||||
|
|
||||||
typeOptions: any[];
|
typeOptions: any[];
|
||||||
|
@ -27,7 +27,6 @@ export class PasswordGeneratorComponent implements OnInit {
|
||||||
password = "-";
|
password = "-";
|
||||||
showOptions = false;
|
showOptions = false;
|
||||||
avoidAmbiguous = false;
|
avoidAmbiguous = false;
|
||||||
showWebsiteOption = false;
|
|
||||||
enforcedPasswordPolicyOptions: PasswordGeneratorPolicyOptions;
|
enforcedPasswordPolicyOptions: PasswordGeneratorPolicyOptions;
|
||||||
usernameWebsite: string = null;
|
usernameWebsite: string = null;
|
||||||
|
|
||||||
|
@ -78,11 +77,6 @@ export class PasswordGeneratorComponent implements OnInit {
|
||||||
this.passwordOptions.type =
|
this.passwordOptions.type =
|
||||||
this.passwordOptions.type === "passphrase" ? "passphrase" : "password";
|
this.passwordOptions.type === "passphrase" ? "passphrase" : "password";
|
||||||
|
|
||||||
if (this.showWebsiteOption) {
|
|
||||||
const websiteOption = { name: this.i18nService.t("websiteName"), value: "website-name" };
|
|
||||||
this.subaddressOptions.push(websiteOption);
|
|
||||||
this.catchallOptions.push(websiteOption);
|
|
||||||
}
|
|
||||||
this.usernameOptions = await this.usernameGenerationService.getOptions();
|
this.usernameOptions = await this.usernameGenerationService.getOptions();
|
||||||
if (this.usernameOptions.type == null) {
|
if (this.usernameOptions.type == null) {
|
||||||
this.usernameOptions.type = "word";
|
this.usernameOptions.type = "word";
|
||||||
|
@ -93,19 +87,21 @@ export class PasswordGeneratorComponent implements OnInit {
|
||||||
) {
|
) {
|
||||||
this.usernameOptions.subaddressEmail = await this.stateService.getEmail();
|
this.usernameOptions.subaddressEmail = await this.stateService.getEmail();
|
||||||
}
|
}
|
||||||
if (!this.showWebsiteOption) {
|
if (this.usernameWebsite == null) {
|
||||||
this.usernameOptions.subaddressType = this.usernameOptions.catchallType = "random";
|
this.usernameOptions.subaddressType = this.usernameOptions.catchallType = "random";
|
||||||
}
|
} else {
|
||||||
if (this.usernameWebsite != null) {
|
|
||||||
this.usernameOptions.website = this.usernameWebsite;
|
this.usernameOptions.website = this.usernameWebsite;
|
||||||
|
const websiteOption = { name: this.i18nService.t("websiteName"), value: "website-name" };
|
||||||
|
this.subaddressOptions.push(websiteOption);
|
||||||
|
this.catchallOptions.push(websiteOption);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (this.type !== "username" && this.type !== "password") {
|
||||||
if (qParams.type === "username" || qParams.type === "password") {
|
if (qParams.type === "username" || qParams.type === "password") {
|
||||||
this.type = qParams.type;
|
this.type = qParams.type;
|
||||||
} else {
|
} else {
|
||||||
const generatorOptions = await this.stateService.getGeneratorOptions();
|
const generatorOptions = await this.stateService.getGeneratorOptions();
|
||||||
if (generatorOptions != null && generatorOptions.type != null) {
|
this.type = generatorOptions?.type ?? "password";
|
||||||
this.type = generatorOptions.type;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
await this.regenerate();
|
await this.regenerate();
|
Loading…
Reference in New Issue