(c *gin.Context)
| 50 | } |
| 51 | |
| 52 | func UpdateUser(c *gin.Context) { |
| 53 | var req model.User |
| 54 | if err := c.ShouldBind(&req); err != nil { |
| 55 | common.ErrorResp(c, err, 400) |
| 56 | return |
| 57 | } |
| 58 | user, err := op.GetUserById(req.ID) |
| 59 | if err != nil { |
| 60 | common.ErrorResp(c, err, 500) |
| 61 | return |
| 62 | } |
| 63 | if user.Role != req.Role { |
| 64 | common.ErrorStrResp(c, "role can not be changed", 400) |
| 65 | return |
| 66 | } |
| 67 | if req.Password == "" { |
| 68 | req.PwdHash = user.PwdHash |
| 69 | req.Salt = user.Salt |
| 70 | } else { |
| 71 | req.SetPassword(req.Password) |
| 72 | req.Password = "" |
| 73 | } |
| 74 | if req.OtpSecret == "" { |
| 75 | req.OtpSecret = user.OtpSecret |
| 76 | } |
| 77 | if req.Disabled && req.IsAdmin() { |
| 78 | common.ErrorStrResp(c, "admin user can not be disabled", 400) |
| 79 | return |
| 80 | } |
| 81 | if err := op.UpdateUser(&req); err != nil { |
| 82 | common.ErrorResp(c, err, 500) |
| 83 | } else { |
| 84 | common.SuccessResp(c) |
| 85 | } |
| 86 | } |
| 87 | |
| 88 | func DeleteUser(c *gin.Context) { |
| 89 | idStr := c.Query("id") |
nothing calls this directly
no test coverage detected