The new logbot, not committed from the wrong terminal window this time.
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

6 years ago
  1. package models
  2. // A User is the information about ID and permission for a user, usually
  3. // the caller.
  4. type User struct {
  5. ID string `json:"id"`
  6. Permissions []string `json:"permissions"`
  7. }
  8. // LoggedIn returns true if the user is logged-in.
  9. func (user *User) LoggedIn() bool {
  10. return user.ID != ""
  11. }
  12. // Permitted gets whether the user has this permission.
  13. func (user *User) Permitted(permissions ...string) bool {
  14. for _, userPermission := range user.Permissions {
  15. for _, permission := range permissions {
  16. if permission == userPermission {
  17. return true
  18. }
  19. }
  20. }
  21. return false
  22. }