Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
B
bwallet
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
JIRA
JIRA
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Go
bwallet
Commits
93c31394
Commit
93c31394
authored
Apr 12, 2021
by
shajiaiming
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
客服权限
parent
9a119911
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
46 additions
and
40 deletions
+46
-40
Auth.go
middleware/auth/Auth.go
+0
-39
auth.go
middleware/auth/auth.go
+36
-0
rbac.go
pkg/e/rbac.go
+6
-0
errno.go
pkg/errno/errno.go
+2
-0
router.go
routers/router.go
+2
-1
No files found.
middleware/auth/Auth.go
deleted
100644 → 0
View file @
9a119911
package
auth
import
(
"github.com/gin-gonic/gin"
"bwallet/pkg/e"
"bwallet/models"
"net/http"
)
func
AUTH
()
gin
.
HandlerFunc
{
return
func
(
c
*
gin
.
Context
)
{
var
code
int
var
data
interface
{}
code
=
e
.
SUCCESS
token
:=
c
.
Request
.
Header
.
Get
(
"Token"
)
if
token
==
""
{
code
=
e
.
INVALID_PARAMS
}
else
{
_
,
err
:=
models
.
CheckToken
(
token
)
if
err
!=
nil
{
code
=
e
.
ERROR_AUTH_CHECK_TOKEN_FAIL
}
}
if
code
!=
e
.
SUCCESS
{
c
.
JSON
(
http
.
StatusUnauthorized
,
gin
.
H
{
"code"
:
code
,
"msg"
:
e
.
GetMsg
(
code
),
"data"
:
data
,
})
c
.
Abort
()
return
}
c
.
Next
()
}
}
middleware/auth/auth.go
0 → 100644
View file @
93c31394
package
auth
import
(
"bwallet/pkg/errno"
"bwallet/pkg/handler"
"bwallet/pkg/util"
"github.com/gin-gonic/gin"
"strings"
)
func
AUTH
(
handlerTableName
map
[
string
]
string
)
gin
.
HandlerFunc
{
return
func
(
ctx
*
gin
.
Context
)
{
token
:=
ctx
.
Request
.
Header
.
Get
(
"Token"
)
user
,
_
:=
util
.
ParseToken
(
token
)
if
81
!=
user
.
UserInfo
.
Uid
{
ctx
.
Next
()
}
handlerName
:=
strings
.
Split
(
ctx
.
HandlerName
(),
"."
)[
1
]
if
_
,
ok
:=
handlerTableName
[
handlerName
];
!
ok
{
ctx
.
Next
()
}
handleAlowed
:=
[]
string
{
"GetWallets"
,
"GetWalletCoinRelationCoinRelations"
,
"GetCoins"
}
_
,
handle
:=
util
.
Contains
(
handleAlowed
,
handlerName
)
if
!
handle
{
handler
.
SendResponse
(
ctx
,
errno
.
PermissionDenied
,
nil
)
ctx
.
Abort
()
return
}
ctx
.
Next
()
}
}
pkg/e/rbac.go
0 → 100644
View file @
93c31394
package
e
type
HandleAllowedDesc
map
[
int32
][]
string
var
HandleAllowed
=
HandleAllowedDesc
{
}
pkg/errno/errno.go
View file @
93c31394
...
@@ -69,6 +69,8 @@ var (
...
@@ -69,6 +69,8 @@ var (
ErrSn
=
&
Errno
{
Code
:
20004
,
Message
:
"Sn error."
}
ErrSn
=
&
Errno
{
Code
:
20004
,
Message
:
"Sn error."
}
ErrAk
=
&
Errno
{
Code
:
20005
,
Message
:
"Ak error."
}
ErrAk
=
&
Errno
{
Code
:
20005
,
Message
:
"Ak error."
}
PermissionDenied
=
&
Errno
{
Code
:
403
,
Message
:
"Permission Denied"
}
// coin errors
// coin errors
ErrCoinNotFound
=
&
Errno
{
Code
:
20101
,
Message
:
"The coin was not found."
}
ErrCoinNotFound
=
&
Errno
{
Code
:
20101
,
Message
:
"The coin was not found."
}
ErrCountCoin
=
&
Errno
{
Code
:
20102
,
Message
:
"The coins statistic error."
}
ErrCountCoin
=
&
Errno
{
Code
:
20102
,
Message
:
"The coins statistic error."
}
...
...
routers/router.go
View file @
93c31394
package
routers
package
routers
import
(
import
(
"bwallet/middleware/auth"
"bwallet/middleware/jwt"
"bwallet/middleware/jwt"
"bwallet/middleware/log"
"bwallet/middleware/log"
"bwallet/pkg/e"
"bwallet/pkg/e"
...
@@ -52,8 +53,8 @@ func InitRouter() *gin.Engine {
...
@@ -52,8 +53,8 @@ func InitRouter() *gin.Engine {
api
:=
r
.
Group
(
"/api"
)
api
:=
r
.
Group
(
"/api"
)
//api.Use(auth.AUTH())
api
.
Use
(
jwt
.
JWT
())
api
.
Use
(
jwt
.
JWT
())
api
.
Use
(
auth
.
AUTH
(
e
.
HandleTableName
))
api
.
POST
(
"/log"
,
backend
.
AddOperationLog
)
api
.
POST
(
"/log"
,
backend
.
AddOperationLog
)
api
.
GET
(
"/logs"
,
backend
.
GetOperationLogs
)
api
.
GET
(
"/logs"
,
backend
.
GetOperationLogs
)
api
.
Use
(
log
.
LogMiddleware
(
e
.
HandleTableName
))
api
.
Use
(
log
.
LogMiddleware
(
e
.
HandleTableName
))
...
...
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