Compare commits

..

No commits in common. "4e9e2aa7fc7a930c744c24f9681e954a7c84fc4e" and "f360bd750d380015596ad28795bbd5d9f67fdc83" have entirely different histories.

3 changed files with 6 additions and 7 deletions

View File

@ -79,8 +79,8 @@ func UpdateUserByID(id int, name, password, email string) {
// 管理员修改用户信息
func UpdateUserByID2(id int, req proto.UpdateUserInfoReq) {
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).UpdateColumns([]string{"Name", "Age", "Role", "Run", "Redis", "Upload", "Avatar", "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)
}
// 用户修改自己的信息

View File

@ -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"` //头像
}

View File

@ -44,8 +44,7 @@ func GetUserByNameLike(name string) []proto.User {
func UpdateUser(user_id int, req proto.UpdateUserInfoReq) (int, error) {
cur_user := dao.FindUserByID2(user_id)
//fmt.Println("cur_user:", cur_user, "req:", req)
if user_id == req.ID && cur_user.Role != "admin" {
if user_id == req.ID {
dao.UpdateUserByID3(user_id, req) //用户修改自己的信息,不能修改权限信息
return user_id, nil
} else if cur_user.Role == "admin" {