-
Notifications
You must be signed in to change notification settings - Fork 13
/
reset-password.vue
121 lines (118 loc) · 3.6 KB
/
reset-password.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
<script setup lang="ts">
import { resetPassword } from '@/api/users'
import type { VForm } from '@/utils/types'
const { t } = useI18n()
const router = useRouter()
const userStore = useUserStore()
const showCurrent = ref(false)
const showNew = ref(false)
const showConfirm = ref(false)
const confirm = ref('')
const password = ref('')
const current = ref('')
const valid = ref(true)
const rules = [
(v: string) => !!v || t('pleaseEnter', [t('password')]),
(v: string) =>
v.length <= 20 ||
t('form.LTE', { input: t('lengthOf', [t('password')]), limit: 20 }),
(v: string) =>
v.length >= 5 ||
t('form.GTE', { input: t('lengthOf', [t('password')]), limit: 5 }),
]
const confirmedRules = computed(() => [
...rules,
password.value === confirm.value || t('notEqualErr'),
])
const form = ref<VForm | null>(null)
async function submit() {
if (form.value!.validate()) {
try {
await resetPassword(password.value, current.value)
Message.success(t('passwordUpdated'))
userStore.logOut()
router.push({ name: 'login' }).catch()
} catch (e) {
Message.error(e)
}
}
}
</script>
<template>
<v-container fluid fill-height>
<v-row>
<v-col cols="12">
<v-head-card
class="mx-auto"
style="max-width: 350px; position: relative; top: -100px"
>
<template #heading>
<v-icon>mdi-key-variant</v-icon>
{{ t('resetPassword') }}
</template>
<v-container>
<v-form ref="form" v-model="valid" lazy-validation>
<v-text-field
v-model="current"
:label="t('currentPassword')"
:counter="20"
:append-icon="showCurrent ? 'mdi-eye' : 'mdi-eye-off'"
:type="showCurrent ? 'text' : 'password'"
required
:rules="rules"
autocomplete="current-password"
@click:append="showCurrent = !showCurrent"
/>
<v-text-field
v-model="password"
:label="t('newPassword')"
:counter="20"
:append-icon="showNew ? 'mdi-eye' : 'mdi-eye-off'"
:type="showNew ? 'text' : 'password'"
:rules="rules"
autocomplete="off"
required
@click:append="showNew = !showNew"
/>
<v-text-field
v-model="confirm"
:label="t('confirmPassword')"
:counter="20"
:append-icon="showConfirm ? 'mdi-eye' : 'mdi-eye-off'"
:type="showConfirm ? 'text' : 'password'"
:rules="confirmedRules"
autocomplete="off"
required
@click:append="showConfirm = !showConfirm"
/>
</v-form>
</v-container>
<template #actions>
<v-spacer />
<v-btn color="primary" :disabled="!valid" @click="submit">
{{ t('submit') }}
</v-btn>
</template>
</v-head-card>
</v-col>
</v-row>
</v-container>
</template>
<i18n lang="json">
{
"en": {
"passwordUpdated": "Password Updated",
"currentPassword": "Current Password",
"confirmPassword": "Confirm Password",
"newPassword": "New Password",
"notEqualErr": "Must be the same as New Password"
},
"zh": {
"passwordUpdated": "密码已更新",
"currentPassword": "当前密码",
"confirmPassword": "确认密码",
"newPassword": "新密码",
"notEqualErr": "与新密码不匹配,请重新输入"
}
}
</i18n>