12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 |
- package models
- import (
- "strings"
- "time"
- )
- // User 用户表
- type User struct {
- Id int `orm:"pk;auto" json:"id"`
- // 用户账号,唯一标识, Uid
- Account string `orm:"unique" json:"account"`
- Nickname string `json:"nickname"`
- Email string `json:"email"`
- // 用户角色,admin为管理员,多个使用逗号分割
- // 现在没多大用
- Roles string `json:"roles"`
- Password string `json:"password"`
- Remark string `json:"remark"`
- Source string `json:"source"` // 账号来源,默认或者自有账号
- TempCode string `json:"tempCode"` // 临时授权码,重置密码
- CreatedAt time.Time `orm:"auto_now_add;type(datetime);default(0001-01-01 00:00:00)" json:"createdAt"`
- Routes []SettingRoute `orm:"-" json:"routes"`
- }
- type UserRole struct {
- Id int `orm:"pk;auto" json:"id"`
- Code string `orm:"size(20)" json:"code"`
- Title string `orm:"size(255)" json:"title"`
- Brief string `orm:"size(255)" json:"brief"`
- Enable bool `orm:"default(true)" json:"enable"`
- RefCount int `orm:"default(0)" json:"refCount"` // 引用次数
- }
- func (u *User) IsAdmin() bool {
- if len(u.Roles) == 0 {
- return false
- }
- if strings.Index(strings.ToUpper(u.Roles), "ADMIN") > -1 {
- return true
- }
- return false
- }
- func (s *UserRole) UniqueClone() (*UserRole, string) {
- return &UserRole{
- Id: s.Id,
- }, "Id"
- }
|