Beispiel #1
0
// Update method
func (c *UserController) Update() {
	userID, err := strconv.ParseInt(c.Ctx.Input.Param(":id"), 10, 0)
	if err != nil {
		logger.Critical("Parse user id error: %v", err)
		c.Abort("500")
		return
	}

	var input struct {
		Password        string `json:"password"`
		PasswordConfirm string `json:"password_confirm"`
	}

	if err = c.ParseJSON(&input); err != nil {
		logger.Critical("Parse JSON params error: %v", err)
		c.Abort("500")
		return
	}
	logger.Debug("input params: %+v", input)

	user := models.FindUserByID(userID)
	if user == nil {
		logger.Critical("User ID[%d] not found", userID)
		c.Abort("500")
		return
	}

	if err = user.Save(); err != nil {
		logger.Critical("Save user error: %v", err)
		c.Abort("500")
		return
	}

	c.Index()
}
Beispiel #2
0
func (c *UserController) findUser() (*models.User, error) {
	userID, err := strconv.ParseInt(c.Ctx.Input.Param(":id"), 10, 0)
	if err != nil {
		logger.Critical("Parse user id error: %v", err)
		return nil, err
	}

	user := models.FindUserByID(userID)
	if user == nil {
		logger.Critical("User ID[%d] not found", userID)
		return nil, errors.New("User not found in database")
	}

	return user, nil
}