feat: remove confirmPassword

This commit is contained in:
fantasticit 2022-06-29 00:04:22 +08:00
parent bf0826b220
commit fb6fdfffb5
5 changed files with 20 additions and 20 deletions

View File

@ -0,0 +1,7 @@
export const isEmail = (email) => {
return !!String(email)
.toLowerCase()
.match(
/^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/
);
};

View File

@ -9,6 +9,7 @@
position: relative;
z-index: 10;
display: flex;
height: calc(100% - 52px);
padding: 10vh 24px;
flex: 1;
flex-direction: column;

View File

@ -3,11 +3,13 @@ import { Author } from 'components/author';
import { LogoImage, LogoText } from 'components/logo';
import { Seo } from 'components/seo';
import { useRegister, useVerifyCode } from 'data/user';
import { isEmail } from 'helpers/validator';
import { useInterval } from 'hooks/use-interval';
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';
@ -25,7 +27,13 @@ const Page = () => {
const { sendVerifyCode, loading: sendVerifyCodeLoading } = useVerifyCode();
const onFormChange = useCallback((formState) => {
setEmail(formState.values.email);
const email = formState.values.email;
if (isEmail(email)) {
setEmail(email);
} else {
setEmail(null);
}
}, []);
const { start, stop } = useInterval(() => {
@ -89,6 +97,7 @@ const Page = () => {
<Title type="tertiary" heading={5} style={{ marginBottom: 16, textAlign: 'center' }}>
</Title>
<Form.Input
noLabel
field="name"
@ -97,6 +106,7 @@ const Page = () => {
placeholder="输入账户名称"
rules={[{ required: true, message: '请输入账户' }]}
></Form.Input>
<Form.Input
noLabel
mode="password"
@ -106,15 +116,6 @@ const Page = () => {
placeholder="输入用户密码"
rules={[{ required: true, message: '请输入密码' }]}
></Form.Input>
<Form.Input
noLabel
mode="password"
field="confirmPassword"
label="密码"
style={{ width: '100%' }}
placeholder="确认用户密码"
rules={[{ required: true, message: '请再次输入密码' }]}
></Form.Input>
<Form.Input
noLabel

View File

@ -1,4 +1,4 @@
import { IsEmail, IsNotEmpty, IsOptional, IsString, MaxLength, MinLength } from 'class-validator';
import { IsEmail, IsNotEmpty, IsString, MaxLength, MinLength } from 'class-validator';
/**
*
@ -15,11 +15,6 @@ export class RegisterUserDto {
@IsNotEmpty({ message: '用户密码不能为空' })
password: string;
@MinLength(5, { message: '用户二次确认密码至少5个字符' })
@IsString({ message: '用户二次确认密码类型错误正确类型为String' })
@IsNotEmpty({ message: '用户二次确认密码不能为空' })
confirmPassword: string;
@IsEmail({ message: '请输入正确的邮箱地址' })
@IsString({ message: '用户邮箱类型错误正确类型为String' })
@IsNotEmpty({ message: '用户邮箱不能为空' })

View File

@ -125,10 +125,6 @@ export class UserService {
throw new HttpException('该账户已被注册', HttpStatus.BAD_REQUEST);
}
if (user.password !== user.confirmPassword) {
throw new HttpException('两次密码不一致,请重试', HttpStatus.BAD_REQUEST);
}
if (await this.userRepo.findOne({ name: user.name })) {
throw new HttpException('该账户已被注册', HttpStatus.BAD_REQUEST);
}