41 lines
914 B
Go
41 lines
914 B
Go
package model
|
|
|
|
import (
|
|
model2 "ArmedPolice/app/common/model"
|
|
"ArmedPolice/serve/orm"
|
|
"ArmedPolice/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()}
|
|
}
|