Validate password length on the user-update endpoint
PUT /users/update doubles as the password-setup/reset call (userid + password only) for the new frontend create-password flow, and had no validation on that field at all. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -3,6 +3,7 @@ package controllers
|
|||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"nearle/models"
|
"nearle/models"
|
||||||
"nearle/services"
|
"nearle/services"
|
||||||
@@ -141,6 +142,17 @@ func (ctl *UserController) UpdateStaff(c *fiber.Ctx) error {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// This endpoint also doubles as the password-setup/reset call (userid +
|
||||||
|
// password only, everything else left zero so GORM's Updates skips it) —
|
||||||
|
// guard the one field that has no validation anywhere else on this path.
|
||||||
|
if pw := strings.TrimSpace(user.Password); pw != "" && len(pw) < 6 {
|
||||||
|
return c.Status(http.StatusBadRequest).JSON(fiber.Map{
|
||||||
|
"status": false,
|
||||||
|
"code": http.StatusBadRequest,
|
||||||
|
"message": "Password must be at least 6 characters",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
if err := ctl.userService.UpdateStaff(user); err != nil {
|
if err := ctl.userService.UpdateStaff(user); err != nil {
|
||||||
return c.JSON(fiber.Map{
|
return c.JSON(fiber.Map{
|
||||||
"status": false,
|
"status": false,
|
||||||
|
|||||||
Reference in New Issue
Block a user