mirror of
https://github.com/snowykami/neo-blog.git
synced 2025-09-26 11:06:23 +00:00
Merge branch 'main' of https://github.com/snowykami/neo-blog
This commit is contained in:
@ -49,7 +49,7 @@ func (s *UserService) UserLogin(req *dto.UserLoginReq) (*dto.UserLoginResp, erro
|
|||||||
}
|
}
|
||||||
return resp, nil
|
return resp, nil
|
||||||
} else {
|
} else {
|
||||||
return nil, errs.ErrInternalServer
|
return nil, errs.New(http.StatusUnauthorized, "Invalid username or password", nil)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20,6 +20,7 @@ import { useRouter, useSearchParams } from "next/navigation"
|
|||||||
import { useTranslations } from "next-intl"
|
import { useTranslations } from "next-intl"
|
||||||
import Captcha from "../common/captcha"
|
import Captcha from "../common/captcha"
|
||||||
import { CaptchaProvider } from "@/models/captcha"
|
import { CaptchaProvider } from "@/models/captcha"
|
||||||
|
import { toast } from "sonner"
|
||||||
|
|
||||||
export function LoginForm({
|
export function LoginForm({
|
||||||
className,
|
className,
|
||||||
@ -47,7 +48,7 @@ export function LoginForm({
|
|||||||
setOidcConfigs(res.data || []) // 确保是数组
|
setOidcConfigs(res.data || []) // 确保是数组
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
console.error("Error fetching OIDC configs:", error)
|
toast.error(t("fetch_oidc_configs_failed") + (error?.message ? `: ${error.message}` : ""))
|
||||||
setOidcConfigs([]) // 错误时设置为空数组
|
setOidcConfigs([]) // 错误时设置为空数组
|
||||||
})
|
})
|
||||||
}, [])
|
}, [])
|
||||||
@ -58,7 +59,8 @@ export function LoginForm({
|
|||||||
setCaptchaProps(res.data)
|
setCaptchaProps(res.data)
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
console.error("Error fetching captcha config:", error)
|
toast.error(t("fetch_captcha_config_failed") + (error?.message ? `: ${error.message}` : ""))
|
||||||
|
setCaptchaProps(null)
|
||||||
})
|
})
|
||||||
}, [refreshCaptchaKey])
|
}, [refreshCaptchaKey])
|
||||||
|
|
||||||
@ -67,11 +69,14 @@ export function LoginForm({
|
|||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
userLogin({ username, password, captcha: captchaToken || "" })
|
userLogin({ username, password, captcha: captchaToken || "" })
|
||||||
.then(res => {
|
.then(res => {
|
||||||
console.log("Login successful:", res)
|
toast.success(t("login_success") + ` ${res.data.user.nickname || res.data.user.username}`);
|
||||||
router.push(redirectBack)
|
router.push(redirectBack)
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
console.error("Login failed:", error)
|
console.log(error)
|
||||||
|
toast.error(t("login_failed") + (error?.response?.data?.message ? `: ${error.response.data.message}` : ""))
|
||||||
|
setRefreshCaptchaKey(k => k + 1)
|
||||||
|
setCaptchaToken(null)
|
||||||
})
|
})
|
||||||
.finally(() => {
|
.finally(() => {
|
||||||
setIsLogging(false)
|
setIsLogging(false)
|
||||||
|
Reference in New Issue
Block a user