本文整理汇总了Golang中github.com/opesun/nocrud/frame/interfaces.User类的典型用法代码示例。如果您正苦于以下问题:Golang User类的具体用法?Golang User怎么用?Golang User使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了User类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: userChecks
func (h *HighLev) userChecks(user iface.User) error {
verbSpec, ok := jsonp.GetM(h.nouns, fmt.Sprint("%v.verbs.%v.userCrit", h.desc.Sentence.Noun, h.desc.Sentence.Verb))
if ok {
_, err := sanitize.Fast(verbSpec, user.Data())
return err
}
nounSpec, ok := jsonp.GetM(h.nouns, fmt.Sprintf("%v.userCrit", h.desc.Sentence.Noun))
if !ok {
return nil
}
_, err := sanitize.Fast(nounSpec, user.Data())
return err
}
示例2: Run
func (h *HighLev) Run(db iface.Db, usr iface.User, defminlev int) ([]interface{}, error) {
desc := h.desc
levi, ok := jsonp.Get(h.nouns, fmt.Sprintf("%v.verbs.%v.level", desc.Sentence.Noun, desc.Sentence.Verb))
if !ok {
levi = defminlev
}
lev, _ := numcon.Int(levi)
if usr.Level() < lev {
return nil, fmt.Errorf("Not allowed.")
}
filterCreator := func(c string, input map[string]interface{}) (iface.Filter, error) {
return db.NewFilter(c, input)
}
inp, data, err := desc.CreateInputs(filterCreator)
if err != nil {
return nil, err
}
if data != nil {
if desc.Sentence.Noun != "options" {
data, err = h.validate(desc.Sentence.Noun, desc.Sentence.Verb, data)
if err != nil {
return nil, err
}
}
inp = append(inp, data)
}
module := h.hooks.Module(desc.VerbLocation)
if !module.Exists() {
return nil, fmt.Errorf("Unkown module.")
}
ins := module.Instance()
var ret []interface{}
ret_rec := func(i ...interface{}) {
ret = i
}
err = ins.Method(desc.Sentence.Verb).Call(ret_rec, inp...)
if err != nil {
return nil, err
}
return ret, nil
}
示例3: Run
func (h *HighLev) Run(db iface.Db, usr iface.User, defminlev int) ([]interface{}, error) {
desc := h.desc
// Authentication.
levi, ok := jsonp.Get(h.nouns, fmt.Sprintf("%v.verbs.%v.level", desc.Sentence.Noun, desc.Sentence.Verb))
if !ok {
levi = defminlev
}
lev, _ := numcon.Int(levi)
if usr.Level() < lev {
return nil, fmt.Errorf("Not allowed.")
}
err := h.userChecks(usr)
if err != nil {
return nil, err
}
filterCreator := func(c string, input map[string]interface{}) (iface.Filter, error) {
return db.NewFilter(c, input)
}
inp, data, err := desc.CreateInputs(filterCreator)
if err != nil {
return nil, err
}
ownLev, own := h.ownLev()
if len(inp) > 0 {
if f, ok := inp[0].(iface.Filter); ok {
// This hook allows you to modify a filter before a verb accesses it.
h.hooks.Select("TopModFilter").Fire(f)
h.hooks.Select(f.Subject() + "TopModFilter").Fire(f)
}
if own && lev <= ownLev {
if f, ok := inp[0].(iface.Filter); ok {
f.AddQuery(map[string]interface{}{
"createdBy": usr.Id(),
})
}
}
}
if data != nil {
if desc.Sentence.Noun != "options" {
data, err = h.validate(desc.Sentence.Noun, desc.Sentence.Verb, data)
if err != nil {
return nil, err
}
}
inp = append(inp, data)
}
module := h.hooks.Module(desc.VerbLocation)
if !module.Exists() {
return nil, fmt.Errorf("Unkown module.")
}
ins := module.Instance()
var ret []interface{}
ret_rec := func(i ...interface{}) {
ret = i
}
err = ins.Method(desc.Sentence.Verb).Call(ret_rec, inp...)
if err != nil {
return nil, err
}
return ret, nil
}
示例4: OnlyAdmin
func OnlyAdmin(u iface.User) {
if u.Level() < 300 {
panic("Only an admin can do this operation.")
}
}
示例5: NotAdmin
func NotAdmin(user iface.User) bool {
return user.Level() < 300
}
示例6: IsStranger
func IsStranger(user iface.User) bool {
return user.Level() == 0
}
示例7: IsRegistered
func IsRegistered(user iface.User) bool {
return user.Level() >= 100
}
示例8: IsModerator
func IsModerator(user iface.User) bool {
return user.Level() >= 200
}
示例9: IsAdmin
func IsAdmin(user iface.User) bool {
return user.Level() >= 300
}
示例10: isProfessional
func isProfessional(u iface.User) bool {
_, ok := u.Data()["professional"]
return ok
}