feat: 邀请注册

This commit is contained in:
archer
2023-04-16 23:26:14 +08:00
parent faf722fa15
commit 03f1ab1a2f
5 changed files with 35 additions and 5 deletions

View File

@@ -20,15 +20,18 @@ export const getTokenLogin = () => GET<UserType>('/user/tokenLogin');
export const postRegister = ({
phone,
password,
code
code,
inviterId
}: {
phone: string;
code: string;
password: string;
inviterId: string;
}) =>
POST<ResLogin>('/user/register', {
phone,
code,
inviterId,
password: createHashPassword(password)
});

View File

@@ -9,7 +9,7 @@ import { UserAuthTypeEnum } from '@/constants/common';
export default async function handler(req: NextApiRequest, res: NextApiResponse<any>) {
try {
const { phone, code, password } = req.body;
const { phone, code, password, inviterId } = req.body;
if (!phone || !code || !password) {
throw new Error('缺少参数');
@@ -46,7 +46,8 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse<
const response = await User.create({
username: phone,
password
password,
inviterId
});
// 根据 id 获取用户信息

View File

@@ -7,6 +7,7 @@ import { useSendCode } from '@/hooks/useSendCode';
import type { ResLogin } from '@/api/response/user';
import { useScreen } from '@/hooks/useScreen';
import { useToast } from '@/hooks/useToast';
import { useRouter } from 'next/router';
interface Props {
loginSuccess: (e: ResLogin) => void;
@@ -21,6 +22,7 @@ interface RegisterType {
}
const RegisterForm = ({ setPageType, loginSuccess }: Props) => {
const { inviterId = '' } = useRouter().query as { inviterId: string };
const { toast } = useToast();
const { mediaLgMd } = useScreen();
const {
@@ -54,7 +56,8 @@ const RegisterForm = ({ setPageType, loginSuccess }: Props) => {
await postRegister({
phone,
code,
password
password,
inviterId
})
);
toast({
@@ -69,7 +72,7 @@ const RegisterForm = ({ setPageType, loginSuccess }: Props) => {
}
setRequesting(false);
},
[loginSuccess, toast]
[inviterId, loginSuccess, toast]
);
return (

View File

@@ -3,6 +3,9 @@ import { hashPassword } from '@/service/utils/tools';
import { PRICE_SCALE } from '@/constants/common';
import { UserModelSchema } from '@/types/mongoSchema';
const UserSchema = new Schema({
email: {
type: String
},
username: {
// 可以是手机/邮箱,新的验证都只用手机
type: String,
@@ -17,9 +20,27 @@ const UserSchema = new Schema({
select: false
},
balance: {
// 平台余额,不可提现
type: Number,
default: 0.5 * PRICE_SCALE
},
inviterId: {
// 谁邀请注册的
type: Schema.Types.ObjectId,
ref: 'user'
},
promotion: {
rate: {
// 返现比例
type: Number,
default: 15
},
amount: {
// 推广金额
type: Number,
default: 0
}
},
openaiKey: {
type: String,
default: ''

View File

@@ -14,6 +14,8 @@ export interface UserModelSchema {
username: string;
password: string;
balance: number;
inviterId?: string;
promotionAmount: number;
openaiKey: string;
createTime: number;
}