mirror of https://github.com/fantasticit/think.git
Merge pull request #171 from fantasticit/feat/emial-validation
commit
1c9753b57d
|
@ -45,7 +45,7 @@ export const System = () => {
|
|||
label={{
|
||||
text: '邮箱检验',
|
||||
extra: (
|
||||
<Tooltip content="开启邮箱检验后,新注册用户必须通过邮箱验证">
|
||||
<Tooltip content="开启邮箱检验后,用户注册、密码等操作必须通过邮箱验证">
|
||||
<IconHelpCircle style={{ color: '--semi-color-text-1' }} />
|
||||
</Tooltip>
|
||||
),
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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';
|
||||
|
||||
|
|
|
@ -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';
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -12,7 +12,7 @@ export class SystemEntity {
|
|||
isSystemLocked: boolean;
|
||||
|
||||
/**
|
||||
* 启用邮箱校验后,必须通过邮箱验证码验证后注册
|
||||
* 启用邮箱校验后,注册、重置密码等操作必须经过邮箱验证
|
||||
*/
|
||||
@Column({ type: 'boolean', default: false, comment: '是否启用邮箱校验' })
|
||||
enableEmailVerify: boolean;
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue