MCPcopy Create free account
hub / github.com/aiprodcoder/MIXAPI / UpdateSelf

Function UpdateSelf

controller/user.go:503–549  ·  view source on GitHub ↗
(c *gin.Context)

Source from the content-addressed store, hash-verified

501}
502
503func UpdateSelf(c *gin.Context) {
504 var user model.User
505 err := json.NewDecoder(c.Request.Body).Decode(&user)
506 if err != nil {
507 c.JSON(http.StatusOK, gin.H{
508 "success": false,
509 "message": "无效的参数",
510 })
511 return
512 }
513 if user.Password == "" {
514 user.Password = "$I_LOVE_U" // make Validator happy :)
515 }
516 if err := common.Validate.Struct(&user); err != nil {
517 c.JSON(http.StatusOK, gin.H{
518 "success": false,
519 "message": "输入不合法 " + err.Error(),
520 })
521 return
522 }
523
524 cleanUser := model.User{
525 Id: c.GetInt("id"),
526 Username: user.Username,
527 Password: user.Password,
528 DisplayName: user.DisplayName,
529 }
530 if user.Password == "$I_LOVE_U" {
531 user.Password = "" // rollback to what it should be
532 cleanUser.Password = ""
533 }
534 updatePassword, err := checkUpdatePassword(user.OriginalPassword, user.Password, cleanUser.Id)
535 if err != nil {
536 common.ApiError(c, err)
537 return
538 }
539 if err := cleanUser.Update(updatePassword); err != nil {
540 common.ApiError(c, err)
541 return
542 }
543
544 c.JSON(http.StatusOK, gin.H{
545 "success": true,
546 "message": "",
547 })
548 return
549}
550
551func checkUpdatePassword(originalPassword string, newPassword string, userId int) (updatePassword bool, err error) {
552 var currentUser *model.User

Callers

nothing calls this directly

Calls 4

UpdateMethod · 0.95
ApiErrorFunction · 0.92
checkUpdatePasswordFunction · 0.85
ErrorMethod · 0.80

Tested by

no test coverage detected