aboutsummaryrefslogtreecommitdiff
path: root/src/components/user_settings/mfa_totp.js
blob: 8408d8e924d4cecbaa35b5ec8ee0392c3bda824c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import Confirm from './confirm.vue'
import { mapState } from 'vuex'

export default {
  props: ['settings'],
  data: () => ({
    error: false,
    currentPassword: '',
    deactivate: false,
    inProgress: false // progress peform request to disable otp method
  }),
  components: {
    'confirm': Confirm
  },
  computed: {
    isActivated () {
      return this.settings.totp
    },
    ...mapState({
      backendInteractor: (state) => state.api.backendInteractor
    })
  },
  methods: {
    doActivate () {
      this.$emit('activate')
    },
    cancelDeactivate () { this.deactivate = false },
    doDeactivate () {
      this.error = null
      this.deactivate = true
    },
    confirmDeactivate () { // confirm deactivate TOTP method
      this.error = null
      this.inProgress = true
      this.backendInteractor.mfaDisableOTP({
        password: this.currentPassword
      })
        .then((res) => {
          this.inProgress = false
          if (res.error) {
            this.error = res.error
            return
          }
          this.deactivate = false
          this.$emit('deactivate')
        })
    }
  }
}