更新权限和用户模型

This commit is contained in:
veypi
2021-10-13 14:43:03 +08:00
parent 3d194e935d
commit cd7029c298
27 changed files with 575 additions and 162 deletions
@@ -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...)
}
+27
View File
@@ -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 ""
}