GraphQL API and utilities for the rpdata project
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
package session
import ( "git.aiterp.net/rpdata/api/internal/store" "github.com/globalsign/mgo" )
var userCollection *mgo.Collection
// A User represents user information about a user that has logged in.
type User struct { ID string `bson:"_id" json:"id"` Nick string `bson:"nick,omitempty" json:"nick,omitempty"` Permissions []string `bson:"permissions" json:"permissions"` }
// Permitted returns true if either of the permissions can be found
//
// `user.ID == page.Author || user.Permitted("story.edit")`
func (user *User) Permitted(permissions ...string) bool { for i := range permissions { for j := range user.Permissions { if permissions[i] == user.Permissions[j] { return true } } }
return false }
// FindUser finds a user by userid
func FindUser(userid string) (User, error) { user := User{} err := userCollection.FindId(userid).One(&user)
return user, err }
func init() { store.HandleInit(func(db *mgo.Database) { userCollection = db.C("core.users") }) }
|