Compare commits

..

2 Commits

Author SHA1 Message Date
junleea 4e9e2aa7fc Merge branch 'refs/heads/feat-user'
# Conflicts:
#	service/userService.go
2024-12-04 14:51:02 +08:00
junleea 92e7c94c62 修复用户权限问题 2024-12-04 14:48:25 +08:00
3 changed files with 7 additions and 6 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)
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"})
}
// 用户修改自己的信息

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,7 +44,8 @@ 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 {
//fmt.Println("cur_user:", cur_user, "req:", req)
if user_id == req.ID && cur_user.Role != "admin" {
dao.UpdateUserByID3(user_id, req) //用户修改自己的信息,不能修改权限信息
return user_id, nil
} else if cur_user.Role == "admin" {