Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
phsl
/
new-api
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
Commit
05f35fd0
authored
Sep 24, 2024
by
1808837298@qq.com
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: 不自动生成系统访问令牌
parent
a50d2e68
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
15 additions
and
4 deletions
+15
-4
controller/user.go
+1
-1
model/main.go
+1
-1
model/user.go
+13
-2
No files found.
controller/user.go
View file @
05f35fd0
...
...
@@ -311,7 +311,7 @@ func GenerateAccessToken(c *gin.Context) {
})
return
}
user
.
AccessToken
=
common
.
GetUUID
(
)
user
.
SetAccessToken
(
common
.
GetUUID
()
)
if
model
.
DB
.
Where
(
"access_token = ?"
,
user
.
AccessToken
)
.
First
(
user
)
.
RowsAffected
!=
0
{
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
...
...
model/main.go
View file @
05f35fd0
...
...
@@ -32,7 +32,7 @@ func createRootAccountIfNeed() error {
Role
:
common
.
RoleRootUser
,
Status
:
common
.
UserStatusEnabled
,
DisplayName
:
"Root User"
,
AccessToken
:
common
.
GetUUID
()
,
AccessToken
:
nil
,
Quota
:
100000000
,
}
DB
.
Create
(
&
rootUser
)
...
...
model/user.go
View file @
05f35fd0
...
...
@@ -25,7 +25,7 @@ type User struct {
WeChatId
string
`json:"wechat_id" gorm:"column:wechat_id;index"`
TelegramId
string
`json:"telegram_id" gorm:"column:telegram_id;index"`
VerificationCode
string
`json:"verification_code" gorm:"-:all"`
// this field is only for Email verification, don't save it to database!
AccessToken
string
`json:"access_token" gorm:"type:char(32);column:access_token;uniqueIndex"`
// this token is for system management
AccessToken
*
string
`json:"access_token" gorm:"type:char(32);column:access_token;uniqueIndex"`
// this token is for system management
Quota
int
`json:"quota" gorm:"type:int;default:0"`
UsedQuota
int
`json:"used_quota" gorm:"type:int;default:0;column:used_quota"`
// used quota
RequestCount
int
`json:"request_count" gorm:"type:int;default:0;"`
// request number
...
...
@@ -38,6 +38,17 @@ type User struct {
DeletedAt
gorm
.
DeletedAt
`gorm:"index"`
}
func
(
user
*
User
)
GetAccessToken
()
string
{
if
user
.
AccessToken
==
nil
{
return
""
}
return
*
user
.
AccessToken
}
func
(
user
*
User
)
SetAccessToken
(
token
string
)
{
user
.
AccessToken
=
&
token
}
// CheckUserExistOrDeleted check if user exist or deleted, if not exist, return false, nil, if deleted or exist, return true, nil
func
CheckUserExistOrDeleted
(
username
string
,
email
string
)
(
bool
,
error
)
{
var
user
User
...
...
@@ -201,7 +212,7 @@ func (user *User) Insert(inviterId int) error {
}
}
user
.
Quota
=
common
.
QuotaForNewUser
user
.
AccessToken
=
common
.
GetUUID
(
)
//user.SetAccessToken(common.GetUUID()
)
user
.
AffCode
=
common
.
GetRandomString
(
4
)
result
:=
DB
.
Create
(
user
)
if
result
.
Error
!=
nil
{
...
...
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