更新
This commit is contained in:
1 parent
5718a00e31
commit
1850ac640e
226 files changed
+37772
-12071
No files matched your search
@@ -2,12 +2,12 @@ package controllers
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"server/models"
|
||||
"server/pkg/identity"
|
||||
"server/pkg/jwtutil"
|
||||
|
||||
beego "github.com/beego/beego/v2/server/web"
|
||||
@@ -19,22 +19,7 @@ type BackendNotifyConfigController struct {
|
||||
}
|
||||
|
||||
func (c *BackendNotifyConfigController) ncClaims() (*jwtutil.Claims, error) {
|
||||
auth := c.Ctx.Request.Header.Get("Authorization")
|
||||
if auth == "" {
|
||||
return nil, fmt.Errorf("未登录")
|
||||
}
|
||||
parts := strings.SplitN(auth, " ", 2)
|
||||
if len(parts) != 2 || parts[0] != "Bearer" {
|
||||
return nil, fmt.Errorf("认证信息格式错误")
|
||||
}
|
||||
claims, err := jwtutil.ParseToken(parts[1])
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("无效的token")
|
||||
}
|
||||
if claims.UserType != "backend" {
|
||||
return nil, fmt.Errorf("无权访问")
|
||||
}
|
||||
return claims, nil
|
||||
return identity.Claims(c.Ctx.Request.Header.Get("Authorization"), identity.EndBackend)
|
||||
}
|
||||
|
||||
func (c *BackendNotifyConfigController) ncJsonErr(httpStatus, bizCode int, msg string) {
|
||||
@@ -60,7 +45,8 @@ type notifyConfigPayload struct {
|
||||
func (c *BackendNotifyConfigController) GetConfig() {
|
||||
claims, err := c.ncClaims()
|
||||
if err != nil {
|
||||
c.ncJsonErr(401, 401, err.Error())
|
||||
code := identity.Status(err)
|
||||
c.ncJsonErr(code, code, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
@@ -77,7 +63,8 @@ func (c *BackendNotifyConfigController) GetConfig() {
|
||||
func (c *BackendNotifyConfigController) UpdateConfig() {
|
||||
claims, err := c.ncClaims()
|
||||
if err != nil {
|
||||
c.ncJsonErr(401, 401, err.Error())
|
||||
code := identity.Status(err)
|
||||
c.ncJsonErr(code, code, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user