You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
OneAuth/oa/models/user.go

42 lines
1.5 KiB
Go

package models
3 weeks ago
import (
"gorm.io/gorm"
)
// salt for user user password gen aes code
// salt 32 hex / 16 byte / 128 bit
// code 64 hex / 32 byte / 256 bit
type User struct {
BaseModel
4 weeks ago
Username string `json:"username" gorm:"type:varchar(100);unique;default:not null" methods:"post,*patch,*list" parse:"json"`
Nickname string `json:"nickname" gorm:"type:varchar(100)" methods:"*post,*patch,*list" parse:"json"`
4 weeks ago
Icon string `json:"icon" methods:"*post,*patch" parse:"json"`
4 weeks ago
Email string `json:"email" gorm:"unique;type:varchar(50);default:null" methods:"*post,*patch,*list" parse:"json"`
Phone string `json:"phone" gorm:"type:varchar(30);unique;default:null" methods:"*post,*patch,*list" parse:"json"`
4 weeks ago
Status uint `json:"status" methods:"*patch,*list" parse:"json"`
1 week ago
Salt string `json:"-" gorm:"type:varchar(32)"`
3 weeks ago
Code string `json:"-" gorm:"type:varchar(64)" methods:"post" parse:"json"`
}
type UserRole struct {
BaseModel
3 weeks ago
UserID string `json:"user_id" methods:"post,delete" parse:"json"`
User *User `json:"-" gorm:"foreignKey:UserID;references:ID"`
RoleID string `json:"role_id" methods:"post,delete" parse:"json"`
Role *Role `json:"-" gorm:"foreignKey:RoleID;references:ID"`
AppID string `json:"app_id" methods:"post,delete" parse:"json"`
App *App `json:"-" gorm:"foreignKey:AppID;references:ID"`
4 weeks ago
Status string `json:"status" methods:"post,*patch,*list" parse:"json"`
}
3 weeks ago
func (m *UserRole) AfterCreate(tx *gorm.DB) error {
return tx.Model(&Role{}).Where("id = ?", m.RoleID).Update("user_count", gorm.Expr("user_count + ?", 1)).Error
}