1 import { Subject } from 'rxjs'
2 import { Component, Input, OnInit } from '@angular/core'
3 import { AuthService, ConfirmService, Notifier, User } from '@app/core'
4 import { TwoFactorService } from './two-factor.service'
7 selector: 'my-account-two-factor-button',
8 templateUrl: './my-account-two-factor-button.component.html'
10 export class MyAccountTwoFactorButtonComponent implements OnInit {
11 @Input() user: User = null
12 @Input() userInformationLoaded: Subject<any>
14 twoFactorEnabled = false
17 private notifier: Notifier,
18 private twoFactorService: TwoFactorService,
19 private confirmService: ConfirmService,
20 private auth: AuthService
25 this.userInformationLoaded.subscribe(() => {
26 this.twoFactorEnabled = this.user.twoFactorEnabled
30 async disableTwoFactor () {
31 const message = $localize`Are you sure you want to disable two factor authentication of your account?`
33 const { confirmed, password } = await this.confirmService.confirmWithPassword(message, $localize`Disable two factor`)
34 if (confirmed === false) return
36 this.twoFactorService.disableTwoFactor({ userId: this.user.id, currentPassword: password })
39 this.twoFactorEnabled = false
41 this.auth.refreshUserInformation()
43 this.notifier.success($localize`Two factor authentication disabled`)
46 error: err => this.notifier.error(err.message)