@@ -199,6 +199,10 @@ func (this *UserController) Edit() {
199199 if len (user ) == 0 {
200200 this .ViewError ("用户不存在!" , "/system/user/list" )
201201 }
202+ // 登录非 root 用户不能修改 root 用户信息
203+ if user ["role_id" ] == fmt .Sprintf ("%d" , models .Role_Root_Id ) && ! this .IsRoot () {
204+ this .ViewError ("没有权限修改!" , "/system/user/list" )
205+ }
202206
203207 roles := []map [string ]string {}
204208 if this .IsRoot () {
@@ -231,6 +235,8 @@ func (this *UserController) Modify() {
231235 position := strings .TrimSpace (this .GetString ("position" , "" ))
232236 location := strings .TrimSpace (this .GetString ("location" , "" ))
233237 im := strings .TrimSpace (this .GetString ("im" , "" ))
238+ password := strings .TrimSpace (this .GetString ("password" , "" ))
239+ this .Ctx .Request .PostForm .Del ("password" )
234240
235241 v := validation.Validation {}
236242 if givenName == "" {
@@ -248,37 +254,47 @@ func (this *UserController) Modify() {
248254 //if !v.Mobile(mobile, "mobile").Ok {
249255 // this.jsonError("手机号格式不正确!")
250256 //}
251- if roleId == "" {
252- this .jsonError ("没有选择角色!" )
253- }
257+ // if roleId == "" {
258+ // this.jsonError("没有选择角色!")
259+ // }
254260 //if phone != "" && !v.Phone(phone, "phone").Ok {
255261 // this.jsonError("电话格式不正确!")
256262 //}
257263
258264 user , err := models .UserModel .GetUserByUserId (userId )
259265 if err != nil {
260266 this .ErrorLog ("修改用户 " + userId + " 失败:" + err .Error ())
261- this .ViewError ("修改用户出错!" , "/system/user/list " )
267+ this .jsonError ("修改用户出错!" )
262268 }
263269 if len (user ) == 0 {
264- this .ViewError ("用户不存在!" , "/system/user/list " )
270+ this .jsonError ("用户不存在!" )
265271 }
266272 if user ["role_id" ] == fmt .Sprintf ("%d" , models .Role_Root_Id ) {
267273 roleId = fmt .Sprintf ("%d" , models .Role_Root_Id )
268274 }
275+ // 登录非 root 用户不能修改 root 用户信息
276+ if user ["role_id" ] == fmt .Sprintf ("%d" , models .Role_Root_Id ) && ! this .IsRoot () {
277+ this .jsonError ("没有权限修改!" )
278+ }
269279
270- _ , err = models . UserModel . Update ( userId , map [string ]interface {}{
280+ updateUser := map [string ]interface {}{
271281 "given_name" : givenName ,
272282 "email" : email ,
273283 "mobile" : mobile ,
274- "role_id" : roleId ,
275284 "phone" : phone ,
276285 "department" : department ,
277286 "position" : position ,
278287 "location" : location ,
279288 "im" : im ,
280- })
281-
289+ }
290+ // 超级管理员才可以修改其他用户密码
291+ if password != "" && this .IsRoot () {
292+ updateUser ["password" ] = models .UserModel .EncodePassword (password )
293+ }
294+ if roleId != "" {
295+ updateUser ["role_id" ] = roleId
296+ }
297+ _ , err = models .UserModel .Update (userId , updateUser )
282298 if err != nil {
283299 this .ErrorLog ("修改用户 " + userId + " 失败:" + err .Error ())
284300 this .jsonError ("修改用户失败" )
0 commit comments