Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
赵月辉
/
fastgpt-migrated
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Unverified
Commit
03f1ab1a
authored
Apr 16, 2023
by
archer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: 邀请注册
parent
faf722fa
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
35 additions
and
5 deletions
+35
-5
src/api/user.ts
+4
-1
src/pages/api/user/register.ts
+3
-2
src/pages/login/components/RegisterForm.tsx
+5
-2
src/service/models/user.ts
+21
-0
src/types/mongoSchema.d.ts
+2
-0
No files found.
src/api/user.ts
View file @
03f1ab1a
...
@@ -20,15 +20,18 @@ export const getTokenLogin = () => GET<UserType>('/user/tokenLogin');
...
@@ -20,15 +20,18 @@ export const getTokenLogin = () => GET<UserType>('/user/tokenLogin');
export
const
postRegister
=
({
export
const
postRegister
=
({
phone
,
phone
,
password
,
password
,
code
code
,
inviterId
}:
{
}:
{
phone
:
string
;
phone
:
string
;
code
:
string
;
code
:
string
;
password
:
string
;
password
:
string
;
inviterId
:
string
;
})
=>
})
=>
POST
<
ResLogin
>
(
'/user/register'
,
{
POST
<
ResLogin
>
(
'/user/register'
,
{
phone
,
phone
,
code
,
code
,
inviterId
,
password
:
createHashPassword
(
password
)
password
:
createHashPassword
(
password
)
});
});
...
...
src/pages/api/user/register.ts
View file @
03f1ab1a
...
@@ -9,7 +9,7 @@ import { UserAuthTypeEnum } from '@/constants/common';
...
@@ -9,7 +9,7 @@ import { UserAuthTypeEnum } from '@/constants/common';
export
default
async
function
handler
(
req
:
NextApiRequest
,
res
:
NextApiResponse
<
any
>
)
{
export
default
async
function
handler
(
req
:
NextApiRequest
,
res
:
NextApiResponse
<
any
>
)
{
try
{
try
{
const
{
phone
,
code
,
password
}
=
req
.
body
;
const
{
phone
,
code
,
password
,
inviterId
}
=
req
.
body
;
if
(
!
phone
||
!
code
||
!
password
)
{
if
(
!
phone
||
!
code
||
!
password
)
{
throw
new
Error
(
'缺少参数'
);
throw
new
Error
(
'缺少参数'
);
...
@@ -46,7 +46,8 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse<
...
@@ -46,7 +46,8 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse<
const
response
=
await
User
.
create
({
const
response
=
await
User
.
create
({
username
:
phone
,
username
:
phone
,
password
password
,
inviterId
});
});
// 根据 id 获取用户信息
// 根据 id 获取用户信息
...
...
src/pages/login/components/RegisterForm.tsx
View file @
03f1ab1a
...
@@ -7,6 +7,7 @@ import { useSendCode } from '@/hooks/useSendCode';
...
@@ -7,6 +7,7 @@ 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'
;
import
{
useToast
}
from
'@/hooks/useToast'
;
import
{
useRouter
}
from
'next/router'
;
interface
Props
{
interface
Props
{
loginSuccess
:
(
e
:
ResLogin
)
=>
void
;
loginSuccess
:
(
e
:
ResLogin
)
=>
void
;
...
@@ -21,6 +22,7 @@ interface RegisterType {
...
@@ -21,6 +22,7 @@ interface RegisterType {
}
}
const
RegisterForm
=
({
setPageType
,
loginSuccess
}:
Props
)
=>
{
const
RegisterForm
=
({
setPageType
,
loginSuccess
}:
Props
)
=>
{
const
{
inviterId
=
''
}
=
useRouter
().
query
as
{
inviterId
:
string
};
const
{
toast
}
=
useToast
();
const
{
toast
}
=
useToast
();
const
{
mediaLgMd
}
=
useScreen
();
const
{
mediaLgMd
}
=
useScreen
();
const
{
const
{
...
@@ -54,7 +56,8 @@ const RegisterForm = ({ setPageType, loginSuccess }: Props) => {
...
@@ -54,7 +56,8 @@ const RegisterForm = ({ setPageType, loginSuccess }: Props) => {
await
postRegister
({
await
postRegister
({
phone
,
phone
,
code
,
code
,
password
password
,
inviterId
})
})
);
);
toast
({
toast
({
...
@@ -69,7 +72,7 @@ const RegisterForm = ({ setPageType, loginSuccess }: Props) => {
...
@@ -69,7 +72,7 @@ const RegisterForm = ({ setPageType, loginSuccess }: Props) => {
}
}
setRequesting
(
false
);
setRequesting
(
false
);
},
},
[
loginSuccess
,
toast
]
[
inviterId
,
loginSuccess
,
toast
]
);
);
return
(
return
(
...
...
src/service/models/user.ts
View file @
03f1ab1a
...
@@ -3,6 +3,9 @@ import { hashPassword } from '@/service/utils/tools';
...
@@ -3,6 +3,9 @@ import { hashPassword } from '@/service/utils/tools';
import
{
PRICE_SCALE
}
from
'@/constants/common'
;
import
{
PRICE_SCALE
}
from
'@/constants/common'
;
import
{
UserModelSchema
}
from
'@/types/mongoSchema'
;
import
{
UserModelSchema
}
from
'@/types/mongoSchema'
;
const
UserSchema
=
new
Schema
({
const
UserSchema
=
new
Schema
({
email
:
{
type
:
String
},
username
:
{
username
:
{
// 可以是手机/邮箱,新的验证都只用手机
// 可以是手机/邮箱,新的验证都只用手机
type
:
String
,
type
:
String
,
...
@@ -17,9 +20,27 @@ const UserSchema = new Schema({
...
@@ -17,9 +20,27 @@ const UserSchema = new Schema({
select
:
false
select
:
false
},
},
balance
:
{
balance
:
{
// 平台余额,不可提现
type
:
Number
,
type
:
Number
,
default
:
0.5
*
PRICE_SCALE
default
:
0.5
*
PRICE_SCALE
},
},
inviterId
:
{
// 谁邀请注册的
type
:
Schema
.
Types
.
ObjectId
,
ref
:
'user'
},
promotion
:
{
rate
:
{
// 返现比例
type
:
Number
,
default
:
15
},
amount
:
{
// 推广金额
type
:
Number
,
default
:
0
}
},
openaiKey
:
{
openaiKey
:
{
type
:
String
,
type
:
String
,
default
:
''
default
:
''
...
...
src/types/mongoSchema.d.ts
View file @
03f1ab1a
...
@@ -14,6 +14,8 @@ export interface UserModelSchema {
...
@@ -14,6 +14,8 @@ export interface UserModelSchema {
username
:
string
;
username
:
string
;
password
:
string
;
password
:
string
;
balance
:
number
;
balance
:
number
;
inviterId
?:
string
;
promotionAmount
:
number
;
openaiKey
:
string
;
openaiKey
:
string
;
createTime
:
number
;
createTime
:
number
;
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment