Class RegisterPost

All Implemented Interfaces:
spark.Route

public class RegisterPost extends PostRoute
The RegisterPost class handles the POST request for processing the registration form submission.
  • Field Details

    • saltGenerator

      private Random saltGenerator
      A random number generator for generating salts.
    • logger

      private org.slf4j.Logger logger
      The logger for this class.
  • Constructor Details

    • RegisterPost

      public RegisterPost(App app)
      Constructs a RegisterPost route with the specified application.
      Parameters:
      app - the application instance
  • Method Details

    • handlePost

      public void handlePost(spark.Request request, spark.Response response) throws SQLException
      Handles the POST request for the registration form submission. This method validates the input, checks for existing users, and registers a new user if the input is valid. If the input is invalid or a user already exists, the user is redirected to the registration page with an error message.
      Specified by:
      handlePost in class PostRoute
      Parameters:
      request - the HTTP request
      response - the HTTP response
      Throws:
      SQLException - if an error occurs during request handling
    • generateSalt

      public String generateSalt()
      Generates a random salt for password hashing. The salt is a 16-byte array encoded as a hexadecimal string.
      Returns:
      a string representing the generated salt
    • checkValidUsername

      public boolean checkValidUsername(String username)
      Checks if the username is valid. A valid username must be between 3 and 16 characters long.
      Parameters:
      username - the username to check
      Returns:
      true if the username is valid, false otherwise