Skip to content

Commit bea7872

Browse files
committed
improve login page
1 parent c5d0b6a commit bea7872

File tree

1 file changed

+39
-9
lines changed

1 file changed

+39
-9
lines changed

assets/views/LoginView.vue

Lines changed: 39 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,25 @@
2626
/>
2727
<v-text-field
2828
v-model="form.user.password"
29-
class="mb-4"
29+
:rules="form.passwordRules"
30+
class="mb-3"
3031
label="Password"
31-
type="password"
32+
:type="showPasswordType"
3233
required
34+
append-inner-icon="mdi-eye"
35+
@click:append-inner="toggleShowPassword"
36+
/>
37+
<v-alert
38+
v-if="form.error"
39+
class="mb-6"
40+
text="Wrong email or password"
41+
type="error"
3342
/>
3443
<v-btn
35-
elevation="1"
3644
:loading="form.loading"
45+
color="primary"
46+
class="mt-1"
47+
prepend-icon="mdi-check"
3748
@click="submit"
3849
>
3950
Submit
@@ -53,36 +64,55 @@
5364
export default {
5465
data: () => ({
5566
form: {
67+
error: false,
5668
valid: false,
5769
loading: false,
70+
showPassword: false,
5871
user: {
5972
username: '',
6073
password: '',
6174
},
6275
emailRules: [
6376
(value) => {
6477
if (value) return true;
65-
6678
return 'E-mail is required.';
6779
},
6880
(value) => {
6981
if (/.+@.+\..+/.test(value)) return true;
70-
7182
return 'E-mail must be valid.';
7283
},
7384
],
85+
passwordRules: [
86+
(value) => {
87+
if (value.length > 3) return true;
88+
return 'Password must be longer than 3 characters';
89+
},
90+
],
7491
},
7592
}),
93+
computed: {
94+
showPasswordType() {
95+
return this.form.showPassword ? 'text' : 'password';
96+
},
97+
},
7698
methods: {
99+
toggleShowPassword() {
100+
this.form.showPassword = !this.form.showPassword;
101+
},
77102
async submit() {
78103
if (this.form.valid === false) {
79104
return;
80105
}
81106
this.form.loading = true;
82-
const { data } = await this.axios.post('/api/login', this.form.user);
83-
localStorage.setItem('token', data.token);
84-
this.$router.push('/');
85-
this.form.loading = false;
107+
try {
108+
const { data } = await this.axios.post('/api/login', this.form.user);
109+
localStorage.setItem('token', data.token);
110+
this.$router.push('/');
111+
} catch {
112+
this.form.error = true;
113+
} finally {
114+
this.form.loading = false;
115+
}
86116
},
87117
},
88118
};

0 commit comments

Comments
 (0)