bitwarden-estensione-browser/src/popup/generator/password-generator.componen...

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

71 lines
2.4 KiB
TypeScript
Raw Normal View History

2018-04-09 23:35:16 +02:00
import { Location } from "@angular/common";
2018-04-10 15:38:21 +02:00
import { Component } from "@angular/core";
import { ActivatedRoute } from "@angular/router";
2018-04-09 23:35:16 +02:00
2022-02-24 18:14:04 +01:00
import { PasswordGeneratorComponent as BasePasswordGeneratorComponent } from "jslib-angular/components/password-generator.component";
import { I18nService } from "jslib-common/abstractions/i18n.service";
import { PasswordGenerationService } from "jslib-common/abstractions/passwordGeneration.service";
import { PlatformUtilsService } from "jslib-common/abstractions/platformUtils.service";
import { StateService } from "jslib-common/abstractions/state.service";
import { UsernameGenerationService } from "jslib-common/abstractions/usernameGeneration.service";
import { CipherView } from "jslib-common/models/view/cipherView";
2018-04-09 23:35:16 +02:00
@Component({
selector: "app-password-generator",
templateUrl: "password-generator.component.html",
})
export class PasswordGeneratorComponent extends BasePasswordGeneratorComponent {
private addEditCipherInfo: any;
2018-04-09 23:35:16 +02:00
private cipherState: CipherView;
2021-12-21 15:43:35 +01:00
constructor(
passwordGenerationService: PasswordGenerationService,
usernameGenerationService: UsernameGenerationService,
platformUtilsService: PlatformUtilsService,
i18nService: I18nService,
stateService: StateService,
route: ActivatedRoute,
private location: Location
) {
super(
passwordGenerationService,
usernameGenerationService,
platformUtilsService,
stateService,
i18nService,
route,
window
);
2018-04-09 23:35:16 +02:00
}
2021-12-21 15:43:35 +01:00
2018-04-09 23:35:16 +02:00
async ngOnInit() {
this.addEditCipherInfo = await this.stateService.getAddEditCipherInfo();
if (this.addEditCipherInfo != null) {
this.cipherState = this.addEditCipherInfo.cipher;
2018-04-09 23:35:16 +02:00
}
2018-04-10 15:38:21 +02:00
this.showSelect = this.cipherState != null;
this.showWebsiteOption =
this.cipherState?.login?.hasUris && this.cipherState.login.uris[0].hostname != null;
if (this.showWebsiteOption) {
this.usernameWebsite = this.cipherState.login.uris[0].hostname;
}
await super.ngOnInit();
2021-12-21 15:43:35 +01:00
}
2018-04-09 23:35:16 +02:00
select() {
super.select();
if (this.type === "password") {
this.cipherState.login.password = this.password;
} else if (this.type === "username") {
this.cipherState.login.username = this.username;
}
this.addEditCipherInfo.cipher = this.cipherState;
this.stateService.setAddEditCipherInfo(this.addEditCipherInfo);
2018-04-09 23:35:16 +02:00
this.close();
2021-12-21 15:43:35 +01:00
}
2018-04-09 23:35:16 +02:00
close() {
this.location.back();
2021-12-21 15:43:35 +01:00
}
2018-04-09 23:35:16 +02:00
}