feat:完善项目信息
This commit is contained in:
43
app/api/admin/model/sys_user.go
Normal file
43
app/api/admin/model/sys_user.go
Normal file
@ -0,0 +1,43 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"SciencesServer/app/common/model"
|
||||
"SciencesServer/serve/orm"
|
||||
"SciencesServer/utils"
|
||||
"errors"
|
||||
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
// SysUser 用户信息
|
||||
type SysUser struct {
|
||||
*model.SysUser
|
||||
}
|
||||
|
||||
func (m *SysUser) ValidatePassword(password string) bool {
|
||||
return utils.HashCompare([]byte(m.Password), []byte(utils.Md5String(password, m.Salt)))
|
||||
}
|
||||
|
||||
func (m *SysUser) IsAdminUser() bool {
|
||||
return m.IsAdmin == model.SysUserAdministratorForAdmin
|
||||
}
|
||||
|
||||
func (m *SysUser) GetByAccountOrMobile(account string, tenantID uint64) (bool, error) {
|
||||
db := orm.GetDB().Table(m.TableName()).
|
||||
Select("id", "tenant_id", "name", "mobile", "password", "salt", "is_admin", "status").
|
||||
Where("tenant_id = ?", tenantID).
|
||||
Where("(account = ? OR mobile = ?)", account, account).
|
||||
Where("is_deleted = ?", model.DeleteStatusForNot)
|
||||
|
||||
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 {
|
||||
return &SysUser{SysUser: model.NewSysUser()}
|
||||
}
|
Reference in New Issue
Block a user