mirror of
https://github.com/labring/FastGPT.git
synced 2025-07-27 16:33:49 +00:00
feat: 限流配置
This commit is contained in:
3
.gitignore
vendored
3
.gitignore
vendored
@@ -35,4 +35,5 @@ yarn-error.log*
|
|||||||
*.tsbuildinfo
|
*.tsbuildinfo
|
||||||
next-env.d.ts
|
next-env.d.ts
|
||||||
public/trainData/
|
public/trainData/
|
||||||
.vscode/
|
.vscode/
|
||||||
|
platform.json
|
@@ -55,5 +55,12 @@ USER nextjs
|
|||||||
EXPOSE 3000
|
EXPOSE 3000
|
||||||
|
|
||||||
ENV PORT 3000
|
ENV PORT 3000
|
||||||
|
ENV MAX_USER ''
|
||||||
|
ENV AXIOS_PROXY_HOST ''
|
||||||
|
ENV AXIOS_PROXY_PORT ''
|
||||||
|
ENV MONGODB_UR ''
|
||||||
|
ENV MY_MAIL ''
|
||||||
|
ENV MAILE_CODE ''
|
||||||
|
ENV TOKEN_KEY ''
|
||||||
|
|
||||||
CMD ["node", "server.js"]
|
CMD ["node", "server.js"]
|
||||||
|
@@ -2,13 +2,13 @@
|
|||||||
import type { NextApiRequest, NextApiResponse } from 'next';
|
import type { NextApiRequest, NextApiResponse } from 'next';
|
||||||
import { jsonRes } from '@/service/response';
|
import { jsonRes } from '@/service/response';
|
||||||
import { AuthCode } from '@/service/models/authCode';
|
import { AuthCode } from '@/service/models/authCode';
|
||||||
import { connectToDatabase } from '@/service/mongo';
|
import { connectToDatabase, User } from '@/service/mongo';
|
||||||
import { sendCode } from '@/service/utils/sendEmail';
|
import { sendCode } from '@/service/utils/sendEmail';
|
||||||
import { EmailTypeEnum } from '@/constants/common';
|
import { EmailTypeEnum } from '@/constants/common';
|
||||||
|
|
||||||
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
|
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
|
||||||
try {
|
try {
|
||||||
const { email, type } = req.query;
|
const { email, type } = req.query as { email: string; type: `${EmailTypeEnum}` };
|
||||||
|
|
||||||
if (!email || !type) {
|
if (!email || !type) {
|
||||||
throw new Error('缺少参数');
|
throw new Error('缺少参数');
|
||||||
@@ -16,6 +16,16 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
|
|||||||
|
|
||||||
await connectToDatabase();
|
await connectToDatabase();
|
||||||
|
|
||||||
|
// 注册人数限流
|
||||||
|
if (type === EmailTypeEnum.register) {
|
||||||
|
const maxCount = process.env.MAX_USER ? +process.env.MAX_USER : Infinity;
|
||||||
|
const userCount = await User.count();
|
||||||
|
|
||||||
|
if (userCount >= maxCount) {
|
||||||
|
throw new Error('当前注册用户已满,请等待名额~');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let code = '';
|
let code = '';
|
||||||
for (let i = 0; i < 6; i++) {
|
for (let i = 0; i < 6; i++) {
|
||||||
code += Math.floor(Math.random() * 10);
|
code += Math.floor(Math.random() * 10);
|
||||||
|
@@ -1,19 +1,12 @@
|
|||||||
import React, { useState, Dispatch, useCallback } from 'react';
|
import React, { useState, Dispatch, useCallback } from 'react';
|
||||||
import {
|
import { FormControl, Box, Input, Button, FormErrorMessage, Flex } from '@chakra-ui/react';
|
||||||
FormControl,
|
|
||||||
Box,
|
|
||||||
Input,
|
|
||||||
Button,
|
|
||||||
FormErrorMessage,
|
|
||||||
useToast,
|
|
||||||
Flex
|
|
||||||
} from '@chakra-ui/react';
|
|
||||||
import { useForm } from 'react-hook-form';
|
import { useForm } from 'react-hook-form';
|
||||||
import { PageTypeEnum } from '@/constants/user';
|
import { PageTypeEnum } from '@/constants/user';
|
||||||
import { postRegister } from '@/api/user';
|
import { postRegister } from '@/api/user';
|
||||||
import { useSendCode } from '@/hooks/useSendCode';
|
import { useSendCode } from '@/hooks/useSendCode';
|
||||||
import type { ResLogin } from '@/api/response/user';
|
import type { ResLogin } from '@/api/response/user';
|
||||||
import { useScreen } from '@/hooks/useScreen';
|
import { useScreen } from '@/hooks/useScreen';
|
||||||
|
import { useToast } from '@/hooks/useToast';
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
loginSuccess: (e: ResLogin) => void;
|
loginSuccess: (e: ResLogin) => void;
|
||||||
@@ -28,7 +21,7 @@ interface RegisterType {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const RegisterForm = ({ setPageType, loginSuccess }: Props) => {
|
const RegisterForm = ({ setPageType, loginSuccess }: Props) => {
|
||||||
const toast = useToast();
|
const { toast } = useToast();
|
||||||
const { mediaLgMd } = useScreen();
|
const { mediaLgMd } = useScreen();
|
||||||
const {
|
const {
|
||||||
register,
|
register,
|
||||||
@@ -66,15 +59,15 @@ const RegisterForm = ({ setPageType, loginSuccess }: Props) => {
|
|||||||
);
|
);
|
||||||
toast({
|
toast({
|
||||||
title: `注册成功`,
|
title: `注册成功`,
|
||||||
status: 'success',
|
status: 'success'
|
||||||
position: 'top'
|
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
typeof error === 'string' &&
|
typeof error === 'string' &&
|
||||||
toast({
|
toast({
|
||||||
title: error,
|
title: error,
|
||||||
status: 'error',
|
status: 'error',
|
||||||
position: 'top'
|
duration: 4000,
|
||||||
|
isClosable: true
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
setRequesting(false);
|
setRequesting(false);
|
||||||
|
Reference in New Issue
Block a user