Files

44 lines
1.0 KiB
Go
Raw Normal View History

2021-09-28 11:47:19 +08:00
package model
import (
2022-01-05 11:29:27 +08:00
"SciencesServer/app/common/model"
2021-09-28 11:47:19 +08:00
"SciencesServer/serve/orm"
"SciencesServer/utils"
"errors"
"gorm.io/gorm"
)
// SysUser 用户信息
type SysUser struct {
2022-01-05 11:29:27 +08:00
*model.SysUser
2021-09-28 11:47:19 +08:00
}
func (m *SysUser) ValidatePassword(password string) bool {
return utils.HashCompare([]byte(m.Password), []byte(utils.Md5String(password, m.Salt)))
}
func (m *SysUser) IsAdminUser() bool {
2022-01-05 11:29:27 +08:00
return m.IsAdmin == model.SysUserAdministratorForAdmin
2021-09-28 11:47:19 +08:00
}
2022-01-05 11:29:27 +08:00
func (m *SysUser) GetByAccountOrMobile(account string, tenantID uint64) (bool, error) {
db := orm.GetDB().Table(m.TableName()).
2022-01-05 18:40:08 +08:00
Select("id", "uuid", "tenant_id", "name", "mobile", "password", "salt", "is_admin", "status").
2022-01-05 11:29:27 +08:00
Where("tenant_id = ?", tenantID).
Where("(account = ? OR mobile = ?)", account, account).
Where("is_deleted = ?", model.DeleteStatusForNot)
2021-09-28 11:47:19 +08:00
if err := db.First(m.SysUser).Error; err != nil {
if errors.Is(err, gorm.ErrRecordNotFound) {
return false, nil
}
return false, err
}
return true, nil
}
func NewSysUser() *SysUser {
2022-01-05 11:29:27 +08:00
return &SysUser{SysUser: model.NewSysUser()}
2021-09-28 11:47:19 +08:00
}