Skip to content

Commit 96ca113

Browse files
committed
fix(auth): auth form
1 parent fea080d commit 96ca113

File tree

1 file changed

+141
-45
lines changed

1 file changed

+141
-45
lines changed

web/src/views/Auth.vue

Lines changed: 141 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@
7676
<v-card class="px-5 py-5" style="border-radius: 15px;">
7777
<v-card-text>
7878
<v-form
79+
@submit.prevent
7980
ref="signInForm"
8081
lazy-validation
8182
v-model="signInFormValid"
@@ -99,7 +100,7 @@
99100
</h2>
100101

101102
<h2 v-else class="text-center pt-4 pb-6">
102-
Log in to your account
103+
Enter to your account
103104
</h2>
104105

105106
<v-alert
@@ -139,12 +140,20 @@
139140
{{ $t('Use recovery code') }}
140141
</a>
141142

142-
<a
143+
<v-btn
144+
:width="200"
145+
small
146+
:disabled="verificationEmailSending"
147+
color="primary"
143148
v-if="verificationMethod === 'email'"
144149
@click="resendEmailVerification()"
145150
>
146-
{{ $t('Resend code to email') }}
147-
</a>
151+
{{
152+
verificationEmailSending
153+
? $t('Email sending...')
154+
: $t('Resend code to email')
155+
}}
156+
</v-btn>
148157
</div>
149158
</div>
150159

@@ -180,45 +189,81 @@
180189
</div>
181190

182191
<div v-else>
183-
<v-text-field
184-
v-model="username"
185-
v-bind:label='$t("username")'
186-
:rules="[v => !!v || $t('username_required')]"
187-
required
188-
:disabled="signInProcess"
189-
v-if="loginWithPassword"
190-
data-testid="auth-username"
191-
></v-text-field>
192192

193-
<v-text-field
194-
v-model="password"
195-
:label="$t('password')"
196-
:rules="[v => !!v || $t('password_required')]"
197-
type="password"
198-
required
199-
:disabled="signInProcess"
200-
@keyup.enter.native="signIn"
201-
style="margin-bottom: 20px;"
202-
v-if="loginWithPassword"
203-
data-testid="auth-password"
204-
></v-text-field>
193+
<div v-if="loginWithPassword">
194+
<v-text-field
195+
v-model="username"
196+
v-bind:label='$t("username")'
197+
:rules="[v => !!v || $t('username_required')]"
198+
required
199+
:disabled="signInProcess"
200+
data-testid="auth-username"
201+
></v-text-field>
202+
203+
<v-text-field
204+
v-model="password"
205+
:label="$t('password')"
206+
:rules="[v => !!v || $t('password_required')]"
207+
type="password"
208+
required
209+
:disabled="signInProcess"
210+
@keyup.enter.native="signIn"
211+
style="margin-bottom: 20px;"
212+
data-testid="auth-password"
213+
></v-text-field>
205214

206-
<v-btn
207-
large
208-
color="primary"
209-
@click="signIn"
210-
:disabled="signInProcess"
211-
block
212-
v-if="loginWithPassword"
213-
rounded
214-
data-testid="auth-signin"
215-
>
216-
{{ $t('signIn') }}
217-
</v-btn>
215+
<v-btn
216+
large
217+
color="primary"
218+
@click="signIn"
219+
:disabled="signInProcess"
220+
block
221+
rounded
222+
data-testid="auth-signin"
223+
>
224+
{{ $t('signIn') }}
225+
</v-btn>
226+
227+
</div>
228+
229+
<div v-else>
230+
<v-text-field
231+
v-model="email"
232+
:label="$t('Email')"
233+
:rules="[v => !!v || $t('email_required')]"
234+
type="email"
235+
required
236+
:disabled="signInProcess"
237+
@keyup.enter.native="signInWithEmail"
238+
style="margin-bottom: 20px;"
239+
data-testid="auth-password"
240+
outlined
241+
class="mb-0"
242+
></v-text-field>
243+
244+
<v-btn
245+
large
246+
color="primary"
247+
@click="signInWithEmail"
248+
:disabled="signInProcess"
249+
block
250+
rounded
251+
data-testid="auth-signin-with-eamil"
252+
>
253+
<v-icon
254+
left
255+
dark
256+
>
257+
mdi-email
258+
</v-icon>
259+
260+
{{ $t('Continue with Email') }}
261+
</v-btn>
262+
</div>
218263

219264
<div
220265
class="auth__divider"
221-
v-if="loginWithPassword && oidcProviders.length > 0"
266+
v-if="oidcProviders.length > 0"
222267
>or</div>
223268

224269
<v-btn
@@ -243,7 +288,7 @@
243288
{{ provider.name }}
244289
</v-btn>
245290

246-
<div class="text-center mt-6" v-if="loginWithPassword">
291+
<div class="text-center mt-6" v-if="loginWithPassword && false">
247292
<a @click="loginHelpDialog = true">{{ $t('dontHaveAccountOrCantSignIn') }}</a>
248293
</div>
249294

@@ -300,6 +345,8 @@ export default {
300345
password: null,
301346
username: null,
302347
348+
email: null,
349+
303350
loginHelpDialog: null,
304351
305352
oidcProviders: [],
@@ -311,6 +358,8 @@ export default {
311358
verificationCode: null,
312359
verificationMethod: null,
313360
recoveryCode: null,
361+
verificationEmailSending: false,
362+
314363
};
315364
},
316365
@@ -336,7 +385,29 @@ export default {
336385
337386
methods: {
338387
async resendEmailVerification() {
339-
// TODO: resend email verification code
388+
if (this.verificationEmailSending) {
389+
return;
390+
}
391+
392+
this.verificationEmailSending = true;
393+
try {
394+
(await axios({
395+
method: 'post',
396+
url: '/api/auth/login/email/resend',
397+
responseType: 'json',
398+
}));
399+
EventBus.$emit('i-snackbar', {
400+
color: 'success',
401+
text: 'Verification email sent successfully.',
402+
});
403+
} catch (e) {
404+
EventBus.$emit('i-snackbar', {
405+
color: 'error',
406+
text: getErrorMessage(e),
407+
});
408+
} finally {
409+
this.verificationEmailSending = false;
410+
}
340411
},
341412
342413
async loadLoginData() {
@@ -439,6 +510,7 @@ export default {
439510
}
440511
441512
this.signInProcess = true;
513+
442514
try {
443515
await axios({
444516
method: 'post',
@@ -451,11 +523,35 @@ export default {
451523
document.location = document.baseURI + window.location.search;
452524
} catch (err) {
453525
this.signInError = getErrorMessage(err);
454-
// if (err.response.status === 401) {
455-
// this.signInError = this.$t('Incorrect verification code.');
456-
// } else {
457-
// this.signInError = getErrorMessage(err);
458-
// }
526+
} finally {
527+
this.signInProcess = false;
528+
}
529+
},
530+
531+
async signInWithEmail() {
532+
this.signInError = null;
533+
534+
if (!this.$refs.signInForm.validate()) {
535+
return;
536+
}
537+
538+
this.signInProcess = true;
539+
try {
540+
await axios({
541+
method: 'post',
542+
url: '/api/auth/login/email',
543+
responseType: 'json',
544+
data: {
545+
email: this.email,
546+
},
547+
});
548+
document.location = document.baseURI + window.location.search;
549+
} catch (err) {
550+
if (err.response.status === 401) {
551+
this.signInError = this.$t('incorrectEmail');
552+
} else {
553+
this.signInError = getErrorMessage(err);
554+
}
459555
} finally {
460556
this.signInProcess = false;
461557
}

0 commit comments

Comments
 (0)