MCPcopy Create free account
hub / github.com/OpenListTeam/OpenList / UpdateUser

Function UpdateUser

server/handles/user.go:52–86  ·  view source on GitHub ↗
(c *gin.Context)

Source from the content-addressed store, hash-verified

50}
51
52func 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
88func DeleteUser(c *gin.Context) {
89 idStr := c.Query("id")

Callers

nothing calls this directly

Calls 7

SetPasswordMethod · 0.95
IsAdminMethod · 0.95
ErrorRespFunction · 0.92
GetUserByIdFunction · 0.92
ErrorStrRespFunction · 0.92
UpdateUserFunction · 0.92
SuccessRespFunction · 0.92

Tested by

no test coverage detected