2018-04-05 21:35:56 +02:00
|
|
|
import {
|
|
|
|
Component,
|
|
|
|
EventEmitter,
|
|
|
|
Input,
|
|
|
|
Output,
|
|
|
|
} from '@angular/core';
|
|
|
|
|
|
|
|
import { ToasterService } from 'angular2-toaster';
|
|
|
|
|
|
|
|
import { CipherType } from 'jslib/enums/cipherType';
|
2019-07-12 21:00:20 +02:00
|
|
|
import { EventType } from 'jslib/enums/eventType';
|
2018-04-05 21:35:56 +02:00
|
|
|
|
|
|
|
import { CipherView } from 'jslib/models/view/cipherView';
|
|
|
|
|
2019-07-12 21:00:20 +02:00
|
|
|
import { EventService } from 'jslib/abstractions/event.service';
|
2018-04-05 21:35:56 +02:00
|
|
|
import { I18nService } from 'jslib/abstractions/i18n.service';
|
|
|
|
import { PlatformUtilsService } from 'jslib/abstractions/platformUtils.service';
|
2020-12-15 17:26:01 +01:00
|
|
|
import { TotpService } from 'jslib/abstractions/totp.service';
|
|
|
|
import { UserService } from 'jslib/abstractions/user.service';
|
2018-04-05 21:35:56 +02:00
|
|
|
|
|
|
|
import { PopupUtilsService } from '../services/popup-utils.service';
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'app-action-buttons',
|
2018-04-06 17:48:45 +02:00
|
|
|
templateUrl: 'action-buttons.component.html',
|
2018-04-05 21:35:56 +02:00
|
|
|
})
|
|
|
|
export class ActionButtonsComponent {
|
|
|
|
@Output() onView = new EventEmitter<CipherView>();
|
2021-01-27 22:45:54 +01:00
|
|
|
@Output() launchEvent = new EventEmitter<CipherView>();
|
2018-04-05 21:35:56 +02:00
|
|
|
@Input() cipher: CipherView;
|
2018-04-06 20:03:35 +02:00
|
|
|
@Input() showView = false;
|
2018-04-05 21:35:56 +02:00
|
|
|
|
|
|
|
cipherType = CipherType;
|
2020-12-15 17:26:01 +01:00
|
|
|
userHasPremiumAccess = false;
|
2018-04-05 21:35:56 +02:00
|
|
|
|
2021-04-14 23:43:09 +02:00
|
|
|
constructor(private toasterService: ToasterService, private i18nService: I18nService,
|
|
|
|
private platformUtilsService: PlatformUtilsService, private eventService: EventService,
|
2020-12-15 17:26:01 +01:00
|
|
|
private totpService: TotpService, private userService: UserService) { }
|
2018-04-05 21:35:56 +02:00
|
|
|
|
2020-12-15 17:26:01 +01:00
|
|
|
async ngOnInit() {
|
|
|
|
this.userHasPremiumAccess = await this.userService.canAccessPremium();
|
|
|
|
}
|
2020-12-17 18:06:31 +01:00
|
|
|
|
2021-01-27 22:45:54 +01:00
|
|
|
launchCipher() {
|
|
|
|
this.launchEvent.emit(this.cipher);
|
2018-04-05 21:35:56 +02:00
|
|
|
}
|
|
|
|
|
2020-12-15 17:26:01 +01:00
|
|
|
async copy(cipher: CipherView, value: string, typeI18nKey: string, aType: string) {
|
2021-01-08 15:48:48 +01:00
|
|
|
if (value == null || aType === 'TOTP' && !this.displayTotpCopyButton(cipher)) {
|
2018-04-05 21:35:56 +02:00
|
|
|
return;
|
2020-12-15 17:26:01 +01:00
|
|
|
} else if (value === cipher.login.totp) {
|
|
|
|
value = await this.totpService.getCode(value);
|
2018-04-05 21:35:56 +02:00
|
|
|
}
|
|
|
|
|
2020-05-24 19:59:49 +02:00
|
|
|
if (!cipher.viewPassword) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-08-13 15:44:59 +02:00
|
|
|
this.platformUtilsService.copyToClipboard(value, { window: window });
|
2018-04-05 21:35:56 +02:00
|
|
|
this.toasterService.popAsync('info', null,
|
|
|
|
this.i18nService.t('valueCopied', this.i18nService.t(typeI18nKey)));
|
2019-07-12 21:00:20 +02:00
|
|
|
|
2020-12-15 17:26:01 +01:00
|
|
|
if (typeI18nKey === 'password' || typeI18nKey === 'verificationCodeTotp') {
|
2019-07-12 21:00:20 +02:00
|
|
|
this.eventService.collect(EventType.Cipher_ClientToggledHiddenFieldVisible, cipher.id);
|
|
|
|
} else if (typeI18nKey === 'securityCode') {
|
|
|
|
this.eventService.collect(EventType.Cipher_ClientCopiedCardCode, cipher.id);
|
|
|
|
}
|
2018-04-05 21:35:56 +02:00
|
|
|
}
|
|
|
|
|
2020-12-15 17:26:01 +01:00
|
|
|
displayTotpCopyButton(cipher: CipherView) {
|
|
|
|
return (cipher?.login?.hasTotp ?? false) &&
|
|
|
|
(cipher.organizationUseTotp || this.userHasPremiumAccess);
|
|
|
|
}
|
|
|
|
|
2018-04-05 21:35:56 +02:00
|
|
|
view() {
|
|
|
|
this.onView.emit(this.cipher);
|
|
|
|
}
|
|
|
|
}
|