更新
This commit is contained in:
1 parent
5718a00e31
commit
1850ac640e
226 files changed
+37772
-12071
No files matched your search
@@ -9,6 +9,7 @@ import (
|
||||
"time"
|
||||
|
||||
"server/models"
|
||||
"server/pkg/identity"
|
||||
"server/pkg/jwtutil"
|
||||
|
||||
"github.com/beego/beego/v2/client/orm"
|
||||
@@ -202,22 +203,7 @@ func crmContactAtoi(s string) int {
|
||||
}
|
||||
|
||||
func (c *BackendCrmContactController) contactClaims() (*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 *BackendCrmContactController) crmContactJsonErr(httpStatus, bizCode int, msg string) {
|
||||
@@ -430,7 +416,8 @@ func crmEnsureCompanyContact(tenantID, companyType string, companyID uint64, nam
|
||||
func (c *BackendCrmContactController) List() {
|
||||
claims, err := c.contactClaims()
|
||||
if err != nil {
|
||||
c.crmContactJsonErr(401, 401, err.Error())
|
||||
code := identity.Status(err)
|
||||
c.crmContactJsonErr(code, code, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
@@ -498,7 +485,8 @@ func (c *BackendCrmContactController) List() {
|
||||
func (c *BackendCrmContactController) Add() {
|
||||
claims, err := c.contactClaims()
|
||||
if err != nil {
|
||||
c.crmContactJsonErr(401, 401, err.Error())
|
||||
code := identity.Status(err)
|
||||
c.crmContactJsonErr(code, code, err.Error())
|
||||
return
|
||||
}
|
||||
var p struct {
|
||||
@@ -579,7 +567,8 @@ func (c *BackendCrmContactController) Add() {
|
||||
func (c *BackendCrmContactController) Edit() {
|
||||
claims, err := c.contactClaims()
|
||||
if err != nil {
|
||||
c.crmContactJsonErr(401, 401, err.Error())
|
||||
code := identity.Status(err)
|
||||
c.crmContactJsonErr(code, code, err.Error())
|
||||
return
|
||||
}
|
||||
var p struct {
|
||||
@@ -668,7 +657,8 @@ func (c *BackendCrmContactController) Edit() {
|
||||
func (c *BackendCrmContactController) Delete() {
|
||||
claims, err := c.contactClaims()
|
||||
if err != nil {
|
||||
c.crmContactJsonErr(401, 401, err.Error())
|
||||
code := identity.Status(err)
|
||||
c.crmContactJsonErr(code, code, err.Error())
|
||||
return
|
||||
}
|
||||
var p struct {
|
||||
|
||||
Reference in new issue
Block a user