Skip to content

Commit

Permalink
Add better error message for max length
Browse files Browse the repository at this point in the history
  • Loading branch information
aebruno committed Feb 9, 2023
1 parent a046626 commit 2dc5862
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions server/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ func (r *Router) AccountSettings(c *fiber.Ctx) error {
return c.Render("account.html", vars)
}

if len(user.First) > 150 || len(user.Last) > 150 {
vars["message"] = "First or Last name is too long. Maximum of 150 chars allowed"
return c.Render("account.html", vars)
}

userUpdated, err := r.adminClient.UserMod(user)
if err != nil {
if ierr, ok := err.(*ipa.IpaError); ok {
Expand Down Expand Up @@ -117,12 +122,16 @@ func (r *Router) accountCreate(user *ipa.User, password, passwordConfirm, captch
return err
}

if user.First == "" || len(user.First) > 150 {
return errors.New("Please provide your first name")
if user.First == "" || user.Last == "" {
return errors.New("Please provide your first and last name")
}

if len(user.First) > 150 {
return errors.New("First name is too long. Maximum of 150 chars allowed")
}

if user.Last == "" || len(user.Last) > 150 {
return errors.New("Please provide your last name")
if len(user.Last) > 150 {
return errors.New("Last name is too long. Maximum of 150 chars allowed")
}

if err := validatePassword(password, passwordConfirm); err != nil {
Expand Down

0 comments on commit 2dc5862

Please sign in to comment.