feat: use system config enableEmailVerify with user regitser, reset password

This commit is contained in:
fantasticit 2022-08-17 18:10:46 +08:00
parent b5e2bea519
commit d96c63e008
7 changed files with 30 additions and 24 deletions

View File

@ -45,7 +45,7 @@ export const System = () => {
label={{
text: '邮箱检验',
extra: (
<Tooltip content="开启邮箱检验后,新注册用户必须通过邮箱验证">
<Tooltip content="开启邮箱检验后,用户注册、密码等操作必须通过邮箱验证">
<IconHelpCircle style={{ color: '--semi-color-text-1' }} />
</Tooltip>
),

View File

@ -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,6 +68,7 @@ export const ResetPassword = ({ onSuccess }) => {
]}
/>
{systemConfig && systemConfig.enableEmailVerify ? (
<Row gutter={8} style={{ paddingTop: 12 }}>
<Col span={16}>
<Form.Input
@ -83,6 +85,7 @@ export const ResetPassword = ({ onSuccess }) => {
</Button>
</Col>
</Row>
) : null}
<Form.Input
noLabel

View File

@ -6,7 +6,7 @@ import { ResetPassword } from 'components/user/reset-password';
import { useRouterQuery } from 'hooks/use-router-query';
import Link from 'next/link';
import Router from 'next/router';
import React, { useCallback, useState } from 'react';
import React, { useCallback } from 'react';
import styles from './index.module.scss';

View File

@ -9,7 +9,6 @@ import { useRouterQuery } from 'hooks/use-router-query';
import { useToggle } from 'hooks/use-toggle';
import Link from 'next/link';
import Router from 'next/router';
import { emit } from 'process';
import React, { useCallback, useState } from 'react';
import styles from './index.module.scss';

View File

@ -4,7 +4,7 @@ import { IsEmail, IsNotEmpty, IsOptional, IsString, MinLength } from 'class-vali
*
*/
export class RegisterUserDto {
@MinLength(5, { message: '用户账号至少5个字符' })
@MinLength(1, { message: '用户账号至少1个字符' })
@IsString({ message: '用户名称类型错误正确类型为String' })
@IsNotEmpty({ message: '用户账号不能为空' })
name: string;

View File

@ -12,7 +12,7 @@ export class SystemEntity {
isSystemLocked: boolean;
/**
*
*
*/
@Column({ type: 'boolean', default: false, comment: '是否启用邮箱校验' })
enableEmailVerify: boolean;

View File

@ -185,7 +185,7 @@ export class UserService {
throw new HttpException('两次密码不一致,请重试', HttpStatus.BAD_REQUEST);
}
if (!(await this.verifyService.checkVerifyCode(email, verifyCode))) {
if (currentSystemConfig.enableEmailVerify && !(await this.verifyService.checkVerifyCode(email, verifyCode))) {
throw new HttpException('验证码不正确,请检查', HttpStatus.BAD_REQUEST);
}
@ -250,6 +250,7 @@ export class UserService {
* @returns
*/
async updateUser(user: UserEntity, dto: UpdateUserDto): Promise<IUser> {
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);
}
}