diff --git a/src/routes/auth/login/+page.server.ts b/src/routes/auth/login/+page.server.ts index 6f4555d..de2e5b7 100644 --- a/src/routes/auth/login/+page.server.ts +++ b/src/routes/auth/login/+page.server.ts @@ -1,5 +1,5 @@ import type { Actions } from './$types'; -import { fail } from '@sveltejs/kit'; +import { fail, redirect } from '@sveltejs/kit'; import { authService } from '$lib/api/services/authService.ts'; import { resolve } from '$app/paths'; import { HttpError } from '$lib/api/httpClient.ts'; @@ -25,6 +25,22 @@ export const actions:Actions = { }) } + const regexp = /^[a-zA-Z0-9_-]{5,16}$/ + + if (!regexp.test(username)){ + return fail(400,{ + username: username.toString(), + message: '用户名格式错误,请输入5-16位字符,只能包含字母、数字、下划线、减号' + }) + } + + if (password.length<8 || password.length>16){ + return fail(400,{ + message: '密码格式错误,请输入8-16位字符' + }) + } + + try{ const response = await authService.login({username,password}); diff --git a/src/routes/auth/login/+page.svelte b/src/routes/auth/login/+page.svelte index ad0f499..e4314c0 100644 --- a/src/routes/auth/login/+page.svelte +++ b/src/routes/auth/login/+page.svelte @@ -2,10 +2,10 @@ import { resolve } from '$app/paths'; import Icon from '$lib/components/icon/Icon.svelte'; import { toast } from '$lib/stores/toastStore.ts'; - import { enhance } from '$app/forms'; - import type { EnhanceResult, LoginFailure } from '$lib/types/api.ts'; - + import { enhance } from '$app/forms'; + import { goto } from '$app/navigation'; + let loading = false; @@ -24,13 +24,25 @@