Skip to content

Commit

Permalink
fix: whether captcha is enabled is determined by pltcfg
Browse files Browse the repository at this point in the history
  • Loading branch information
ElaBosak233 committed Jun 2, 2024
1 parent 47561c3 commit 9b44b2b
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 21 deletions.
1 change: 0 additions & 1 deletion internal/extension/files/configs/application.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@
}
},
"captcha": {
"enabled": false,
"provider": "turnstile",
"turnstile": {
"url": "https://challenges.cloudflare.com/turnstile/v0/siteverify",
Expand Down
2 changes: 1 addition & 1 deletion internal/service/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func (t *UserService) Create(req request.UserCreateRequest) (err error) {
func (t *UserService) Register(req request.UserRegisterRequest) (err error) {
hashedPassword, _ := bcrypt.GenerateFromPassword([]byte(req.Password), bcrypt.DefaultCost)
success := true
if config.AppCfg().Captcha.Enabled {
if config.PltCfg().User.Register.Captcha.Enabled {
capt := captcha.NewCaptcha()
success, err = capt.Verify(req.CaptchaToken, req.RemoteIP)
}
Expand Down
32 changes: 17 additions & 15 deletions web/src/pages/login.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -130,26 +130,28 @@ export default function Page() {
登录
</Button>
</form>
<Box
sx={{
display: "flex",
marginTop: "1rem",
justifyContent: "end",
}}
>
没有帐号?
{configStore?.pltCfg?.user?.register?.enabled && (
<Box
onClick={() => navigate("/register")}
sx={{
fontStyle: "italic",
":hover": {
cursor: "pointer",
},
display: "flex",
marginTop: "1rem",
justifyContent: "end",
}}
>
注册
没有帐号?
<Box
onClick={() => navigate("/register")}
sx={{
fontStyle: "italic",
":hover": {
cursor: "pointer",
},
}}
>
注册
</Box>
</Box>
</Box>
)}
</Box>
</Box>
</>
Expand Down
7 changes: 3 additions & 4 deletions web/src/pages/register.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
showErrNotification,
showSuccessNotification,
} from "@/utils/notification";
import Turnstile, { useTurnstile } from "react-turnstile";
import Turnstile from "react-turnstile";
import ReCAPTCHA from "react-google-recaptcha";

export default function Page() {
Expand All @@ -20,8 +20,6 @@ export default function Page() {
const userApi = useUserApi();
const authStore = useAuthStore();

const turnstile = useTurnstile();

useEffect(() => {
document.title = `注册 - ${configStore?.pltCfg?.site?.title}`;
}, []);
Expand Down Expand Up @@ -143,7 +141,8 @@ export default function Page() {
{...form.getInputProps("password")}
/>
<Flex justify={"center"}>
{configStore?.captchaCfg?.enabled && (
{configStore?.pltCfg?.user?.register?.captcha
?.enabled && (
<>
{configStore?.captchaCfg?.provider ===
"turnstile" && (
Expand Down

0 comments on commit 9b44b2b

Please sign in to comment.