feat:完善信息
This commit is contained in:
40
app/api/manage/model/sys_user.go
Normal file
40
app/api/manage/model/sys_user.go
Normal file
@ -0,0 +1,40 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
model2 "SciencesServer/app/common/model"
|
||||
"SciencesServer/serve/orm"
|
||||
"SciencesServer/utils"
|
||||
"errors"
|
||||
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
// SysUser 用户信息
|
||||
type SysUser struct {
|
||||
*model2.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 == model2.SysUserAdministratorForAdmin
|
||||
}
|
||||
|
||||
func (m *SysUser) GetByAccountOrMobile(param string) (bool, error) {
|
||||
db := orm.GetDB().Table(m.TableName()).Where("(account = ? OR mobile = ?)", param, param).
|
||||
Where("is_deleted = ?", model2.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: model2.NewSysUser()}
|
||||
}
|
Reference in New Issue
Block a user