-
Notifications
You must be signed in to change notification settings - Fork 385
/
ActivateAccountRequest.vue
206 lines (190 loc) · 7.04 KB
/
ActivateAccountRequest.vue
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
// Copyright (C) 2024 Storj Labs, Inc.
// See LICENSE for copying information.
<template>
<v-container class="fill-height">
<v-row justify="center">
<v-col cols="12" sm="9" md="7" lg="5" xl="4" xxl="3">
<v-card title="Verify Account" class="pa-2 pa-sm-7">
<v-card-item>
<v-alert
v-if="isActivationExpired"
variant="tonal"
color="error"
rounded="lg"
density="comfortable"
border
closable
>
<template #text>
The verification link you clicked on has expired. Request a new link.
</template>
</v-alert>
</v-card-item>
<v-card-text>
<p>If you haven’t verified your account yet, input your email to receive a new verification link. Make sure you’re signing on the right satellite.</p>
<v-form v-model="formValid" class="pt-4" @submit.prevent>
<v-select
v-model="satellite"
label="Satellite"
:items="satellites"
item-title="satellite"
:hint="satellite.hint"
persistent-hint
return-object
chips
class="mt-3 mb-2"
/>
<v-text-field
v-model="email"
label="Email address"
name="email"
type="email"
:rules="emailRules"
autofocus
clearable
required
class="my-2"
/>
<VueHcaptcha
v-if="captchaConfig.hcaptcha.enabled"
ref="captcha"
:sitekey="captchaConfig.hcaptcha.siteKey"
:re-captcha-compat="false"
size="invisible"
@verify="onCaptchaVerified"
@error="onCaptchaError"
/>
<v-btn
color="primary"
size="large"
block
:loading="isLoading"
:disabled="!formValid"
@click="onActivateClick"
>
Get Activation Link
</v-btn>
</v-form>
</v-card-text>
</v-card>
<p class="pt-6 text-center text-body-2">Go back to <router-link class="link" to="/login">login</router-link></p>
</v-col>
</v-row>
</v-container>
</template>
<script setup lang="ts">
import { computed, onMounted, ref } from 'vue';
import { useRoute, useRouter } from 'vue-router';
import {
VAlert,
VBtn,
VCard, VCardItem,
VCardText,
VCol,
VContainer,
VForm,
VRow,
VSelect,
VTextField,
} from 'vuetify/components';
import VueHcaptcha from '@hcaptcha/vue3-hcaptcha';
import { useConfigStore } from '@/store/modules/configStore';
import { EmailRule, RequiredRule, ValidationRule } from '@poc/types/common';
import { useLoading } from '@/composables/useLoading';
import { useNotify } from '@/utils/hooks';
import { AuthHttpApi } from '@/api/auth';
import { MultiCaptchaConfig } from '@/types/config.gen';
const auth: AuthHttpApi = new AuthHttpApi();
const configStore = useConfigStore();
const route = useRoute();
const router = useRouter();
const notify = useNotify();
const { isLoading, withLoading } = useLoading();
const email = ref<string>('');
const isActivationExpired = ref<boolean>(false);
const formValid = ref<boolean>(false);
const captchaResponseToken = ref<string>('');
const captcha = ref<VueHcaptcha>();
const satellitesHints = [
{ satellite: 'US1', hint: 'Recommended for North and South America' },
{ satellite: 'EU1', hint: 'Recommended for Europe and Africa' },
{ satellite: 'AP1', hint: 'Recommended for Asia and Australia' },
];
const emailRules: ValidationRule<string>[] = [
RequiredRule,
EmailRule,
];
/**
* This component's captcha configuration.
*/
const captchaConfig = computed((): MultiCaptchaConfig => {
return configStore.state.config.captcha.login;
});
/**
* Name of the current satellite.
*/
const satellite = computed({
get: () => {
const satName = configStore.state.config.satelliteName;
const item = satellitesHints.find(item => item.satellite === satName);
return item ?? { satellite: satName, hint: '' };
},
set: value => {
const sats = configStore.state.config.partneredSatellites ?? [];
const satellite = sats.find(sat => sat.name === value.satellite);
if (satellite) {
window.location.href = satellite.address + configStore.optionalV2Path + '/forgot-password';
}
},
});
/**
* Information about partnered satellites.
*/
const satellites = computed(() => {
const satellites = configStore.state.config.partneredSatellites ?? [];
return satellites.map(satellite => {
const item = satellitesHints.find(item => item.satellite === satellite.name);
return item ?? { satellite: satellite.name, hint: '' };
});
});
/**
* Handles captcha verification response.
*/
function onCaptchaVerified(response: string): void {
captchaResponseToken.value = response;
onActivateClick();
}
/**
* Handles captcha error.
*/
function onCaptchaError(): void {
captchaResponseToken.value = '';
notify.error('The captcha encountered an error. Please try again.', null);
}
/**
* onActivateClick validates input fields and requests resending of activation email.
*/
async function onActivateClick(): Promise<void> {
if (!formValid.value) {
return;
}
if (captcha.value && !captchaResponseToken.value) {
captcha.value.execute();
return;
}
await withLoading(async () => {
try {
await auth.resendEmail(email.value);
notify.success('Activation link sent');
router.push(`/signup-confirmation?email=${encodeURIComponent(email.value)}`);
} catch (error) {
notify.notifyError(error);
}
});
captcha.value?.reset();
captchaResponseToken.value = '';
}
onMounted((): void => {
isActivationExpired.value = route.query.expired === 'true';
});
</script>