From d96c63e008e485131b745258ec0d112084421628 Mon Sep 17 00:00:00 2001 From: fantasticit Date: Wed, 17 Aug 2022 18:10:46 +0800 Subject: [PATCH] feat: use system config enableEmailVerify with user regitser, reset password --- .../admin/system-config/system/index.tsx | 2 +- .../components/user/reset-password/index.tsx | 37 ++++++++++--------- .../client/src/pages/forgetPassword/index.tsx | 2 +- packages/client/src/pages/register/index.tsx | 1 - packages/server/src/dtos/create-user.dto.ts | 2 +- packages/server/src/entities/system.entity.ts | 2 +- packages/server/src/services/user.service.ts | 8 +++- 7 files changed, 30 insertions(+), 24 deletions(-) diff --git a/packages/client/src/components/admin/system-config/system/index.tsx b/packages/client/src/components/admin/system-config/system/index.tsx index dd1d4005..0e66888e 100644 --- a/packages/client/src/components/admin/system-config/system/index.tsx +++ b/packages/client/src/components/admin/system-config/system/index.tsx @@ -45,7 +45,7 @@ export const System = () => { label={{ text: '邮箱检验', extra: ( - + ), diff --git a/packages/client/src/components/user/reset-password/index.tsx b/packages/client/src/components/user/reset-password/index.tsx index 49ea2013..7eeeeab4 100644 --- a/packages/client/src/components/user/reset-password/index.tsx +++ b/packages/client/src/components/user/reset-password/index.tsx @@ -1,5 +1,5 @@ import { Button, Col, Form, Row, Toast, Typography } from '@douyinfe/semi-ui'; -import { useResetPassword, useVerifyCode } from 'data/user'; +import { useResetPassword, useSystemPublicConfig, useVerifyCode } from 'data/user'; import { useInterval } from 'hooks/use-interval'; import { useToggle } from 'hooks/use-toggle'; import React, { useCallback, useState } from 'react'; @@ -9,6 +9,7 @@ export const ResetPassword = ({ onSuccess }) => { const [hasSendVerifyCode, toggleHasSendVerifyCode] = useToggle(false); const [countDown, setCountDown] = useState(0); const { reset, loading } = useResetPassword(); + const { data: systemConfig } = useSystemPublicConfig(); const { sendVerifyCode, loading: sendVerifyCodeLoading } = useVerifyCode(); const onFormChange = useCallback((formState) => { @@ -67,22 +68,24 @@ export const ResetPassword = ({ onSuccess }) => { ]} /> - - - - - - - - + {systemConfig && systemConfig.enableEmailVerify ? ( + + + + + + + + + ) : null} { + const currentSystemConfig = await this.systemService.getConfigFromDatabase(); const oldData = await this.userRepo.findOne(user.id); if (oldData.email !== dto.email) { @@ -257,7 +258,10 @@ export class UserService { throw new HttpException('该邮箱已被注册', HttpStatus.BAD_REQUEST); } - if (!(await this.verifyService.checkVerifyCode(dto.email, dto.verifyCode))) { + if ( + currentSystemConfig.enableEmailVerify && + !(await this.verifyService.checkVerifyCode(dto.email, dto.verifyCode)) + ) { throw new HttpException('验证码不正确,请检查', HttpStatus.BAD_REQUEST); } }