user.go 682 B

123456789101112131415161718192021222324252627282930
  1. package models
  2. import (
  3. "strings"
  4. "time"
  5. )
  6. // User 用户表
  7. type User struct {
  8. Id int `orm:"pk;auto" json:"id"`
  9. // 用户账号,唯一标识, Uid
  10. Account string `orm:"unique" json:"account"`
  11. Nickname string `json:"nickname"`
  12. // 用户角色,admin为管理员,多个使用逗号分割
  13. // 现在没多大用
  14. Roles string `json:"roles"`
  15. Password string `json:"password"`
  16. Remark string `json:"remark"`
  17. CreatedAt time.Time `orm:"auto_now_add;type(datetime)" json:"createdAt"`
  18. }
  19. func (u *User) IsAdmin() bool {
  20. if len(u.Roles) == 0 {
  21. return false
  22. }
  23. if strings.Index(strings.ToUpper(u.Roles), "ADMIN") > -1 {
  24. return true
  25. }
  26. return false
  27. }