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
f820158e
authored
Apr 27, 2023
by
JustSong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: check user status when validating token (#23)
parent
9667bc86
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
23 additions
and
0 deletions
+23
-0
middleware/auth.go
+10
-0
model/user.go
+13
-0
No files found.
middleware/auth.go
View file @
f820158e
...
...
@@ -98,6 +98,16 @@ func TokenAuth() func(c *gin.Context) {
c
.
Abort
()
return
}
if
!
model
.
IsUserEnabled
(
token
.
UserId
)
{
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
"error"
:
gin
.
H
{
"message"
:
"用户已被封禁"
,
"type"
:
"one_api_error"
,
},
})
c
.
Abort
()
return
}
c
.
Set
(
"id"
,
token
.
UserId
)
c
.
Set
(
"token_id"
,
token
.
Id
)
c
.
Set
(
"unlimited_times"
,
token
.
UnlimitedTimes
)
...
...
model/user.go
View file @
f820158e
...
...
@@ -195,6 +195,19 @@ func IsAdmin(userId int) bool {
return
user
.
Role
>=
common
.
RoleAdminUser
}
func
IsUserEnabled
(
userId
int
)
bool
{
if
userId
==
0
{
return
false
}
var
user
User
err
:=
DB
.
Where
(
"id = ?"
,
userId
)
.
Select
(
"status"
)
.
Find
(
&
user
)
.
Error
if
err
!=
nil
{
common
.
SysError
(
"No such user "
+
err
.
Error
())
return
false
}
return
user
.
Status
==
common
.
UserStatusEnabled
}
func
ValidateAccessToken
(
token
string
)
(
user
*
User
)
{
if
token
==
""
{
return
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