feat:完善信息
This commit is contained in:
47
app/api/manage/controller/user/person.go
Normal file
47
app/api/manage/controller/user/person.go
Normal file
@ -0,0 +1,47 @@
|
||||
package user
|
||||
|
||||
import (
|
||||
"SciencesServer/app/api/manage/model"
|
||||
model2 "SciencesServer/app/common/model"
|
||||
"SciencesServer/app/service"
|
||||
"errors"
|
||||
"time"
|
||||
)
|
||||
|
||||
type Person struct{ *service.Session }
|
||||
|
||||
type PersonHandle func(session *service.Session) *Person
|
||||
|
||||
// EditPassword 修改密码
|
||||
func (c *Person) EditPassword(oldPassword, password, repeatPwd string) error {
|
||||
if password != repeatPwd {
|
||||
return errors.New("两次密码不一致")
|
||||
}
|
||||
mSysUser := model.NewSysUser()
|
||||
|
||||
isExist, err := model2.FirstWhere(mSysUser.SysUser, model2.NewWhere("uuid", c.UID))
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
} else if !isExist {
|
||||
return errors.New("用户信息不存在或已被删除")
|
||||
}
|
||||
if !mSysUser.ValidatePassword(oldPassword) {
|
||||
return errors.New("旧密码错误")
|
||||
}
|
||||
mSysUser.Password = password
|
||||
mSysUser.Pass()
|
||||
|
||||
if err = model2.Updates(mSysUser.SysUser, map[string]interface{}{
|
||||
"password": mSysUser.Password, "salt": mSysUser.Salt, "updated_at": time.Now(),
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func NewPerson() PersonHandle {
|
||||
return func(session *service.Session) *Person {
|
||||
return &Person{Session: session}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user