修改认证中心对接方式
This commit is contained in:
@@ -27,10 +27,6 @@ export function AuthLoginPanel({
|
||||
const feedbackRef = useRef<HTMLDivElement | null>(null);
|
||||
const hasMissingConfig = !configured && Boolean(missing?.length);
|
||||
|
||||
useEffect(() => {
|
||||
refreshCaptcha();
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
return runScopedMotion(screenRef, (scope) => revealChildren(scope));
|
||||
}, []);
|
||||
@@ -55,14 +51,19 @@ export function AuthLoginPanel({
|
||||
setSubmitting(true);
|
||||
setError(null);
|
||||
try {
|
||||
const payload: Record<string, string> = { username, password, next };
|
||||
if (code.trim() && randomStr) {
|
||||
payload.code = code.trim();
|
||||
payload.randomStr = randomStr;
|
||||
}
|
||||
const response = await fetch("/api/auth/password", {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ username, password, code, randomStr, next })
|
||||
body: JSON.stringify(payload)
|
||||
});
|
||||
const payload = await response.json();
|
||||
if (!response.ok) throw new Error(payload.error || "登录失败");
|
||||
window.location.assign(payload.redirectTo || next || "/create");
|
||||
const result = await response.json().catch(() => ({})) as { error?: string; redirectTo?: string };
|
||||
if (!response.ok) throw new Error(result.error || "登录失败");
|
||||
window.location.assign(result.redirectTo || next || "/create");
|
||||
} catch (err) {
|
||||
setError(err instanceof Error ? err.message : String(err));
|
||||
refreshCaptcha();
|
||||
@@ -123,15 +124,22 @@ export function AuthLoginPanel({
|
||||
value={code}
|
||||
onChange={(event) => setCode(event.target.value)}
|
||||
disabled={!configured || submitting}
|
||||
placeholder="请输入验证码"
|
||||
placeholder="需要时填写"
|
||||
/>
|
||||
<button className="auth-captcha-button" type="button" onClick={refreshCaptcha} disabled={!configured || submitting} aria-label="刷新验证码" title="刷新验证码">
|
||||
<button
|
||||
className="auth-captcha-button"
|
||||
type="button"
|
||||
onClick={refreshCaptcha}
|
||||
disabled={!configured || submitting}
|
||||
aria-label="刷新验证码"
|
||||
title="刷新验证码"
|
||||
>
|
||||
{captchaSrc ? <img src={captchaSrc} alt="验证码" /> : <RefreshCw size={18} />}
|
||||
</button>
|
||||
</div>
|
||||
</label>
|
||||
|
||||
<button className="button primary auth-submit" type="submit" disabled={!configured || submitting || !username.trim() || !password || !code.trim()} data-animate>
|
||||
<button className="button primary auth-submit" type="submit" disabled={!configured || submitting || !username.trim() || !password} data-animate>
|
||||
{submitting ? <Loader2 className="spin" size={18} /> : <LogIn size={18} />}
|
||||
登录
|
||||
</button>
|
||||
|
||||
Reference in New Issue
Block a user