更新权限和用户模型
This commit is contained in:
@@ -8,12 +8,12 @@ import (
|
||||
"github.com/veypi/OneBD/rfc"
|
||||
)
|
||||
|
||||
type Auth struct {
|
||||
type UserHandler struct {
|
||||
Payload *models.PayLoad
|
||||
ignoreMethod map[rfc.Method]bool
|
||||
}
|
||||
|
||||
func (a *Auth) Init(m OneBD.Meta) error {
|
||||
func (a *UserHandler) Init(m OneBD.Meta) error {
|
||||
if a.ignoreMethod != nil && a.ignoreMethod[m.Method()] {
|
||||
return nil
|
||||
}
|
||||
@@ -29,7 +29,7 @@ func (a *Auth) Init(m OneBD.Meta) error {
|
||||
return oerr.NotLogin.Attach(err)
|
||||
}
|
||||
|
||||
func (a *Auth) Ignore(methods ...rfc.Method) {
|
||||
func (a *UserHandler) Ignore(methods ...rfc.Method) {
|
||||
if a.ignoreMethod == nil {
|
||||
a.ignoreMethod = make(map[rfc.Method]bool)
|
||||
}
|
||||
@@ -38,6 +38,6 @@ func (a *Auth) Ignore(methods ...rfc.Method) {
|
||||
}
|
||||
}
|
||||
|
||||
func (a *Auth) CheckAuth(name string, tags ...string) models.AuthLevel {
|
||||
return a.Payload.CheckAuth(name, tags...)
|
||||
func (a *UserHandler) GetAuth(ResourceID string, ResourceUUID ...string) models.AuthLevel {
|
||||
return a.Payload.GetAuth(ResourceID, ResourceUUID...)
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package auth
|
||||
|
||||
import (
|
||||
"OneAuth/models"
|
||||
"github.com/veypi/utils"
|
||||
"sync"
|
||||
)
|
||||
|
||||
var keyCache = sync.Map{}
|
||||
|
||||
func GetUserKey(uid uint, app *models.App) string {
|
||||
if app.ID == 1 {
|
||||
key, _ := keyCache.LoadOrStore(uid, utils.RandSeq(16))
|
||||
return key.(string)
|
||||
}
|
||||
// TODO: 获取其他应用user_key
|
||||
return ""
|
||||
}
|
||||
|
||||
func RefreshUserKey(uid uint, app *models.App) string {
|
||||
if app.ID == 1 {
|
||||
key := utils.RandSeq(16)
|
||||
keyCache.Store(uid, key)
|
||||
return key
|
||||
}
|
||||
return ""
|
||||
}
|
||||
@@ -17,11 +17,11 @@ var json = jsoniter.ConfigFastest
|
||||
|
||||
type ApiHandler struct {
|
||||
OneBD.BaseHandler
|
||||
auth.Auth
|
||||
auth.UserHandler
|
||||
}
|
||||
|
||||
func (h *ApiHandler) Init(m OneBD.Meta) error {
|
||||
return tools.MultiIniter(m, &h.BaseHandler, &h.Auth)
|
||||
return tools.MultiIniter(m, &h.BaseHandler, &h.UserHandler)
|
||||
}
|
||||
|
||||
func (h *ApiHandler) OnResponse(data interface{}) {
|
||||
|
||||
Reference in New Issue
Block a user