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

GatewaySettings.vue « components « js - github.com/nextcloud/twofactor_gateway.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 868ee8fa8dd65e5478190bfe86a4eecc93503169 (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
140
141
142
143
144
145
<template>
	<div>
		<div v-if="!isAvailable">
			<L10n text="The {displayName} gateway is not configured."
				  :options="{displayName: displayName}"/>
		</div>
		<div v-else-if="loading">
			<span class="icon-loading-small"></span>
		</div>
		<div v-else>
			<p v-if="state === 0">
				<slot name="instructions"/>
				<L10n text="You are not using {displayName} for two-factor authentication at the moment."
					  :options="{displayName: displayName}"/>
				<button @click="enable">
					<L10n text="Enable"></L10n>
				</button>
			</p>
			<p v-if="state === 1">
				<slot name="instructions"/>
				<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 SMS. Please insert the code here:"
					  :options="{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 {displayName}."
					  :options="{displayName: displayName}"/>
				<button @click="disable">
					<l10n text="Disable"></l10n>
				</button>
			</p>
		</div>
	</div>
</template>

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

	export default {
		name: "GatewaySettings",
		props: [
			'gatewayName',
			'displayName',
		],
		data () {
			return {
				loading: true,
				state: 0,
				isAvailable: true,
				phoneNumber: '',
				confirmationCode: '',
				identifier: '',
				verificationError: false
			};
		},
		mounted: function () {
			getState(this.gatewayName)
				.then(res => {
					console.debug('loaded state for gateway ' + this.gatewayName, res);
					this.isAvailable = res.isAvailable;
					this.state = res.state;
					this.phoneNumber = res.phoneNumber;
				})
				.catch(console.error.bind(this))
				.then(() => this.loading = false);
		},
		methods: {
			enable: function () {
				this.state = 1;
				this.verificationError = false;
				this.loading = false;
			},
			verify: function () {
				this.loading = true;
				this.verificationError = false;
				startVerification(this.gatewayName, 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.gatewayName, 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(this.gatewayName)
					.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>