更新
This commit is contained in:
1 parent
5718a00e31
commit
1850ac640e
226 files changed
+37772
-12071
No files matched your search
@@ -4,6 +4,7 @@ import (
|
||||
"encoding/json"
|
||||
"io"
|
||||
"server/models"
|
||||
"server/pkg/identity"
|
||||
"server/pkg/jwtutil"
|
||||
"strconv"
|
||||
"strings"
|
||||
@@ -19,22 +20,7 @@ type PlatformNotebookController struct {
|
||||
|
||||
// requireAuth 验证平台用户权限
|
||||
func requireNotebookAuth(c *beego.Controller) (*jwtutil.Claims, error) {
|
||||
auth := c.Ctx.Request.Header.Get("Authorization")
|
||||
if auth == "" {
|
||||
return nil, orm.ErrNoRows
|
||||
}
|
||||
parts := strings.SplitN(auth, " ", 2)
|
||||
if len(parts) != 2 || parts[0] != "Bearer" {
|
||||
return nil, orm.ErrNoRows
|
||||
}
|
||||
claims, err := jwtutil.ParseToken(parts[1])
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if claims.UserType != "platform" {
|
||||
return nil, orm.ErrNoRows
|
||||
}
|
||||
return claims, nil
|
||||
return identity.Claims(c.Ctx.Request.Header.Get("Authorization"), identity.EndPlatform)
|
||||
}
|
||||
|
||||
// jsonResponse 统一JSON响应
|
||||
@@ -56,7 +42,8 @@ func jsonResponse(c *beego.Controller, httpStatus, code int, msg string, data in
|
||||
func (c *PlatformNotebookController) List() {
|
||||
claims, err := requireNotebookAuth(&c.Controller)
|
||||
if err != nil {
|
||||
jsonResponse(&c.Controller, 401, 401, "未登录或无权限", nil)
|
||||
code := identity.Status(err)
|
||||
jsonResponse(&c.Controller, code, code, err.Error(), nil)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -111,7 +98,8 @@ func (c *PlatformNotebookController) List() {
|
||||
func (c *PlatformNotebookController) Detail() {
|
||||
claims, err := requireNotebookAuth(&c.Controller)
|
||||
if err != nil {
|
||||
jsonResponse(&c.Controller, 401, 401, "未登录或无权限", nil)
|
||||
code := identity.Status(err)
|
||||
jsonResponse(&c.Controller, code, code, err.Error(), nil)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -145,7 +133,8 @@ func (c *PlatformNotebookController) Detail() {
|
||||
func (c *PlatformNotebookController) Create() {
|
||||
claims, err := requireNotebookAuth(&c.Controller)
|
||||
if err != nil {
|
||||
jsonResponse(&c.Controller, 401, 401, "未登录或无权限", nil)
|
||||
code := identity.Status(err)
|
||||
jsonResponse(&c.Controller, code, code, err.Error(), nil)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -196,7 +185,8 @@ func (c *PlatformNotebookController) Create() {
|
||||
func (c *PlatformNotebookController) Update() {
|
||||
claims, err := requireNotebookAuth(&c.Controller)
|
||||
if err != nil {
|
||||
jsonResponse(&c.Controller, 401, 401, "未登录或无权限", nil)
|
||||
code := identity.Status(err)
|
||||
jsonResponse(&c.Controller, code, code, err.Error(), nil)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -273,7 +263,8 @@ func (c *PlatformNotebookController) Update() {
|
||||
func (c *PlatformNotebookController) Delete() {
|
||||
claims, err := requireNotebookAuth(&c.Controller)
|
||||
if err != nil {
|
||||
jsonResponse(&c.Controller, 401, 401, "未登录或无权限", nil)
|
||||
code := identity.Status(err)
|
||||
jsonResponse(&c.Controller, code, code, err.Error(), nil)
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user