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: 1fd899dcd8e3e5d5df755d4189d573f747837ded (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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
<template>
	<div class="section">
		<h2 data-anchor-name="sms-second-factor-auth">
			<l10n text="Message gateway second-factor auth"></l10n>
		</h2>
		<div v-if="loading">
			<span class="icon-loading-small"></span>
		</div>
		<div v-else>
			<p>
				<l10n text="Here you can configure the message gateway to receive two-factor authentication codes via {gateway}."
					  v-bind:options="{gateway: gatewayName}"></l10n>
			</p>
			<p v-if="state === 0">
				<l10n text="You are not using gateway for two-factor authentication at the moment."></l10n>
				<button @click="enable">
					<l10n text="Enable"></l10n>
				</button>
			</p>
			<p v-if="state === 1">
				<strong v-if="verificationError === true">
					<l10n text="Could not verify your code. Please try again."></l10n>
				</strong>
				<l10n text="Enter your identification (e.g. phone number to start the verification):"></l10n>
				<input v-model="identifier">
				<button @click="verify">
					<l10n text="Verify"></l10n>
				</button>
			</p>
			<p v-if="state === 2">
				<l10n text="A confirmation code has been sent to {phone} via {gateway}. Please insert the code here:"
					  v-bind:options="{gateway: gatewayName, phone: phoneNumber}"></l10n>
				<input v-model="confirmationCode">
				<button @click="confirm">
					<l10n text="Confirm"></l10n>
				</button>
			</p>
			<p v-if="state === 3">
				<l10n text="Your account was successfully configured to receive messages via {gateway}."
					  v-bind:options="{gateway: gatewayName}"></l10n>
				<button @click="disable">
					<l10n text="Disable"></l10n>
				</button>
			</p>
		</div>
	</div>
</template>

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

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

				tryVerification(this.confirmationCode)
					.then(res => {
						this.state = 3;
						this.loading = false;
					})
					.catch(res => {
						this.state = 1;
						this.verificationError = true;
						this.loading = false;
					});
			},

			disable: function () {
				this.loading = true;

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

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