Welcome to mirror list, hosted at ThFree Co, Russian Federation.

settings.vue « view « js - github.com/nextcloud/twofactor_gateway.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: b58f7eee9cbc44c93b97251ec44a9d347c256338 (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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
<template>
    <div class="section">
        <h2 data-anchor-name="sms-second-factor-auth"><l10n text="SMS second-factor auth"></l10n></h2>
        <div v-if="loading">
              <span class="icon-loading-small"></span>
        </div>
        <div v-else>
          <p v-if="state === 0">
              <l10n text="You are not using SMS-based two-factor authentication at the moment"></l10n>
              <button @click="enable"><l10n text="Enable"></l10n></button>
          </p>
          <p v-if="state === 1">
              <l10n text="A confirmation code has been sent to {phone}. Please check your phone and insert the code here:"
                    v-bind:options="{phone: phoneNumber}"></l10n>
              <input v-model="confirmationCode">
              <button @click="confirm"><l10n text="Confirm"></l10n></button>
          </p>
          <p v-if="state === 2">
              <l10n text="SMS-based two-factor authentication is enabled for your account."></l10n>
          </p>
        </div>
    </div>
</template>

<script>
import l10n from "view/l10n.vue";
import {
  getState,
  startVerification,
  tryVerification
} from "service/registration";

export default {
  data() {
    return {
      loading: true,
      state: 0,
      phoneNumber: "12344556",
      confirmationCode: ""
    };
  },
  mounted: function() {
    getState()
      .then(res => {
        this.state = res.state;
        this.phoneNumber = res.phoneNumber;
        this.loading = false;
      })
      .catch(console.error.bind(this));
  },
  methods: {
    enable: function() {
      this.loading = true;
      startVerification()
        .then(res => {
          this.state = 1;
          this.phoneNumber = res.phoneNumber;
          this.loading = false;
        })
        .catch(console.error.bind(this));
    },
    confirm: function() {
      this.loading = true;

      tryVerification(this.confirmationCode)
        .then(res => {
          this.state = 2;
          this.loading = false;
        })
        .catch(console.error.bind(this));
    }
  },
  components: {
    l10n
  }
};
</script>

<style>
.icon-loading-small {
  padding-left: 15px;
}
</style>