Compare commits
No commits in common. "f360bd750d380015596ad28795bbd5d9f67fdc83" and "27ba32888d783adfcd1955d33a8e689c55204d1e" have entirely different histories.
f360bd750d
...
27ba32888d
|
|
@ -77,13 +77,6 @@ func UpdateUserByID(id int, name, password, email string) {
|
||||||
DB.Model(&User{}).Where("id = ?", id).Updates(User{Name: name, Password: password, Email: email})
|
DB.Model(&User{}).Where("id = ?", id).Updates(User{Name: name, Password: password, Email: email})
|
||||||
}
|
}
|
||||||
|
|
||||||
// 管理员修改用户信息
|
|
||||||
func UpdateUserByID2(id int, req proto.UpdateUserInfoReq) {
|
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{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"` //年龄
|
Age int `json:"age" form:"age"` //年龄
|
||||||
Role string `json:"role" form:"role"` //角色
|
Role string `json:"role" form:"role"` //角色
|
||||||
Gender string `json:"gender" form:"gender"` //性别
|
Gender string `json:"gender" form:"gender"` //性别
|
||||||
Redis *bool `json:"redis" form:"redis"` //是否刷新redis
|
Redis bool `json:"redis" form:"redis"` //是否刷新redis
|
||||||
Upload *bool `json:"upload" form:"upload"` //是否上传头像
|
Upload bool `json:"upload" form:"upload"` //是否上传头像
|
||||||
Run *bool `json:"run" form:"run"` //是否运行
|
Run bool `json:"run" form:"run"` //是否运行
|
||||||
Avatar string `json:"avatar" form:"avatar"` //头像
|
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) {
|
func UpdateUser(user_id int, req proto.UpdateUserInfoReq) (int, error) {
|
||||||
cur_user := dao.FindUserByID2(user_id)
|
cur_user := dao.FindUserByID2(user_id)
|
||||||
if user_id == req.ID {
|
if user_id == req.ID {
|
||||||
dao.UpdateUserByID3(user_id, req) //用户修改自己的信息,不能修改权限信息
|
dao.UpdateUserByID2(user_id, req)
|
||||||
return user_id, nil
|
return user_id, nil
|
||||||
} else if cur_user.Role == "admin" {
|
} else if cur_user.Role == "admin" {
|
||||||
dao.UpdateUserByID2(req.ID, req)
|
dao.UpdateUserByID2(req.ID, req)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue