feat(auth): 支持开放注册

- 新增注册接口与注册页面,开放注册时可创建普通用户并自动登录。
- 公共配置增加开放注册状态,登录页可跳转注册入口。
- 补充注册流程测试,验证关闭注册、账号创建与登录行为。
This commit is contained in:
LanQin
2026-06-15 23:57:56 +08:00
parent f8ff2a814b
commit f7e6165b72
7 changed files with 208 additions and 6 deletions
+9 -4
View File
@@ -1,5 +1,5 @@
import * as React from "react"
import { Navigate } from "react-router-dom"
import { Link, Navigate } from "react-router-dom"
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query"
import { api } from "@/lib/api"
import { useMe } from "@/hooks/use-me"
@@ -42,11 +42,11 @@ export function LoginPage() {
<>
<div className="space-y-2">
<Label htmlFor="email"></Label>
<Input id="email" name="email" type="email" defaultValue="admin@lanqin.local" required className="h-11 text-base" />
<Input id="email" name="email" type="email" autoComplete="username" required className="h-11 text-base" />
</div>
<div className="space-y-2">
<Label htmlFor="password"></Label>
<Input id="password" name="password" type="password" defaultValue="ChangeMe123!" required className="h-11 text-base" />
<Input id="password" name="password" type="password" autoComplete="current-password" required className="h-11 text-base" />
</div>
</>
) : (
@@ -62,6 +62,11 @@ export function LoginPage() {
{login.isPending ? "登录中..." : challengeToken ? "验证登录" : "登录"}
</Button>
{challengeToken && <Button type="button" variant="ghost" className="w-full" onClick={() => setChallengeToken("")}></Button>}
{!challengeToken && publicSettings.data?.openRegistration && (
<Button type="button" variant="ghost" className="w-full" asChild>
<Link to="/register"></Link>
</Button>
)}
</form>
</div>
</div>
@@ -77,7 +82,7 @@ declare global {
}
}
function TurnstileBox({ siteKey, onToken }: { siteKey: string; onToken: (token: string) => void }) {
export function TurnstileBox({ siteKey, onToken }: { siteKey: string; onToken: (token: string) => void }) {
const ref = React.useRef<HTMLDivElement | null>(null)
React.useEffect(() => {
if (!siteKey || !ref.current) return