bitwarden-estensione-browser/apps/browser/src/popup/generator/generator.component.ts

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

72 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-06-14 17:10:53 +02:00
import { GeneratorComponent as BaseGeneratorComponent } from "@bitwarden/angular/components/generator.component";
import { I18nService } from "@bitwarden/common/abstractions/i18n.service";
import { LogService } from "@bitwarden/common/abstractions/log.service";
import { PasswordGenerationService } from "@bitwarden/common/abstractions/passwordGeneration.service";
import { PlatformUtilsService } from "@bitwarden/common/abstractions/platformUtils.service";
import { StateService } from "@bitwarden/common/abstractions/state.service";
import { UsernameGenerationService } from "@bitwarden/common/abstractions/usernameGeneration.service";
import { CipherView } from "@bitwarden/common/models/view/cipherView";
2018-04-09 23:35:16 +02:00
@Component({
selector: "app-generator",
templateUrl: "generator.component.html",
2018-04-09 23:35:16 +02:00
})
export class GeneratorComponent extends BaseGeneratorComponent {
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,
logService: LogService,
private location: Location
) {
super(
passwordGenerationService,
usernameGenerationService,
platformUtilsService,
stateService,
i18nService,
logService,
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
}
this.comingFromAddEdit = this.cipherState != null;
if (this.cipherState?.login?.hasUris) {
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
}