mirror of
https://github.com/Rain-kl/OpenFlare.git
synced 2026-10-06 15:46:37 +08:00
登录界面优化
This commit is contained in:
Binary file not shown.
|
Before Width: | Height: | Size: 74 KiB |
@@ -0,0 +1,31 @@
|
|||||||
|
import {ImageResponse} from 'next/og'
|
||||||
|
import {WavesIcon} from 'lucide-react'
|
||||||
|
|
||||||
|
export const size = {
|
||||||
|
width: 32,
|
||||||
|
height: 32,
|
||||||
|
}
|
||||||
|
export const contentType = 'image/png'
|
||||||
|
|
||||||
|
export default function Icon() {
|
||||||
|
return new ImageResponse(
|
||||||
|
(
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
background: 'black',
|
||||||
|
width: '100%',
|
||||||
|
height: '100%',
|
||||||
|
display: 'flex',
|
||||||
|
alignItems: 'center',
|
||||||
|
justifyContent: 'center',
|
||||||
|
borderRadius: '20%',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<WavesIcon color="white" size={20} />
|
||||||
|
</div>
|
||||||
|
),
|
||||||
|
{
|
||||||
|
...size,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -6,6 +6,7 @@ import {BellRingProvider} from "@/contexts/bell-ring-context";
|
|||||||
import {NotificationSettingsProvider} from "@/contexts/notification-settings-context";
|
import {NotificationSettingsProvider} from "@/contexts/notification-settings-context";
|
||||||
import {UserProvider} from "@/contexts/user-context";
|
import {UserProvider} from "@/contexts/user-context";
|
||||||
import {AppQueryProvider} from "@/components/providers/query-provider";
|
import {AppQueryProvider} from "@/components/providers/query-provider";
|
||||||
|
import {SiteTitleUpdater} from "@/components/providers/title-updater";
|
||||||
import {RobotsMeta} from "@/components/layout/robots-meta";
|
import {RobotsMeta} from "@/components/layout/robots-meta";
|
||||||
import "./globals.css";
|
import "./globals.css";
|
||||||
|
|
||||||
@@ -36,6 +37,7 @@ export default function RootLayout({
|
|||||||
>
|
>
|
||||||
<CustomThemeProvider>
|
<CustomThemeProvider>
|
||||||
<AppQueryProvider>
|
<AppQueryProvider>
|
||||||
|
<SiteTitleUpdater />
|
||||||
<RobotsMeta />
|
<RobotsMeta />
|
||||||
<UserProvider>
|
<UserProvider>
|
||||||
<NotificationSettingsProvider>
|
<NotificationSettingsProvider>
|
||||||
|
|||||||
@@ -0,0 +1,67 @@
|
|||||||
|
"use client"
|
||||||
|
|
||||||
|
import type {ReactNode} from "react"
|
||||||
|
import {motion} from "motion/react"
|
||||||
|
import {WavesIcon} from "lucide-react"
|
||||||
|
|
||||||
|
import {cn} from "@/lib/utils"
|
||||||
|
|
||||||
|
interface AuthShellProps {
|
||||||
|
children: ReactNode
|
||||||
|
wide?: boolean
|
||||||
|
}
|
||||||
|
|
||||||
|
export function AuthShell({children, wide = false}: AuthShellProps) {
|
||||||
|
return (
|
||||||
|
<main className="relative flex min-h-screen w-full items-center justify-center overflow-x-hidden bg-background px-4 py-6 sm:px-8 sm:py-8 [@media(max-height:700px)]:py-3">
|
||||||
|
<div
|
||||||
|
aria-hidden="true"
|
||||||
|
className="pointer-events-none absolute inset-0 bg-[linear-gradient(to_right,var(--border)_1px,transparent_1px),linear-gradient(to_bottom,var(--border)_1px,transparent_1px)] bg-[size:56px_56px] opacity-45 [mask-image:linear-gradient(to_bottom,transparent,black_12%,black_88%,transparent)]"
|
||||||
|
/>
|
||||||
|
<div
|
||||||
|
aria-hidden="true"
|
||||||
|
className="pointer-events-none absolute inset-y-0 left-1/2 w-px -translate-x-1/2 bg-border/70"
|
||||||
|
/>
|
||||||
|
<motion.section
|
||||||
|
initial={{opacity: 0, y: 18}}
|
||||||
|
animate={{opacity: 1, y: 0}}
|
||||||
|
transition={{duration: 0.45, ease: "easeOut"}}
|
||||||
|
className={cn(
|
||||||
|
"relative w-full border-x border-dashed border-border/80 bg-background/95 px-6 py-8 backdrop-blur-sm sm:px-10 sm:py-10 [@media(max-height:700px)]:py-5",
|
||||||
|
wide ? "max-w-2xl" : "max-w-xl",
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
{children}
|
||||||
|
</motion.section>
|
||||||
|
</main>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
interface AuthHeadingProps {
|
||||||
|
title: string
|
||||||
|
description: string
|
||||||
|
siteName?: string
|
||||||
|
}
|
||||||
|
|
||||||
|
export function AuthHeading({
|
||||||
|
title,
|
||||||
|
description,
|
||||||
|
siteName = "Wavelet",
|
||||||
|
}: AuthHeadingProps) {
|
||||||
|
return (
|
||||||
|
<header className="flex flex-col gap-6 [@media(max-height:700px)]:gap-3">
|
||||||
|
<div className="flex items-center gap-3">
|
||||||
|
<span className="flex size-9 items-center justify-center rounded-full bg-foreground text-background [@media(max-height:700px)]:size-8">
|
||||||
|
<WavesIcon aria-hidden="true" />
|
||||||
|
</span>
|
||||||
|
<span className="font-semibold tracking-tight [@media(min-height:761px)]:text-lg">{siteName}</span>
|
||||||
|
</div>
|
||||||
|
<div className="flex flex-col gap-1.5 [@media(max-height:700px)]:gap-1">
|
||||||
|
<h1 className="text-2xl font-semibold tracking-tight text-foreground sm:text-3xl [@media(min-height:900px)]:sm:text-4xl">
|
||||||
|
{title}
|
||||||
|
</h1>
|
||||||
|
<p className="text-sm text-muted-foreground [@media(min-height:900px)]:text-base">{description}</p>
|
||||||
|
</div>
|
||||||
|
</header>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -3,28 +3,31 @@
|
|||||||
import {useEffect, useMemo, useRef, useState} from "react"
|
import {useEffect, useMemo, useRef, useState} from "react"
|
||||||
import {useMutation, useQuery} from "@tanstack/react-query"
|
import {useMutation, useQuery} from "@tanstack/react-query"
|
||||||
import {useRouter, useSearchParams} from "next/navigation"
|
import {useRouter, useSearchParams} from "next/navigation"
|
||||||
import {KeyRound} from "lucide-react"
|
import {EyeIcon, EyeOffIcon} from "lucide-react"
|
||||||
import {toast} from "sonner"
|
import {toast} from "sonner"
|
||||||
import Link from "next/link"
|
import Link from "next/link"
|
||||||
|
|
||||||
import {useAuth} from "@/components/providers/auth-provider"
|
import {useAuth} from "@/components/providers/auth-provider"
|
||||||
import {Button} from "@/components/ui/button"
|
import {Button} from "@/components/ui/button"
|
||||||
import {Input} from "@/components/ui/input"
|
import {Input} from "@/components/ui/input"
|
||||||
import {Label} from "@/components/ui/label"
|
|
||||||
import {Separator} from "@/components/ui/separator"
|
import {Separator} from "@/components/ui/separator"
|
||||||
import {Spinner} from "@/components/ui/spinner"
|
import {Spinner} from "@/components/ui/spinner"
|
||||||
import {Card, CardContent} from "@/components/ui/card"
|
import {Field, FieldGroup, FieldLabel} from "@/components/ui/field"
|
||||||
import {CapWidget} from "@/components/auth/cap-widget"
|
import {CapWidget} from "@/components/auth/cap-widget"
|
||||||
|
import {AuthHeading} from "@/components/auth/auth-shell"
|
||||||
import {OTPForm} from "./otp-form"
|
import {OTPForm} from "./otp-form"
|
||||||
import services from "@/lib/services"
|
import services from "@/lib/services"
|
||||||
import type {LoginRequest} from "@/lib/services/auth/types"
|
import type {LoginRequest} from "@/lib/services/auth/types"
|
||||||
|
|
||||||
function getRedirectTarget(searchParams: ReturnType<typeof useSearchParams>) {
|
function getRedirectTarget(searchParams: ReturnType<typeof useSearchParams>) {
|
||||||
const callbackUrl = searchParams.get("callbackUrl")
|
const callbackUrl = searchParams.get("callbackUrl")
|
||||||
const storedRedirect = sessionStorage.getItem("redirect_after_login")
|
const storedRedirect =
|
||||||
|
typeof window === "undefined"
|
||||||
|
? null
|
||||||
|
: sessionStorage.getItem("redirect_after_login")
|
||||||
const target = callbackUrl || storedRedirect || "/home"
|
const target = callbackUrl || storedRedirect || "/home"
|
||||||
|
|
||||||
if (storedRedirect) {
|
if (storedRedirect && typeof window !== "undefined") {
|
||||||
sessionStorage.removeItem("redirect_after_login")
|
sessionStorage.removeItem("redirect_after_login")
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -33,7 +36,7 @@ function getRedirectTarget(searchParams: ReturnType<typeof useSearchParams>) {
|
|||||||
|
|
||||||
function persistRedirectTarget(searchParams: ReturnType<typeof useSearchParams>) {
|
function persistRedirectTarget(searchParams: ReturnType<typeof useSearchParams>) {
|
||||||
const callbackUrl = searchParams.get("callbackUrl")
|
const callbackUrl = searchParams.get("callbackUrl")
|
||||||
if (callbackUrl) {
|
if (callbackUrl && typeof window !== "undefined") {
|
||||||
sessionStorage.setItem("redirect_after_login", callbackUrl)
|
sessionStorage.setItem("redirect_after_login", callbackUrl)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -43,18 +46,23 @@ function configBool(value: string | undefined, fallback: boolean) {
|
|||||||
return value === "true"
|
return value === "true"
|
||||||
}
|
}
|
||||||
|
|
||||||
export function LoginForm() {
|
export function LoginForm({ onOTPStateChange }: { onOTPStateChange?: (show: boolean) => void }) {
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
const searchParams = useSearchParams()
|
const searchParams = useSearchParams()
|
||||||
const { setUser } = useAuth()
|
const { setUser } = useAuth()
|
||||||
const [username, setUsername] = useState("")
|
const [username, setUsername] = useState("")
|
||||||
const [password, setPassword] = useState("")
|
const [password, setPassword] = useState("")
|
||||||
|
const [showPassword, setShowPassword] = useState(false)
|
||||||
const [code, setCode] = useState("")
|
const [code, setCode] = useState("")
|
||||||
const [showLoginCodeInput, setShowLoginCodeInput] = useState(false)
|
const [showLoginCodeInput, setShowLoginCodeInput] = useState(false)
|
||||||
const [loginCooldown, setLoginCooldown] = useState(0)
|
const [loginCooldown, setLoginCooldown] = useState(0)
|
||||||
const [errorMessage, setErrorMessage] = useState("")
|
const [errorMessage, setErrorMessage] = useState("")
|
||||||
const [loginCodeTip, setLoginCodeTip] = useState<React.ReactNode>(null)
|
const [loginCodeTip, setLoginCodeTip] = useState<React.ReactNode>(null)
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
onOTPStateChange?.(showLoginCodeInput)
|
||||||
|
}, [showLoginCodeInput, onOTPStateChange])
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (loginCooldown > 0) {
|
if (loginCooldown > 0) {
|
||||||
const timer = setTimeout(() => setLoginCooldown(loginCooldown - 1), 1000)
|
const timer = setTimeout(() => setLoginCooldown(loginCooldown - 1), 1000)
|
||||||
@@ -125,9 +133,7 @@ export function LoginForm() {
|
|||||||
|
|
||||||
if (errorMsg.startsWith("smtp_invalid:")) {
|
if (errorMsg.startsWith("smtp_invalid:")) {
|
||||||
const tip = errorMsg.substring("smtp_invalid:".length)
|
const tip = errorMsg.substring("smtp_invalid:".length)
|
||||||
setLoginCodeTip(
|
setLoginCodeTip("请输入您的登录验证码。")
|
||||||
<span className="text-amber-500 font-medium">{tip}</span>
|
|
||||||
)
|
|
||||||
setShowLoginCodeInput(true)
|
setShowLoginCodeInput(true)
|
||||||
setLoginCooldown(0)
|
setLoginCooldown(0)
|
||||||
toast.warning(tip)
|
toast.warning(tip)
|
||||||
@@ -217,11 +223,9 @@ export function LoginForm() {
|
|||||||
|
|
||||||
if (publicConfigQuery.isPending) {
|
if (publicConfigQuery.isPending) {
|
||||||
return (
|
return (
|
||||||
<Card className="w-full border-border/60 bg-background/80 shadow-2xl backdrop-blur">
|
<div className="flex items-center justify-center py-24">
|
||||||
<CardContent className="flex justify-center items-center py-12">
|
<Spinner />
|
||||||
<Spinner />
|
</div>
|
||||||
</CardContent>
|
|
||||||
</Card>
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -240,111 +244,123 @@ export function LoginForm() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Card className="w-full border-border/60 bg-background/80 shadow-2xl backdrop-blur">
|
<div className="flex flex-col gap-6 [@media(max-height:700px)]:gap-4">
|
||||||
<CardContent className="space-y-5 p-5 sm:p-6">
|
<AuthHeading
|
||||||
<div className="space-y-2 text-center">
|
siteName={publicConfigQuery.data?.site_name}
|
||||||
<h2 className="text-xl font-semibold tracking-tight text-foreground">
|
title="登录到您的账号"
|
||||||
账号登录
|
description="欢迎回来,请输入您的账号信息继续。"
|
||||||
</h2>
|
/>
|
||||||
</div>
|
|
||||||
|
|
||||||
<div className="space-y-4 pt-2">
|
<div className="flex flex-col gap-5 [@media(max-height:700px)]:gap-3">
|
||||||
<div className="space-y-3">
|
<FieldGroup className="gap-4 [@media(max-height:700px)]:gap-3">
|
||||||
<div className="space-y-3">
|
<Field className="gap-1.5">
|
||||||
<div className="space-y-1.5">
|
<FieldLabel htmlFor="username">
|
||||||
<Label htmlFor="username">邮箱/用户名</Label>
|
邮箱或用户名 <span className="text-destructive">*</span>
|
||||||
<Input
|
</FieldLabel>
|
||||||
id="username"
|
<Input
|
||||||
value={username}
|
id="username"
|
||||||
onChange={(e) => setUsername(e.target.value)}
|
value={username}
|
||||||
placeholder="请输入邮箱或用户名"
|
onChange={(e) => setUsername(e.target.value)}
|
||||||
autoComplete="username"
|
placeholder="输入邮箱或用户名"
|
||||||
onKeyDown={(e) => e.key === "Enter" && handlePasswordLogin()}
|
autoComplete="username"
|
||||||
/>
|
className="h-10 text-sm [@media(max-height:700px)]:h-9"
|
||||||
</div>
|
onKeyDown={(e) => e.key === "Enter" && handlePasswordLogin()}
|
||||||
<div className="space-y-1.5">
|
/>
|
||||||
<Label htmlFor="password">密码</Label>
|
</Field>
|
||||||
<Input
|
<Field className="gap-1.5">
|
||||||
id="password"
|
<FieldLabel htmlFor="password">
|
||||||
value={password}
|
密码 <span className="text-destructive">*</span>
|
||||||
onChange={(e) => setPassword(e.target.value)}
|
</FieldLabel>
|
||||||
type="password"
|
<div className="relative">
|
||||||
placeholder="请输入密码"
|
<Input
|
||||||
autoComplete="current-password"
|
id="password"
|
||||||
onKeyDown={(e) => e.key === "Enter" && handlePasswordLogin()}
|
value={password}
|
||||||
/>
|
onChange={(e) => setPassword(e.target.value)}
|
||||||
</div>
|
type={showPassword ? "text" : "password"}
|
||||||
|
placeholder="输入您的密码"
|
||||||
</div>
|
autoComplete="current-password"
|
||||||
|
className="h-10 pr-11 text-sm [@media(max-height:700px)]:h-9"
|
||||||
{/* Cap 人机验证 */}
|
onKeyDown={(e) => e.key === "Enter" && handlePasswordLogin()}
|
||||||
{capEnabled && (
|
|
||||||
<CapWidget
|
|
||||||
key={capResetKey}
|
|
||||||
onToken={handleCapToken}
|
|
||||||
onError={handleCapError}
|
|
||||||
autoStart={capAutoSolve}
|
|
||||||
/>
|
/>
|
||||||
)}
|
<Button
|
||||||
|
type="button"
|
||||||
{errorMessage ? (
|
variant="ghost"
|
||||||
<div className="rounded-lg border border-destructive/30 bg-destructive/5 px-3 py-2 text-sm text-destructive">
|
size="icon-sm"
|
||||||
{errorMessage}
|
aria-label={showPassword ? "隐藏密码" : "显示密码"}
|
||||||
</div>
|
className="absolute right-1.5 top-1/2 -translate-y-1/2 text-muted-foreground"
|
||||||
) : null}
|
onClick={() => setShowPassword((visible) => !visible)}
|
||||||
|
>
|
||||||
<Button
|
{showPassword ? <EyeOffIcon /> : <EyeIcon />}
|
||||||
type="button"
|
</Button>
|
||||||
className="w-full"
|
|
||||||
variant={"secondary"}
|
|
||||||
onClick={handlePasswordLogin}
|
|
||||||
disabled={loginDisabled}
|
|
||||||
>
|
|
||||||
{loginMutation.isPending ? (
|
|
||||||
<>
|
|
||||||
<Spinner className="mr-2" />
|
|
||||||
登录中...
|
|
||||||
</>
|
|
||||||
) : (
|
|
||||||
<>
|
|
||||||
<KeyRound className="mr-2 size-4" />
|
|
||||||
登录
|
|
||||||
</>
|
|
||||||
)}
|
|
||||||
</Button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{authSources.length > 0 ? (
|
|
||||||
<>
|
|
||||||
<Separator />
|
|
||||||
<div className="space-y-3">
|
|
||||||
<div className="grid gap-2">
|
|
||||||
{authSources.map((source) => (
|
|
||||||
<Button
|
|
||||||
key={source.id}
|
|
||||||
type="button"
|
|
||||||
variant="outline"
|
|
||||||
className="justify-start"
|
|
||||||
onClick={() => void handleOAuthLogin(source.name)}
|
|
||||||
>
|
|
||||||
{source.display_name || source.name} 登录
|
|
||||||
</Button>
|
|
||||||
))}
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</>
|
</Field>
|
||||||
|
</FieldGroup>
|
||||||
|
|
||||||
|
{/* Cap 人机验证 */}
|
||||||
|
{capEnabled && (
|
||||||
|
<CapWidget
|
||||||
|
key={capResetKey}
|
||||||
|
onToken={handleCapToken}
|
||||||
|
onError={handleCapError}
|
||||||
|
autoStart={capAutoSolve}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{errorMessage ? (
|
||||||
|
<div className="rounded-lg border border-destructive/30 bg-destructive/5 px-3 py-2 text-sm text-destructive">
|
||||||
|
{errorMessage}
|
||||||
|
</div>
|
||||||
) : null}
|
) : null}
|
||||||
|
|
||||||
{registrationEnabled && (
|
<Button
|
||||||
<div className="text-center text-xs text-muted-foreground mt-4">
|
type="button"
|
||||||
{"Don't have an account?"}{" "}
|
className="h-10 w-full [@media(max-height:700px)]:h-9"
|
||||||
<Link href="/register" className="font-semibold text-indigo-500 hover:text-indigo-600 transition-colors">
|
variant="auth"
|
||||||
Sign up
|
onClick={handlePasswordLogin}
|
||||||
</Link>
|
disabled={loginDisabled}
|
||||||
|
>
|
||||||
|
{loginMutation.isPending ? (
|
||||||
|
<>
|
||||||
|
<Spinner />
|
||||||
|
登录中...
|
||||||
|
</>
|
||||||
|
) : (
|
||||||
|
"登录"
|
||||||
|
)}
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{authSources.length > 0 ? (
|
||||||
|
<div className="flex flex-col gap-3">
|
||||||
|
<div className="flex items-center gap-3">
|
||||||
|
<Separator className="flex-1" />
|
||||||
|
<span className="text-xs text-muted-foreground">或者使用</span>
|
||||||
|
<Separator className="flex-1" />
|
||||||
</div>
|
</div>
|
||||||
)}
|
<div className="grid gap-2">
|
||||||
</CardContent>
|
{authSources.map((source) => (
|
||||||
</Card>
|
<Button
|
||||||
|
key={source.id}
|
||||||
|
type="button"
|
||||||
|
variant="outline"
|
||||||
|
className="h-10 [@media(max-height:700px)]:h-9"
|
||||||
|
onClick={() => void handleOAuthLogin(source.name)}
|
||||||
|
>
|
||||||
|
{source.display_name || source.name} 登录
|
||||||
|
</Button>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
) : null}
|
||||||
|
|
||||||
|
{registrationEnabled && (
|
||||||
|
<div className="text-center text-sm text-muted-foreground">
|
||||||
|
还没有账号?{" "}
|
||||||
|
<Link href="/register" className="font-medium text-foreground underline underline-offset-4">
|
||||||
|
立即注册
|
||||||
|
</Link>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,9 +6,9 @@ import {useRouter, useSearchParams} from "next/navigation"
|
|||||||
import {toast} from "sonner"
|
import {toast} from "sonner"
|
||||||
import {Spinner} from "@/components/ui/spinner"
|
import {Spinner} from "@/components/ui/spinner"
|
||||||
import {LoginForm} from "@/components/auth/login-form"
|
import {LoginForm} from "@/components/auth/login-form"
|
||||||
|
import {AuthShell} from "@/components/auth/auth-shell"
|
||||||
import {Check} from "lucide-react"
|
import {Check} from "lucide-react"
|
||||||
|
|
||||||
import {AuroraBackground} from "@/components/ui/aurora-background"
|
|
||||||
import services from "@/lib/services"
|
import services from "@/lib/services"
|
||||||
import {useAuth} from "@/components/providers/auth-provider"
|
import {useAuth} from "@/components/providers/auth-provider"
|
||||||
|
|
||||||
@@ -27,6 +27,7 @@ export function LoginPage() {
|
|||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
const searchParams = useSearchParams()
|
const searchParams = useSearchParams()
|
||||||
const { setUser } = useAuth()
|
const { setUser } = useAuth()
|
||||||
|
const [showOTP, setShowOTP] = useState(false)
|
||||||
|
|
||||||
/* 处理OAuth回调 */
|
/* 处理OAuth回调 */
|
||||||
const [isProcessingCallback, setIsProcessingCallback] = useState(() => {
|
const [isProcessingCallback, setIsProcessingCallback] = useState(() => {
|
||||||
@@ -136,25 +137,8 @@ export function LoginPage() {
|
|||||||
}, [searchParams, router, resolveRedirectTarget, setUser])
|
}, [searchParams, router, resolveRedirectTarget, setUser])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<AuroraBackground>
|
<AuthShell wide={showOTP}>
|
||||||
<motion.div
|
<div className="w-full">
|
||||||
initial={{ opacity: 0, y: 40 }}
|
|
||||||
whileInView={{ opacity: 1, y: 0 }}
|
|
||||||
viewport={{ once: true }}
|
|
||||||
transition={{
|
|
||||||
delay: 0.3,
|
|
||||||
duration: 0.8,
|
|
||||||
ease: "easeInOut",
|
|
||||||
}}
|
|
||||||
className="relative z-10 w-full max-w-sm px-4"
|
|
||||||
>
|
|
||||||
{/*Title Do Not Remove*/}
|
|
||||||
{/*<div className="text-center mb-8 space-y-2">*/}
|
|
||||||
{/* <h1 className="text-3xl font-bold tracking-tight text-foreground">*/}
|
|
||||||
{/* Refresh*/}
|
|
||||||
{/* </h1>*/}
|
|
||||||
{/*</div>*/}
|
|
||||||
|
|
||||||
<AnimatePresence mode="wait">
|
<AnimatePresence mode="wait">
|
||||||
{isProcessingCallback || isCheckingSession ? (
|
{isProcessingCallback || isCheckingSession ? (
|
||||||
<motion.div
|
<motion.div
|
||||||
@@ -165,36 +149,36 @@ export function LoginPage() {
|
|||||||
className="w-full"
|
className="w-full"
|
||||||
>
|
>
|
||||||
{isCheckingSession ? (
|
{isCheckingSession ? (
|
||||||
<div className="flex flex-col items-center justify-center space-y-4 py-2">
|
<div className="flex flex-col items-center justify-center gap-4 py-16">
|
||||||
<div className="relative">
|
<div className="relative">
|
||||||
<Spinner className="w-8 h-8 text-blue-600" />
|
<Spinner className="size-8" />
|
||||||
</div>
|
</div>
|
||||||
<div className="text-center space-y-2">
|
<div className="flex flex-col gap-2 text-center">
|
||||||
<h3 className="font-semibold tracking-tight text-foreground">正在检查登录状态</h3>
|
<h3 className="font-semibold tracking-tight text-foreground">正在检查登录状态</h3>
|
||||||
<p className="text-xs text-muted-foreground">请稍候,我们正在确认当前会话...</p>
|
<p className="text-xs text-muted-foreground">请稍候,我们正在确认当前会话...</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
) : loginSuccess ? (
|
) : loginSuccess ? (
|
||||||
<div className="flex flex-col items-center justify-center space-y-4 py-2">
|
<div className="flex flex-col items-center justify-center gap-4 py-16">
|
||||||
<motion.div
|
<motion.div
|
||||||
initial={{ scale: 0.5, opacity: 0 }}
|
initial={{ scale: 0.5, opacity: 0 }}
|
||||||
animate={{ scale: 1, opacity: 1 }}
|
animate={{ scale: 1, opacity: 1 }}
|
||||||
transition={{ type: "spring", stiffness: 300, damping: 20 }}
|
transition={{ type: "spring", stiffness: 300, damping: 20 }}
|
||||||
className="w-8 h-8 rounded-full bg-green-500/10 flex items-center justify-center text-green-500 ring-1 ring-green-500/20"
|
className="flex size-8 items-center justify-center rounded-full bg-primary/10 text-primary ring-1 ring-primary/20"
|
||||||
>
|
>
|
||||||
<Check className="w-6 h-6" strokeWidth={3} />
|
<Check className="size-6" strokeWidth={3} />
|
||||||
</motion.div>
|
</motion.div>
|
||||||
<div className="text-center space-y-2">
|
<div className="flex flex-col gap-2 text-center">
|
||||||
<h3 className="font-semibold tracking-tight text-foreground">登录成功</h3>
|
<h3 className="font-semibold tracking-tight text-foreground">登录成功</h3>
|
||||||
<p className="text-xs text-muted-foreground">正在跳转至控制台...</p>
|
<p className="text-xs text-muted-foreground">正在跳转至控制台...</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
) : (
|
) : (
|
||||||
<div className="flex flex-col items-center justify-center space-y-4 py-2">
|
<div className="flex flex-col items-center justify-center gap-4 py-16">
|
||||||
<div className="relative">
|
<div className="relative">
|
||||||
<Spinner className="w-8 h-8 text-blue-600" />
|
<Spinner className="size-8" />
|
||||||
</div>
|
</div>
|
||||||
<div className="text-center space-y-2">
|
<div className="flex flex-col gap-2 text-center">
|
||||||
<h3 className="font-semibold tracking-tight text-foreground">正在验证凭据</h3>
|
<h3 className="font-semibold tracking-tight text-foreground">正在验证凭据</h3>
|
||||||
<p className="text-xs text-muted-foreground">请稍候,我们正在为您建立安全会话...</p>
|
<p className="text-xs text-muted-foreground">请稍候,我们正在为您建立安全会话...</p>
|
||||||
</div>
|
</div>
|
||||||
@@ -209,11 +193,11 @@ export function LoginPage() {
|
|||||||
transition={{ duration: 0.4 }}
|
transition={{ duration: 0.4 }}
|
||||||
className="w-full"
|
className="w-full"
|
||||||
>
|
>
|
||||||
<LoginForm />
|
<LoginForm onOTPStateChange={setShowOTP} />
|
||||||
</motion.div>
|
</motion.div>
|
||||||
)}
|
)}
|
||||||
</AnimatePresence>
|
</AnimatePresence>
|
||||||
</motion.div>
|
</div>
|
||||||
</AuroraBackground>
|
</AuthShell>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,9 +4,9 @@ import * as React from "react"
|
|||||||
import {RefreshCwIcon} from "lucide-react"
|
import {RefreshCwIcon} from "lucide-react"
|
||||||
|
|
||||||
import {Button} from "@/components/ui/button"
|
import {Button} from "@/components/ui/button"
|
||||||
import {Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle,} from "@/components/ui/card"
|
|
||||||
import {Field, FieldLabel} from "@/components/ui/field"
|
import {Field, FieldLabel} from "@/components/ui/field"
|
||||||
import {InputOTP, InputOTPGroup, InputOTPSeparator, InputOTPSlot,} from "@/components/ui/input-otp"
|
import {InputOTP, InputOTPGroup, InputOTPSeparator, InputOTPSlot,} from "@/components/ui/input-otp"
|
||||||
|
import {AuthHeading} from "@/components/auth/auth-shell"
|
||||||
import {cn} from "@/lib/utils"
|
import {cn} from "@/lib/utils"
|
||||||
|
|
||||||
interface OTPFormProps {
|
interface OTPFormProps {
|
||||||
@@ -29,17 +29,16 @@ export function OTPForm({
|
|||||||
onSubmit,
|
onSubmit,
|
||||||
}: OTPFormProps) {
|
}: OTPFormProps) {
|
||||||
return (
|
return (
|
||||||
<Card className="w-full border-border/60 bg-background/80 shadow-2xl backdrop-blur">
|
<div className="flex flex-col gap-6 [@media(max-height:700px)]:gap-4">
|
||||||
<CardHeader className="space-y-1.5 p-5 sm:p-6 pb-2 text-center">
|
<AuthHeading
|
||||||
<CardTitle className="text-xl font-semibold tracking-tight text-foreground">
|
title="验证您的登录"
|
||||||
验证登录
|
description="输入发送到安全邮箱的 6 位验证码。"
|
||||||
</CardTitle>
|
/>
|
||||||
<CardDescription className="text-sm text-muted-foreground leading-normal">
|
{loginCodeTip ? (
|
||||||
{loginCodeTip}
|
<p className="text-sm leading-6 text-muted-foreground">{loginCodeTip}</p>
|
||||||
</CardDescription>
|
) : null}
|
||||||
</CardHeader>
|
<div className="flex flex-col gap-5 [@media(max-height:700px)]:gap-3">
|
||||||
<CardContent className="space-y-5 p-5 sm:p-6 pt-2">
|
<Field className="gap-3">
|
||||||
<Field className="space-y-3">
|
|
||||||
<div className="flex items-center justify-between">
|
<div className="flex items-center justify-between">
|
||||||
<FieldLabel htmlFor="otp-verification" className="text-sm font-medium">
|
<FieldLabel htmlFor="otp-verification" className="text-sm font-medium">
|
||||||
验证码
|
验证码
|
||||||
@@ -50,13 +49,13 @@ export function OTPForm({
|
|||||||
type="button"
|
type="button"
|
||||||
onClick={onResend}
|
onClick={onResend}
|
||||||
disabled={loginCooldown > 0 || isPending}
|
disabled={loginCooldown > 0 || isPending}
|
||||||
className="gap-1 text-xs px-2 py-1 h-7"
|
className="h-8 text-xs"
|
||||||
>
|
>
|
||||||
<RefreshCwIcon className={cn("size-3", isPending && "animate-spin")} />
|
<RefreshCwIcon className={cn(isPending && "animate-spin")} />
|
||||||
{loginCooldown > 0 ? `${loginCooldown}秒后重发` : "重新发送"}
|
{loginCooldown > 0 ? `${loginCooldown}秒后重发` : "重新发送"}
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
<div className="flex justify-center">
|
<div className="flex justify-start">
|
||||||
<InputOTP
|
<InputOTP
|
||||||
maxLength={6}
|
maxLength={6}
|
||||||
id="otp-verification"
|
id="otp-verification"
|
||||||
@@ -80,17 +79,16 @@ export function OTPForm({
|
|||||||
</InputOTP>
|
</InputOTP>
|
||||||
</div>
|
</div>
|
||||||
</Field>
|
</Field>
|
||||||
</CardContent>
|
|
||||||
<CardFooter className="flex-col gap-4 p-5 sm:p-6 pt-2">
|
|
||||||
<Button
|
<Button
|
||||||
type="button"
|
type="button"
|
||||||
className="w-full"
|
className="h-10 w-full [@media(max-height:700px)]:h-9"
|
||||||
|
variant="auth"
|
||||||
onClick={onSubmit}
|
onClick={onSubmit}
|
||||||
disabled={isPending || code.length < 6}
|
disabled={isPending || code.length < 6}
|
||||||
>
|
>
|
||||||
{isPending ? "验证中..." : "验证"}
|
{isPending ? "验证中..." : "验证"}
|
||||||
</Button>
|
</Button>
|
||||||
<div className="text-xs text-muted-foreground text-center">
|
<div className="text-center text-sm text-muted-foreground">
|
||||||
遇到登录问题?{" "}
|
遇到登录问题?{" "}
|
||||||
<a
|
<a
|
||||||
href="#"
|
href="#"
|
||||||
@@ -99,7 +97,7 @@ export function OTPForm({
|
|||||||
联系客服
|
联系客服
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
</CardFooter>
|
</div>
|
||||||
</Card>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,22 +3,24 @@
|
|||||||
import {useEffect, useMemo, useState} from "react"
|
import {useEffect, useMemo, useState} from "react"
|
||||||
import {useMutation, useQuery} from "@tanstack/react-query"
|
import {useMutation, useQuery} from "@tanstack/react-query"
|
||||||
import {useRouter, useSearchParams} from "next/navigation"
|
import {useRouter, useSearchParams} from "next/navigation"
|
||||||
import {UserPlus} from "lucide-react"
|
|
||||||
import {toast} from "sonner"
|
import {toast} from "sonner"
|
||||||
import Link from "next/link"
|
import Link from "next/link"
|
||||||
|
|
||||||
import {useAuth} from "@/components/providers/auth-provider"
|
import {useAuth} from "@/components/providers/auth-provider"
|
||||||
import {Button} from "@/components/ui/button"
|
import {Button} from "@/components/ui/button"
|
||||||
import {Input} from "@/components/ui/input"
|
import {Input} from "@/components/ui/input"
|
||||||
import {Label} from "@/components/ui/label"
|
|
||||||
import {Spinner} from "@/components/ui/spinner"
|
import {Spinner} from "@/components/ui/spinner"
|
||||||
import {Card, CardContent} from "@/components/ui/card"
|
import {Field, FieldGroup, FieldLabel} from "@/components/ui/field"
|
||||||
|
import {AuthHeading} from "@/components/auth/auth-shell"
|
||||||
import services from "@/lib/services"
|
import services from "@/lib/services"
|
||||||
import type {RegisterRequest} from "@/lib/services/auth/types"
|
import type {RegisterRequest} from "@/lib/services/auth/types"
|
||||||
|
|
||||||
function getRedirectTarget(searchParams: ReturnType<typeof useSearchParams>) {
|
function getRedirectTarget(searchParams: ReturnType<typeof useSearchParams>) {
|
||||||
const callbackUrl = searchParams.get("callbackUrl")
|
const callbackUrl = searchParams.get("callbackUrl")
|
||||||
const storedRedirect = sessionStorage.getItem("redirect_after_login")
|
const storedRedirect =
|
||||||
|
typeof window === "undefined"
|
||||||
|
? null
|
||||||
|
: sessionStorage.getItem("redirect_after_login")
|
||||||
return callbackUrl || storedRedirect || "/home"
|
return callbackUrl || storedRedirect || "/home"
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -142,11 +144,9 @@ export function RegisterForm() {
|
|||||||
|
|
||||||
if (publicConfigQuery.isPending) {
|
if (publicConfigQuery.isPending) {
|
||||||
return (
|
return (
|
||||||
<Card className="w-full border-border/60 bg-background/80 shadow-2xl backdrop-blur">
|
<div className="flex items-center justify-center py-24">
|
||||||
<CardContent className="flex justify-center items-center py-12">
|
<Spinner />
|
||||||
<Spinner />
|
</div>
|
||||||
</CardContent>
|
|
||||||
</Card>
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -155,125 +155,124 @@ export function RegisterForm() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Card className="w-full border-border/60 bg-background/80 shadow-2xl backdrop-blur">
|
<div className="flex flex-col gap-6 [@media(max-height:700px)]:gap-4">
|
||||||
<CardContent className="space-y-5 p-5 sm:p-6">
|
<AuthHeading
|
||||||
<div className="space-y-2 text-center">
|
siteName={publicConfigQuery.data?.site_name}
|
||||||
<h2 className="text-xl font-semibold tracking-tight text-foreground">
|
title="创建您的账号"
|
||||||
创建账号
|
description="填写以下信息,开始使用平台服务。"
|
||||||
</h2>
|
/>
|
||||||
</div>
|
|
||||||
|
|
||||||
<div className="space-y-3 pt-2">
|
<div className="flex flex-col gap-5 [@media(max-height:700px)]:gap-3">
|
||||||
<div className="space-y-3">
|
<FieldGroup className="gap-4 [@media(min-width:500px)]:grid [@media(min-width:500px)]:grid-cols-2 [@media(max-height:700px)]:gap-3">
|
||||||
<div className="space-y-1.5">
|
<Field className="gap-1.5">
|
||||||
<Label htmlFor="username">用户名</Label>
|
<FieldLabel htmlFor="username">用户名 <span className="text-destructive">*</span></FieldLabel>
|
||||||
<Input
|
<Input
|
||||||
id="username"
|
id="username"
|
||||||
value={username}
|
value={username}
|
||||||
onChange={(e) => setUsername(e.target.value)}
|
onChange={(e) => setUsername(e.target.value)}
|
||||||
placeholder="请输入用户名"
|
placeholder="请输入用户名"
|
||||||
autoComplete="username"
|
autoComplete="username"
|
||||||
onKeyDown={(e) => e.key === "Enter" && handleRegister()}
|
className="h-10 text-sm [@media(max-height:700px)]:h-9"
|
||||||
/>
|
onKeyDown={(e) => e.key === "Enter" && handleRegister()}
|
||||||
</div>
|
/>
|
||||||
<div className="space-y-1.5">
|
</Field>
|
||||||
<Label htmlFor="nickname">
|
<Field className="gap-1.5">
|
||||||
昵称
|
<FieldLabel htmlFor="nickname">
|
||||||
<span className="text-muted-foreground font-normal text-xs ml-1">(可选)</span>
|
昵称
|
||||||
</Label>
|
<span className="ml-1 text-xs font-normal text-muted-foreground">(可选)</span>
|
||||||
<Input
|
</FieldLabel>
|
||||||
id="nickname"
|
<Input
|
||||||
value={nickname}
|
id="nickname"
|
||||||
onChange={(e) => setNickname(e.target.value)}
|
value={nickname}
|
||||||
placeholder="请输入昵称"
|
onChange={(e) => setNickname(e.target.value)}
|
||||||
autoComplete="nickname"
|
placeholder="请输入昵称"
|
||||||
onKeyDown={(e) => e.key === "Enter" && handleRegister()}
|
autoComplete="nickname"
|
||||||
/>
|
className="h-10 text-sm [@media(max-height:700px)]:h-9"
|
||||||
</div>
|
onKeyDown={(e) => e.key === "Enter" && handleRegister()}
|
||||||
<div className="space-y-1.5">
|
/>
|
||||||
<Label htmlFor="password">密码</Label>
|
</Field>
|
||||||
<Input
|
<Field className="gap-1.5">
|
||||||
id="password"
|
<FieldLabel htmlFor="email">电子邮箱 <span className="text-destructive">*</span></FieldLabel>
|
||||||
value={password}
|
<Input
|
||||||
onChange={(e) => setPassword(e.target.value)}
|
id="email"
|
||||||
type="password"
|
value={email}
|
||||||
placeholder="请输入密码(至少 8 位)"
|
onChange={(e) => setEmail(e.target.value)}
|
||||||
autoComplete="new-password"
|
placeholder="请输入电子邮箱"
|
||||||
onKeyDown={(e) => e.key === "Enter" && handleRegister()}
|
autoComplete="email"
|
||||||
/>
|
className="h-10 text-sm [@media(max-height:700px)]:h-9"
|
||||||
</div>
|
onKeyDown={(e) => e.key === "Enter" && handleRegister()}
|
||||||
<div className="space-y-1.5">
|
/>
|
||||||
<Label htmlFor="email">电子邮箱</Label>
|
</Field>
|
||||||
<Input
|
<Field className="gap-1.5">
|
||||||
id="email"
|
<FieldLabel htmlFor="password">密码 <span className="text-destructive">*</span></FieldLabel>
|
||||||
value={email}
|
<Input
|
||||||
onChange={(e) => setEmail(e.target.value)}
|
id="password"
|
||||||
placeholder="请输入电子邮箱"
|
value={password}
|
||||||
autoComplete="email"
|
onChange={(e) => setPassword(e.target.value)}
|
||||||
onKeyDown={(e) => e.key === "Enter" && handleRegister()}
|
type="password"
|
||||||
/>
|
placeholder="请输入密码(至少 8 位)"
|
||||||
</div>
|
autoComplete="new-password"
|
||||||
{emailRegisterEnabled && (
|
className="h-10 text-sm [@media(max-height:700px)]:h-9"
|
||||||
<div className="space-y-1.5">
|
onKeyDown={(e) => e.key === "Enter" && handleRegister()}
|
||||||
<Label htmlFor="code">邮箱验证码</Label>
|
/>
|
||||||
<div className="flex gap-2">
|
</Field>
|
||||||
<Input
|
{emailRegisterEnabled && (
|
||||||
id="code"
|
<Field className="gap-1.5 [@media(min-width:500px)]:col-span-2">
|
||||||
value={code}
|
<FieldLabel htmlFor="code">邮箱验证码 <span className="text-destructive">*</span></FieldLabel>
|
||||||
onChange={(e) => setCode(e.target.value)}
|
<div className="flex gap-2">
|
||||||
placeholder="请输入 6 位邮箱验证码"
|
<Input
|
||||||
maxLength={6}
|
id="code"
|
||||||
className="flex-1"
|
value={code}
|
||||||
onKeyDown={(e) => e.key === "Enter" && handleRegister()}
|
onChange={(e) => setCode(e.target.value)}
|
||||||
/>
|
placeholder="请输入 6 位邮箱验证码"
|
||||||
<Button
|
maxLength={6}
|
||||||
type="button"
|
className="h-10 flex-1 text-sm [@media(max-height:700px)]:h-9"
|
||||||
variant="outline"
|
onKeyDown={(e) => e.key === "Enter" && handleRegister()}
|
||||||
onClick={handleSendRegisterCode}
|
/>
|
||||||
disabled={registerCooldown > 0 || sendRegisterCodeMutation.isPending}
|
<Button
|
||||||
className="w-[120px] text-xs"
|
type="button"
|
||||||
>
|
variant="outline"
|
||||||
{registerCooldown > 0 ? `${registerCooldown}秒后重发` : "获取验证码"}
|
onClick={handleSendRegisterCode}
|
||||||
</Button>
|
disabled={registerCooldown > 0 || sendRegisterCodeMutation.isPending}
|
||||||
</div>
|
className="h-10 w-[120px] text-xs [@media(max-height:700px)]:h-9"
|
||||||
|
>
|
||||||
|
{registerCooldown > 0 ? `${registerCooldown}秒后重发` : "获取验证码"}
|
||||||
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
)}
|
</Field>
|
||||||
|
)}
|
||||||
|
</FieldGroup>
|
||||||
|
|
||||||
|
{errorMessage ? (
|
||||||
|
<div className="rounded-lg border border-destructive/30 bg-destructive/5 px-3 py-2 text-sm text-destructive">
|
||||||
|
{errorMessage}
|
||||||
</div>
|
</div>
|
||||||
|
) : null}
|
||||||
|
|
||||||
{errorMessage ? (
|
<Button
|
||||||
<div className="rounded-lg border border-destructive/30 bg-destructive/5 px-3 py-2 text-sm text-destructive">
|
type="button"
|
||||||
{errorMessage}
|
className="h-10 w-full [@media(max-height:700px)]:h-9"
|
||||||
</div>
|
variant="auth"
|
||||||
) : null}
|
onClick={handleRegister}
|
||||||
|
disabled={registerMutation.isPending}
|
||||||
|
>
|
||||||
|
{registerMutation.isPending ? (
|
||||||
|
<>
|
||||||
|
<Spinner />
|
||||||
|
注册中...
|
||||||
|
</>
|
||||||
|
) : (
|
||||||
|
"创建账号"
|
||||||
|
)}
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
|
||||||
<Button
|
<div className="text-center text-sm text-muted-foreground">
|
||||||
type="button"
|
已经有账号?{" "}
|
||||||
className="w-full"
|
<Link href="/login" className="font-medium text-foreground underline underline-offset-4">
|
||||||
variant="secondary"
|
返回登录
|
||||||
onClick={handleRegister}
|
</Link>
|
||||||
disabled={registerMutation.isPending}
|
</div>
|
||||||
>
|
</div>
|
||||||
{registerMutation.isPending ? (
|
|
||||||
<>
|
|
||||||
<Spinner className="mr-2" />
|
|
||||||
注册中...
|
|
||||||
</>
|
|
||||||
) : (
|
|
||||||
<>
|
|
||||||
<UserPlus className="mr-2 size-4" />
|
|
||||||
创建账号
|
|
||||||
</>
|
|
||||||
)}
|
|
||||||
</Button>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div className="text-center text-xs text-muted-foreground mt-4">
|
|
||||||
Already have an account?{" "}
|
|
||||||
<Link href="/login" className="font-semibold text-indigo-500 hover:text-indigo-600 transition-colors">
|
|
||||||
Sign in
|
|
||||||
</Link>
|
|
||||||
</div>
|
|
||||||
</CardContent>
|
|
||||||
</Card>
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,25 +1,12 @@
|
|||||||
"use client"
|
"use client"
|
||||||
|
|
||||||
import {motion} from "motion/react"
|
|
||||||
import {RegisterForm} from "@/components/auth/register-form"
|
import {RegisterForm} from "@/components/auth/register-form"
|
||||||
import {AuroraBackground} from "@/components/ui/aurora-background"
|
import {AuthShell} from "@/components/auth/auth-shell"
|
||||||
|
|
||||||
export function RegisterPage() {
|
export function RegisterPage() {
|
||||||
return (
|
return (
|
||||||
<AuroraBackground>
|
<AuthShell wide>
|
||||||
<motion.div
|
<RegisterForm />
|
||||||
initial={{ opacity: 0, y: 40 }}
|
</AuthShell>
|
||||||
whileInView={{ opacity: 1, y: 0 }}
|
|
||||||
viewport={{ once: true }}
|
|
||||||
transition={{
|
|
||||||
delay: 0.3,
|
|
||||||
duration: 0.8,
|
|
||||||
ease: "easeInOut",
|
|
||||||
}}
|
|
||||||
className="relative z-10 w-full max-w-sm px-4"
|
|
||||||
>
|
|
||||||
<RegisterForm />
|
|
||||||
</motion.div>
|
|
||||||
</AuroraBackground>
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,36 @@
|
|||||||
|
"use client"
|
||||||
|
|
||||||
|
import {useQuery} from '@tanstack/react-query'
|
||||||
|
import {useEffect} from 'react'
|
||||||
|
import services from '@/lib/services'
|
||||||
|
import {usePathname} from 'next/navigation'
|
||||||
|
|
||||||
|
export function SiteTitleUpdater() {
|
||||||
|
const pathname = usePathname()
|
||||||
|
const publicConfigQuery = useQuery({
|
||||||
|
queryKey: ["public-config"],
|
||||||
|
queryFn: () => services.config.getPublicConfig(),
|
||||||
|
})
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const siteName = publicConfigQuery.data?.site_name || "Wavelet Platform"
|
||||||
|
|
||||||
|
// Determine the page suffix based on path
|
||||||
|
let suffix = ""
|
||||||
|
if (pathname === "/login") {
|
||||||
|
suffix = " - 登录"
|
||||||
|
} else if (pathname === "/register") {
|
||||||
|
suffix = " - 注册"
|
||||||
|
} else if (pathname.startsWith("/admin")) {
|
||||||
|
suffix = " - 后台管理"
|
||||||
|
} else if (pathname === "/home") {
|
||||||
|
suffix = " - 控制台"
|
||||||
|
} else if (pathname === "/") {
|
||||||
|
suffix = ""
|
||||||
|
}
|
||||||
|
|
||||||
|
document.title = `${siteName}${suffix}`
|
||||||
|
}, [publicConfigQuery.data?.site_name, pathname])
|
||||||
|
|
||||||
|
return null
|
||||||
|
}
|
||||||
@@ -1,8 +1,8 @@
|
|||||||
import * as React from "react"
|
import * as React from "react"
|
||||||
import { Slot } from "@radix-ui/react-slot"
|
import {Slot} from "@radix-ui/react-slot"
|
||||||
import { cva, type VariantProps } from "class-variance-authority"
|
import {cva, type VariantProps} from "class-variance-authority"
|
||||||
|
|
||||||
import { cn } from "@/lib/utils"
|
import {cn} from "@/lib/utils"
|
||||||
|
|
||||||
const buttonVariants = cva(
|
const buttonVariants = cva(
|
||||||
"cursor-pointer inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium transition-all disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg:not([class*='size-'])]:size-4 shrink-0 [&_svg]:shrink-0 outline-none focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px] aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive",
|
"cursor-pointer inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium transition-all disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg:not([class*='size-'])]:size-4 shrink-0 [&_svg]:shrink-0 outline-none focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px] aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive",
|
||||||
@@ -10,6 +10,7 @@ const buttonVariants = cva(
|
|||||||
variants: {
|
variants: {
|
||||||
variant: {
|
variant: {
|
||||||
default: "bg-primary text-primary-foreground hover:bg-primary/90",
|
default: "bg-primary text-primary-foreground hover:bg-primary/90",
|
||||||
|
auth: "bg-foreground text-background hover:bg-foreground/90",
|
||||||
destructive:
|
destructive:
|
||||||
"bg-destructive text-white hover:bg-destructive/90 focus-visible:ring-destructive/20 dark:focus-visible:ring-destructive/40 dark:bg-destructive/60",
|
"bg-destructive text-white hover:bg-destructive/90 focus-visible:ring-destructive/20 dark:focus-visible:ring-destructive/40 dark:bg-destructive/60",
|
||||||
outline:
|
outline:
|
||||||
|
|||||||
+1
-1
@@ -103,7 +103,7 @@ export function proxy(request: NextRequest) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* 页面请求:公共路由放行 */
|
/* 页面请求:公共路由放行 */
|
||||||
const publicRoutes = ['/', '/login', '/callback', '/privacy', '/terms']
|
const publicRoutes = ['/', '/login', '/register', '/callback', '/privacy', '/terms']
|
||||||
const publicPrefixes = ['/docs/', '/epay/']
|
const publicPrefixes = ['/docs/', '/epay/']
|
||||||
|
|
||||||
if (publicRoutes.includes(pathname) || publicPrefixes.some(p => pathname.startsWith(p))) {
|
if (publicRoutes.includes(pathname) || publicPrefixes.some(p => pathname.startsWith(p))) {
|
||||||
|
|||||||
+39
-39
@@ -5,43 +5,43 @@
|
|||||||
package user
|
package user
|
||||||
|
|
||||||
const (
|
const (
|
||||||
errBindParamsFailed = "参数绑定失败"
|
errBindParamsFailed = "参数绑定失败"
|
||||||
errInvalidParams = "无效的参数"
|
errInvalidParams = "无效的参数"
|
||||||
errPasswordLoginDisabled = "管理员关闭了密码登录" //nolint:gosec // false positive: this is an error message, not hardcoded credentials
|
errPasswordLoginDisabled = "管理员关闭了密码登录" //nolint:gosec // false positive: this is an error message, not hardcoded credentials
|
||||||
errUsernameOrPasswordWrong = "用户名或密码错误" //nolint:gosec // false positive: this is an error message, not hardcoded credentials
|
errUsernameOrPasswordWrong = "用户名或密码错误" //nolint:gosec // false positive: this is an error message, not hardcoded credentials
|
||||||
errLoginEmailMissing = "该账号未绑定邮箱,请联系管理员绑定邮箱后再登录"
|
errLoginEmailMissing = "该账号未绑定邮箱,请联系管理员绑定邮箱后再登录"
|
||||||
errNeedEmailCodePrefix = "need_email_code:"
|
errNeedEmailCodePrefix = "need_email_code:"
|
||||||
errSMTPInvalidUseTempCodePrefix = "smtp_invalid:"
|
errSMTPInvalidUseTempCodePrefix = "smtp_invalid:"
|
||||||
errSMTPInvalidUseTempCode = "smtp 配置无效,使用临时码登录"
|
errSMTPInvalidUseTempCode = "smtp 配置无效,使用临时码登录"
|
||||||
errEmailCodeInvalidOrExpired = "验证码错误或已过期"
|
errEmailCodeInvalidOrExpired = "验证码错误或已过期"
|
||||||
errSaveSessionFailed = "无法保存会话信息,请重试"
|
errSaveSessionFailed = "无法保存会话信息,请重试"
|
||||||
errRegistrationDisabled = "管理员关闭了注册"
|
errRegistrationDisabled = "管理员关闭了注册"
|
||||||
errPasswordTooShort = "密码长度不能少于 8 位" //nolint:gosec // false positive: this is an error message, not hardcoded credentials
|
errPasswordTooShort = "密码长度不能少于 8 位" //nolint:gosec // false positive: this is an error message, not hardcoded credentials
|
||||||
errEmailOrCodeRequired = "邮箱或验证码未填写"
|
errEmailOrCodeRequired = "邮箱或验证码未填写"
|
||||||
errNewPasswordTooShort = "新密码长度不能少于 8 位" //nolint:gosec // false positive: this is an error message, not hardcoded credentials
|
errNewPasswordTooShort = "新密码长度不能少于 8 位" //nolint:gosec // false positive: this is an error message, not hardcoded credentials
|
||||||
errLoginRequired = "请先登录"
|
errLoginRequired = "请先登录"
|
||||||
errUserNotFound = "未找到该用户"
|
errUserNotFound = "未找到该用户"
|
||||||
errOldPasswordIncorrect = "原密码不正确" //nolint:gosec // false positive: this is an error message, not hardcoded credentials
|
errOldPasswordIncorrect = "原密码不正确" //nolint:gosec // false positive: this is an error message, not hardcoded credentials
|
||||||
errPasswordEncryptFailed = "密码加密失败,请重试" //nolint:gosec // false positive: this is an error message, not hardcoded credentials
|
errPasswordEncryptFailed = "密码加密失败,请重试" //nolint:gosec // false positive: this is an error message, not hardcoded credentials
|
||||||
errEmailRequired = "邮箱地址不能为空"
|
errEmailRequired = "邮箱地址不能为空"
|
||||||
errUnsupportedEmailScene = "不支持的验证场景"
|
errUnsupportedEmailScene = "不支持的验证场景"
|
||||||
errEmailAlreadyRegistered = "该邮箱已被注册"
|
errEmailAlreadyRegistered = "该邮箱已被注册"
|
||||||
errEmailCodeCooldown = "验证码发送频繁,请稍后再试"
|
errEmailCodeCooldown = "验证码发送频繁,请稍后再试"
|
||||||
errEmailFormatInvalid = "邮箱格式不正确"
|
errEmailFormatInvalid = "邮箱格式不正确"
|
||||||
errEmailAlreadyBound = "该邮箱已被其他账号绑定"
|
errEmailAlreadyBound = "该邮箱已被其他账号绑定"
|
||||||
errRenderEmailTemplateFailed = "渲染验证邮件模板失败:%w"
|
errRenderEmailTemplateFailed = "渲染验证邮件模板失败:%w"
|
||||||
errGenerateEmailCodeFailed = "生成验证码失败,请重试"
|
errGenerateEmailCodeFailed = "生成验证码失败,请重试"
|
||||||
errDispatchEmailTaskFailed = "投递验证邮件发送任务失败,请重试"
|
errDispatchEmailTaskFailed = "投递验证邮件发送任务失败,请重试"
|
||||||
errTokenNameRequired = "令牌名称不能为空" //nolint:gosec // false positive: this is an error message, not hardcoded credentials
|
errTokenNameRequired = "令牌名称不能为空" //nolint:gosec // false positive: this is an error message, not hardcoded credentials
|
||||||
errAccessTokenLimitReached = "已达到访问令牌最大创建数量限制" //nolint:gosec // false positive: this is an error message, not hardcoded credentials
|
errAccessTokenLimitReached = "已达到访问令牌最大创建数量限制" //nolint:gosec // false positive: this is an error message, not hardcoded credentials
|
||||||
errGenerateTokenFailed = "生成令牌失败" //nolint:gosec // false positive: this is an error message, not hardcoded credentials
|
errGenerateTokenFailed = "生成令牌失败" //nolint:gosec // false positive: this is an error message, not hardcoded credentials
|
||||||
errInvalidTokenID = "无效的令牌ID" //nolint:gosec // false positive: this is an error message, not hardcoded credentials
|
errInvalidTokenID = "无效的令牌ID" //nolint:gosec // false positive: this is an error message, not hardcoded credentials
|
||||||
errTokenNotFoundOrForbidden = "令牌不存在或无权操作" //nolint:gosec // false positive: this is an error message, not hardcoded credentials
|
errTokenNotFoundOrForbidden = "令牌不存在或无权操作" //nolint:gosec // false positive: this is an error message, not hardcoded credentials
|
||||||
errAdminTokenRequiresAdmin = "只有管理员才能创建具有管理员权限的令牌" //nolint:gosec // false positive: this is an error message, not hardcoded credentials
|
errAdminTokenRequiresAdmin = "只有管理员才能创建具有管理员权限的令牌" //nolint:gosec // false positive: this is an error message, not hardcoded credentials
|
||||||
errTaskPayloadRequired = "任务参数不能为空"
|
errTaskPayloadRequired = "任务参数不能为空"
|
||||||
errInvalidJSONFormat = "无效的 JSON 格式: %w"
|
errInvalidJSONFormat = "无效的 JSON 格式: %w"
|
||||||
errEmailTaskFieldsRequired = "to、subject、body 不能为空"
|
errEmailTaskFieldsRequired = "to、subject、body 不能为空"
|
||||||
errParseEmailPayloadFailed = "解析邮件发送参数失败: %w"
|
errParseEmailPayloadFailed = "解析邮件发送参数失败: %w"
|
||||||
errSMTPConfigIncomplete = "系统 SMTP 邮件服务配置不完整"
|
errSMTPConfigIncomplete = "系统 SMTP 邮件服务配置不完整"
|
||||||
errSendMailFailed = "发送邮件失败: %w"
|
errSendMailFailed = "发送邮件失败: %w"
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user