merge: 同步 upstream/main 新功能到定制版本
- feat: Add slider verification code (bd67997) - fix bug: Inventory cannot be zero (1f7a6ee) - fix: resolve merge conflicts and lint errors
This commit is contained in:
@@ -16,10 +16,11 @@ import { useForm } from "react-hook-form";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { z } from "zod";
|
||||
import { useGlobalStore } from "@/stores/global";
|
||||
import LocalCaptcha, { type LocalCaptchaRef } from "../local-captcha";
|
||||
import SendCode from "../send-code";
|
||||
import SliderCaptcha, { type SliderCaptchaRef } from "../slider-captcha";
|
||||
import type { TurnstileRef } from "../turnstile";
|
||||
import CloudFlareTurnstile from "../turnstile";
|
||||
import LocalCaptcha, { type LocalCaptchaRef } from "../local-captcha";
|
||||
|
||||
export default function RegisterForm({
|
||||
loading,
|
||||
@@ -41,6 +42,7 @@ export default function RegisterForm({
|
||||
|
||||
const isTurnstile = verify.captcha_type === "turnstile";
|
||||
const isLocal = verify.captcha_type === "local";
|
||||
const isSlider = verify.captcha_type === "slider";
|
||||
const captchaEnabled = verify.enable_user_register_captcha;
|
||||
|
||||
const handleCheckUser = async (email: string) => {
|
||||
@@ -78,8 +80,16 @@ export default function RegisterForm({
|
||||
: z.string().nullish(),
|
||||
captcha_code:
|
||||
captchaEnabled && isLocal
|
||||
? z.string().min(1, t("captcha.required", "Please enter captcha code"))
|
||||
? z
|
||||
.string()
|
||||
.min(1, t("captcha.required", "Please enter captcha code"))
|
||||
: z.string().nullish(),
|
||||
slider_token:
|
||||
captchaEnabled && isSlider
|
||||
? z
|
||||
.string()
|
||||
.min(1, t("captcha.sliderRequired", "Please complete the slider"))
|
||||
: z.string().optional(),
|
||||
})
|
||||
.superRefine(({ password, repeat_password }, ctx) => {
|
||||
if (password !== repeat_password) {
|
||||
@@ -94,6 +104,9 @@ export default function RegisterForm({
|
||||
const form = useForm<z.infer<typeof formSchema>>({
|
||||
resolver: zodResolver(formSchema),
|
||||
defaultValues: {
|
||||
cf_token: "",
|
||||
captcha_code: "",
|
||||
slider_token: "",
|
||||
...initialValues,
|
||||
invite: localStorage.getItem("invite") || "",
|
||||
},
|
||||
@@ -101,6 +114,7 @@ export default function RegisterForm({
|
||||
|
||||
const turnstile = useRef<TurnstileRef>(null);
|
||||
const localCaptcha = useRef<LocalCaptchaRef>(null);
|
||||
const sliderCaptcha = useRef<SliderCaptchaRef>(null);
|
||||
const handleSubmit = form.handleSubmit((data) => {
|
||||
try {
|
||||
// Add captcha_id for local captcha
|
||||
@@ -111,6 +125,7 @@ export default function RegisterForm({
|
||||
} catch (_error) {
|
||||
turnstile.current?.reset();
|
||||
localCaptcha.current?.reset();
|
||||
sliderCaptcha.current?.reset();
|
||||
}
|
||||
});
|
||||
|
||||
@@ -130,7 +145,10 @@ export default function RegisterForm({
|
||||
<FormItem>
|
||||
<FormControl>
|
||||
<Input
|
||||
placeholder={t("register.emailPlaceholder", "Enter your email...")}
|
||||
placeholder={t(
|
||||
"register.emailPlaceholder",
|
||||
"Enter your email..."
|
||||
)}
|
||||
type="email"
|
||||
{...field}
|
||||
/>
|
||||
@@ -146,7 +164,10 @@ export default function RegisterForm({
|
||||
<FormItem>
|
||||
<FormControl>
|
||||
<Input
|
||||
placeholder={t("register.passwordPlaceholder", "Enter your password...")}
|
||||
placeholder={t(
|
||||
"register.passwordPlaceholder",
|
||||
"Enter your password..."
|
||||
)}
|
||||
type="password"
|
||||
{...field}
|
||||
/>
|
||||
@@ -163,7 +184,10 @@ export default function RegisterForm({
|
||||
<FormControl>
|
||||
<Input
|
||||
disabled={loading}
|
||||
placeholder={t("register.repeatPasswordPlaceholder", "Enter password again...")}
|
||||
placeholder={t(
|
||||
"register.repeatPasswordPlaceholder",
|
||||
"Enter password again..."
|
||||
)}
|
||||
type="password"
|
||||
{...field}
|
||||
/>
|
||||
@@ -182,7 +206,10 @@ export default function RegisterForm({
|
||||
<div className="flex items-center gap-2">
|
||||
<Input
|
||||
disabled={loading}
|
||||
placeholder={t("register.codePlaceholder", "Enter code...")}
|
||||
placeholder={t(
|
||||
"register.codePlaceholder",
|
||||
"Enter code..."
|
||||
)}
|
||||
type="text"
|
||||
{...field}
|
||||
value={field.value as string}
|
||||
@@ -248,8 +275,8 @@ export default function RegisterForm({
|
||||
<FormControl>
|
||||
<LocalCaptcha
|
||||
{...field}
|
||||
ref={localCaptcha}
|
||||
onCaptchaIdChange={setCaptchaId}
|
||||
ref={localCaptcha}
|
||||
/>
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
@@ -257,6 +284,20 @@ export default function RegisterForm({
|
||||
)}
|
||||
/>
|
||||
)}
|
||||
{captchaEnabled && isSlider && (
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="slider_token"
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormControl>
|
||||
<SliderCaptcha {...field} ref={sliderCaptcha} />
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
)}
|
||||
<Button disabled={loading} type="submit">
|
||||
{loading && <Icon className="animate-spin" icon="mdi:loading" />}
|
||||
{t("register.title", "Register")}
|
||||
|
||||
Reference in New Issue
Block a user