MCPcopy Create free account
hub / github.com/TalkingData/owl / updateUserProfile

Function updateUserProfile

api/users.go:194–220  ·  view source on GitHub ↗
(c *gin.Context)

Source from the content-addressed store, hash-verified

192}
193
194func updateUserProfile(c *gin.Context) {
195 response := gin.H{"code": http.StatusOK}
196 defer c.JSON(http.StatusOK, response)
197 var user User
198 if err := c.BindJSON(&user); err != nil {
199 response["code"] = http.StatusBadRequest
200 log.Println(err)
201 return
202 }
203 if user.ID == 0 {
204 response["code"] = http.StatusBadRequest
205 return
206 }
207 currUser := mydb.getUserProfile(c.GetString("username"))
208 if user.ID != currUser.ID {
209 if !currUser.isAdmin() {
210 response["code"] = http.StatusForbidden
211 return
212 }
213 }
214 user.Password = currUser.Password
215 if err := mydb.updateUserProfile(&user); err != nil {
216 response["code"] = http.StatusInternalServerError
217 return
218 }
219 response["user"] = mydb.getUserProfile(user.Username)
220}
221
222func changeUserRole(c *gin.Context) {
223 response := gin.H{"code": http.StatusOK}

Callers

nothing calls this directly

Calls 3

getUserProfileMethod · 0.80
isAdminMethod · 0.80
updateUserProfileMethod · 0.80

Tested by

no test coverage detected