更新
This commit is contained in:
1 parent
5718a00e31
commit
1850ac640e
226 files changed
+37772
-12071
No files matched your search
@@ -11,6 +11,7 @@ import (
|
||||
"time"
|
||||
|
||||
"server/models"
|
||||
"server/pkg/identity"
|
||||
"server/pkg/jwtutil"
|
||||
|
||||
"github.com/beego/beego/v2/client/orm"
|
||||
@@ -21,23 +22,9 @@ type AppReminderController struct {
|
||||
beego.Controller
|
||||
}
|
||||
|
||||
// 只放行移动端与租户端令牌:/api/** 仅被 uniapp 调用,平台令牌不该能打移动端接口。
|
||||
func (c *AppReminderController) appClaims() (*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 != "backend" && claims.UserType != "app" && claims.UserType != "platform" {
|
||||
return nil, orm.ErrNoRows
|
||||
}
|
||||
return claims, nil
|
||||
return identity.Claims(c.Ctx.Request.Header.Get("Authorization"), identity.EndApp, identity.EndBackend)
|
||||
}
|
||||
|
||||
func (c *AppReminderController) jsonErr(httpStatus, bizCode int, msg string) {
|
||||
@@ -72,7 +59,7 @@ type appSchedulePayload struct {
|
||||
func (c *AppReminderController) GetList() {
|
||||
claims, err := c.appClaims()
|
||||
if err != nil {
|
||||
c.jsonErr(401, 401, "未登录或无权限")
|
||||
c.jsonErr(identity.Status(err), identity.Status(err), err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
@@ -173,7 +160,7 @@ func (c *AppReminderController) GetList() {
|
||||
func (c *AppReminderController) GetDetail() {
|
||||
claims, err := c.appClaims()
|
||||
if err != nil {
|
||||
c.jsonErr(401, 401, "未登录或无权限")
|
||||
c.jsonErr(identity.Status(err), identity.Status(err), err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
@@ -246,7 +233,7 @@ func (c *AppReminderController) GetDetail() {
|
||||
func (c *AppReminderController) Create() {
|
||||
claims, err := c.appClaims()
|
||||
if err != nil {
|
||||
c.jsonErr(401, 401, "未登录或无权限")
|
||||
c.jsonErr(identity.Status(err), identity.Status(err), err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
@@ -348,7 +335,7 @@ func (c *AppReminderController) Create() {
|
||||
func (c *AppReminderController) Update() {
|
||||
claims, err := c.appClaims()
|
||||
if err != nil {
|
||||
c.jsonErr(401, 401, "未登录或无权限")
|
||||
c.jsonErr(identity.Status(err), identity.Status(err), err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
@@ -484,7 +471,7 @@ func (c *AppReminderController) Update() {
|
||||
func (c *AppReminderController) Delete() {
|
||||
claims, err := c.appClaims()
|
||||
if err != nil {
|
||||
c.jsonErr(401, 401, "未登录或无权限")
|
||||
c.jsonErr(identity.Status(err), identity.Status(err), err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
@@ -545,7 +532,7 @@ func (c *AppReminderController) Delete() {
|
||||
func (c *AppReminderController) ToggleComplete() {
|
||||
claims, err := c.appClaims()
|
||||
if err != nil {
|
||||
c.jsonErr(401, 401, "未登录或无权限")
|
||||
c.jsonErr(identity.Status(err), identity.Status(err), err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user