Compare commits
2 Commits
27ba32888d
...
f360bd750d
| Author | SHA1 | Date |
|---|---|---|
|
|
f360bd750d | |
|
|
be11fcbcef |
|
|
@ -77,6 +77,13 @@ func UpdateUserByID(id int, name, password, email string) {
|
|||
DB.Model(&User{}).Where("id = ?", id).Updates(User{Name: name, Password: password, Email: email})
|
||||
}
|
||||
|
||||
// 管理员修改用户信息
|
||||
func UpdateUserByID2(id int, req proto.UpdateUserInfoReq) {
|
||||
DB.Debug().Model(&User{}).Where("id = ?", id).Updates(User{Name: req.Username, Age: req.Age, Role: req.Role, Run: req.Run, Redis: req.Redis, Upload: req.Upload, Avatar: req.Avatar, Gender: req.Gender})
|
||||
user := User{Name: req.Username, Age: req.Age, Role: req.Role, Run: *req.Run, Redis: *req.Redis, Upload: *req.Upload, Avatar: req.Avatar, Gender: req.Gender}
|
||||
DB.Debug().Model(&User{}).Where("id = ?", id).Updates(user)
|
||||
}
|
||||
|
||||
// 用户修改自己的信息
|
||||
func UpdateUserByID3(id int, req proto.UpdateUserInfoReq) {
|
||||
DB.Debug().Model(&User{}).Where("id = ?", id).Updates(User{Name: req.Username, Age: req.Age, Avatar: req.Avatar, Gender: req.Gender})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,9 +6,9 @@ type UpdateUserInfoReq struct {
|
|||
Age int `json:"age" form:"age"` //年龄
|
||||
Role string `json:"role" form:"role"` //角色
|
||||
Gender string `json:"gender" form:"gender"` //性别
|
||||
Redis bool `json:"redis" form:"redis"` //是否刷新redis
|
||||
Upload bool `json:"upload" form:"upload"` //是否上传头像
|
||||
Run bool `json:"run" form:"run"` //是否运行
|
||||
Redis *bool `json:"redis" form:"redis"` //是否刷新redis
|
||||
Upload *bool `json:"upload" form:"upload"` //是否上传头像
|
||||
Run *bool `json:"run" form:"run"` //是否运行
|
||||
Avatar string `json:"avatar" form:"avatar"` //头像
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -45,7 +45,7 @@ func GetUserByNameLike(name string) []proto.User {
|
|||
func UpdateUser(user_id int, req proto.UpdateUserInfoReq) (int, error) {
|
||||
cur_user := dao.FindUserByID2(user_id)
|
||||
if user_id == req.ID {
|
||||
dao.UpdateUserByID2(user_id, req)
|
||||
dao.UpdateUserByID3(user_id, req) //用户修改自己的信息,不能修改权限信息
|
||||
return user_id, nil
|
||||
} else if cur_user.Role == "admin" {
|
||||
dao.UpdateUserByID2(req.ID, req)
|
||||
|
|
|
|||
Loading…
Reference in New Issue