mirror of
https://github.com/rustmailer/bichon.git
synced 2026-08-03 07:48:34 +02:00
feat: increase password max to 256, fix i18n, and force re-login #83
- Raise password maximum length from 32 to 256 characters - fix profileSchema to accept `t` for proper internationalization - Invalidate user's WebUI token on password change, requiring re-login
This commit is contained in:
@@ -47,40 +47,40 @@ import AvatarUpload from './avatar-upload'
|
||||
import useMinimalAccountList from '@/hooks/use-minimal-account-list'
|
||||
import { PermissionsDialog } from './permissions-dialog'
|
||||
|
||||
const profileSchema = z.object({
|
||||
const profileSchema = (t: (key: string) => string) => z.object({
|
||||
username: z
|
||||
.string({
|
||||
required_error: 'settings.profile.validation.username.required',
|
||||
required_error: t('settings.profile.validation.username.required'),
|
||||
})
|
||||
.min(5, {
|
||||
message: 'settings.profile.validation.username.min',
|
||||
message: t('settings.profile.validation.username.min'),
|
||||
})
|
||||
.max(32, {
|
||||
message: 'settings.profile.validation.username.max',
|
||||
message: t('settings.profile.validation.username.max'),
|
||||
}),
|
||||
|
||||
email: z
|
||||
.string({
|
||||
required_error: 'settings.profile.validation.email.required',
|
||||
required_error: t('settings.profile.validation.email.required'),
|
||||
})
|
||||
.email({
|
||||
message: 'settings.profile.validation.email.invalid',
|
||||
message: t('settings.profile.validation.email.invalid'),
|
||||
}),
|
||||
|
||||
password: z
|
||||
.string()
|
||||
.min(8, {
|
||||
message: 'settings.profile.validation.password.min',
|
||||
message: t('settings.profile.validation.password.min'),
|
||||
})
|
||||
.max(32, {
|
||||
message: 'settings.profile.validation.password.max',
|
||||
.max(256, {
|
||||
message: t('settings.profile.validation.password.max'),
|
||||
})
|
||||
.or(z.literal(''))
|
||||
.optional()
|
||||
.transform((v) => (v ? v : undefined)),
|
||||
})
|
||||
|
||||
export type ProfileFormValues = z.infer<typeof profileSchema>
|
||||
export type ProfileFormValues = z.infer<ReturnType<typeof profileSchema>>
|
||||
|
||||
function fileToBase64(file: File): Promise<string> {
|
||||
return new Promise((resolve, reject) => {
|
||||
@@ -110,7 +110,7 @@ export function UserProfileForm({ user }: UserProfileFormProps) {
|
||||
useState<number | undefined>(undefined)
|
||||
|
||||
const form = useForm<ProfileFormValues>({
|
||||
resolver: zodResolver(profileSchema),
|
||||
resolver: zodResolver(profileSchema(t)),
|
||||
mode: 'onChange',
|
||||
defaultValues: {
|
||||
username: user.username,
|
||||
|
||||
@@ -111,14 +111,14 @@ const createUserSchema = (t: any) => z.object({
|
||||
password: z.string()
|
||||
.min(1, t('users.actions.schema.password_required'))
|
||||
.min(8, t('users.actions.schema.password_min'))
|
||||
.max(32, t('users.actions.schema.password_max')),
|
||||
.max(256, t('users.actions.schema.password_max')),
|
||||
});
|
||||
|
||||
const updateUserSchema = (t: any) => z.object({
|
||||
...baseUserSchema(t),
|
||||
password: z.string()
|
||||
.min(8, t('users.actions.schema.password_min'))
|
||||
.max(32, t('users.actions.schema.password_max'))
|
||||
.max(256, t('users.actions.schema.password_max'))
|
||||
.or(z.literal(''))
|
||||
.optional()
|
||||
.transform(v => v || undefined),
|
||||
|
||||
Reference in New Issue
Block a user