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.
26 lines
605 B
26 lines
605 B
package models
|
|
|
|
// A User is the information about ID and permission for a user, usually
|
|
// the caller.
|
|
type User struct {
|
|
ID string `json:"id"`
|
|
Permissions []string `json:"permissions"`
|
|
}
|
|
|
|
// LoggedIn returns true if the user is logged-in.
|
|
func (user *User) LoggedIn() bool {
|
|
return user.ID != ""
|
|
}
|
|
|
|
// Permitted gets whether the user has this permission.
|
|
func (user *User) Permitted(permissions ...string) bool {
|
|
for _, userPermission := range user.Permissions {
|
|
for _, permission := range permissions {
|
|
if permission == userPermission {
|
|
return true
|
|
}
|
|
}
|
|
}
|
|
|
|
return false
|
|
}
|