mirror of https://github.com/nocodb/nocodb
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
163 lines
4.8 KiB
163 lines
4.8 KiB
2 years ago
|
<script lang="ts" setup>
|
||
2 years ago
|
import type { RuleObject } from 'ant-design-vue/es/form'
|
||
2 years ago
|
import { iconMap, message, navigateTo, reactive, ref, useApi, useGlobal, useI18n, useRouter } from '#imports'
|
||
2 years ago
|
|
||
|
const router = useRouter()
|
||
|
|
||
|
const { api, error, isLoading } = useApi({ useGlobalInstance: true })
|
||
|
|
||
|
const { t } = useI18n()
|
||
|
|
||
|
const { signOut } = useGlobal()
|
||
|
|
||
|
const formValidator = ref()
|
||
|
|
||
|
const form = reactive({
|
||
|
currentPassword: '',
|
||
|
password: '',
|
||
|
passwordRepeat: '',
|
||
|
})
|
||
|
|
||
2 years ago
|
const formRules: Record<string, RuleObject[]> = {
|
||
2 years ago
|
currentPassword: [
|
||
|
// Current password is required
|
||
|
{ required: true, message: t('msg.error.signUpRules.passwdRequired') },
|
||
|
],
|
||
|
password: [
|
||
|
// Password is required
|
||
|
{ required: true, message: t('msg.error.signUpRules.passwdRequired') },
|
||
|
{ min: 8, message: t('msg.error.signUpRules.passwdLength') },
|
||
|
],
|
||
|
passwordRepeat: [
|
||
|
// PasswordRepeat is required
|
||
|
{ required: true, message: t('msg.error.signUpRules.passwdRequired') },
|
||
|
// Passwords match
|
||
|
{
|
||
|
validator: (_: unknown, _v: string) => {
|
||
|
return new Promise((resolve, reject) => {
|
||
2 years ago
|
if (form.password === form.passwordRepeat) return resolve()
|
||
2 years ago
|
reject(new Error(t('msg.error.signUpRules.passwdMismatch')))
|
||
|
})
|
||
|
},
|
||
|
message: t('msg.error.signUpRules.passwdMismatch'),
|
||
|
},
|
||
|
],
|
||
|
}
|
||
|
|
||
|
const passwordChange = async () => {
|
||
|
const valid = formValidator.value.validate()
|
||
|
if (!valid) return
|
||
|
|
||
|
error.value = null
|
||
|
|
||
|
await api.auth.passwordChange({
|
||
|
currentPassword: form.currentPassword,
|
||
|
newPassword: form.password,
|
||
|
})
|
||
|
|
||
|
message.success(t('msg.success.passwordChanged'))
|
||
|
|
||
2 years ago
|
await signOut()
|
||
2 years ago
|
|
||
2 years ago
|
await navigateTo('/signin')
|
||
2 years ago
|
}
|
||
|
|
||
|
const resetError = () => {
|
||
|
if (error.value) error.value = null
|
||
|
}
|
||
|
</script>
|
||
|
|
||
|
<template>
|
||
2 years ago
|
<div
|
||
|
class="relative flex flex-col justify-center gap-2 w-full p-8 md:(bg-white rounded-lg border-1 border-gray-200 shadow)"
|
||
|
data-testid="user-change-password"
|
||
|
>
|
||
2 years ago
|
<LazyGeneralNocoIcon class="color-transition hover:(ring ring-accent)" :animate="isLoading" />
|
||
|
|
||
|
<div
|
||
2 years ago
|
class="color-transition transform group absolute top-5 left-5 text-4xl rounded-full cursor-pointer"
|
||
2 years ago
|
@click="() => router.back()"
|
||
|
>
|
||
2 years ago
|
<component :is="iconMap.chevronLeft" class="text-black group-hover:(text-accent scale-110)" />
|
||
2 years ago
|
</div>
|
||
|
|
||
|
<h1 class="prose-2xl font-bold self-center my-4">{{ $t('activity.changePwd') }}</h1>
|
||
|
|
||
|
<a-form
|
||
|
ref="formValidator"
|
||
2 years ago
|
data-testid="nc-user-settings-form"
|
||
2 years ago
|
layout="vertical"
|
||
|
class="change-password lg:max-w-3/4 w-full !mx-auto"
|
||
|
no-style
|
||
|
:model="form"
|
||
|
@finish="passwordChange"
|
||
|
>
|
||
|
<Transition name="layout">
|
||
2 years ago
|
<div v-if="error" class="mx-auto mb-4 bg-red-500 text-white rounded-lg w-3/4 p-1">
|
||
2 years ago
|
<div data-testid="nc-user-settings-form__error" class="flex items-center gap-2 justify-center">
|
||
2 years ago
|
<MaterialSymbolsWarning />
|
||
|
{{ error }}
|
||
|
</div>
|
||
|
</div>
|
||
|
</Transition>
|
||
|
|
||
|
<a-form-item :label="$t('placeholder.password.current')" name="currentPassword" :rules="formRules.currentPassword">
|
||
|
<a-input-password
|
||
|
v-model:value="form.currentPassword"
|
||
2 years ago
|
data-testid="nc-user-settings-form__current-password"
|
||
2 years ago
|
size="large"
|
||
|
class="password"
|
||
|
:placeholder="$t('placeholder.password.current')"
|
||
|
@focus="resetError"
|
||
|
/>
|
||
|
</a-form-item>
|
||
|
|
||
|
<a-form-item :label="$t('placeholder.password.new')" name="password" :rules="formRules.password">
|
||
|
<a-input-password
|
||
|
v-model:value="form.password"
|
||
2 years ago
|
data-testid="nc-user-settings-form__new-password"
|
||
2 years ago
|
size="large"
|
||
|
class="password"
|
||
|
:placeholder="$t('placeholder.password.new')"
|
||
|
@focus="resetError"
|
||
|
/>
|
||
|
</a-form-item>
|
||
|
|
||
|
<a-form-item :label="$t('placeholder.password.confirm')" name="passwordRepeat" :rules="formRules.passwordRepeat">
|
||
|
<a-input-password
|
||
|
v-model:value="form.passwordRepeat"
|
||
2 years ago
|
data-testid="nc-user-settings-form__new-password-repeat"
|
||
2 years ago
|
size="large"
|
||
|
class="password"
|
||
|
:placeholder="$t('placeholder.password.confirm')"
|
||
|
@focus="resetError"
|
||
|
/>
|
||
|
</a-form-item>
|
||
|
|
||
|
<div class="text-center">
|
||
2 years ago
|
<button data-testid="nc-user-settings-form__submit" class="scaling-btn bg-opacity-100" type="submit">
|
||
2 years ago
|
<span class="flex items-center gap-2">
|
||
2 years ago
|
<component :is="iconMap.passwordChange" />
|
||
2 years ago
|
{{ $t('activity.changePwd') }}
|
||
|
</span>
|
||
|
</button>
|
||
|
</div>
|
||
|
</a-form>
|
||
|
</div>
|
||
|
</template>
|
||
|
|
||
|
<style lang="scss">
|
||
|
.change-password {
|
||
2 years ago
|
.ant-input-affix-wrapper,
|
||
|
.ant-input {
|
||
|
@apply !appearance-none my-1 border-1 border-solid border-primary border-opacity-50 rounded;
|
||
|
}
|
||
|
|
||
|
.password {
|
||
|
input {
|
||
|
@apply !border-none !m-0;
|
||
2 years ago
|
}
|
||
|
}
|
||
|
}
|
||
|
</style>
|