diff options
Diffstat (limited to 'user/validators.go')
| -rw-r--r-- | user/validators.go | 60 | 
1 files changed, 22 insertions, 38 deletions
diff --git a/user/validators.go b/user/validators.go index e497122..e9a894c 100644 --- a/user/validators.go +++ b/user/validators.go @@ -1,5 +1,5 @@  /* openbills - Server for web based Libre Billing Software - * Copyright (C) 2023-2024  Vidhu Kant Sharma <vidhukant@vidhukant.com> + * Copyright (C) 2023-2025  Vidhu Kant Sharma <vidhukant@vidhukant.com>   *   * This program is free software: you can redistribute it and/or modify   * it under the terms of the GNU General Public License as published by @@ -40,45 +40,40 @@ func validatePassword(pass string) error {  func validateUsername(username string) error {  	// check if username is too short -	if len(username) < viper.GetInt("username.min_username_length") { +	if len(username) < 2 {  		return errors.ErrUsernameTooShort  	}  	// check if username is too long -	if len(username) > viper.GetInt("username.max_username_length") { +	if len(username) > 32 {  		return errors.ErrUsernameTooLong  	} - -  for _, char := range username { -    if !strings.Contains(username, string(char)) { -      return errors.ErrInvalidUsername -    } -  } +  +	// (11th October 2025) what the fuck even is this  +	// I'm not even deleting this I can't stop laughing +  //  +  // for _, char := range username { +  //   if !strings.Contains(username, string(char)) { +  //     return errors.ErrInvalidUsername +  //   } +  // }    return nil  }  func (u *User) validate() error { -	u.Username = strings.TrimSpace(u.Username)  	u.Email = strings.TrimSpace(u.Email) -  u.Phone = strings.TrimSpace(u.Phone) -  u.Website = strings.TrimSpace(u.Website) -  u.Gstin = strings.TrimSpace(u.Gstin) -	u.IsVerified = false - -  // don't validate if GSTIN is empty -  if u.Gstin != "" && !util.ValidateGstin(u.Gstin) { -    return errors.ErrInvalidGSTIN -  } - -  // don't validate if phone is empty -  if u.Phone != "" && !util.ValidatePhone(u.Phone) { -    return errors.ErrInvalidPhone -  } +  u.Username = strings.TrimSpace(u.Username) -  // don't validate if website is empty -  if u.Website != "" && !util.ValidateWebsite(u.Website) { -    return errors.ErrInvalidWebsite +	// don't accept empty username +  if u.Username == "" { +    return errors.ErrEmptyUsername +  } else { +    // validate username +    err := validateUsername(u.Username) +    if err != nil { +      return err +    }    }    // don't accept empty email @@ -91,17 +86,6 @@ func (u *User) validate() error {      }    } -  // don't accept empty username -  if u.Username == "" { -    return errors.ErrEmptyUsername -  } else { -    // validate username -    err := validateUsername(u.Username) -    if err != nil { -      return err -    } -  } -    // validate password    err := validatePassword(u.Password)    if err != nil {  |