Package io.github.sigmacasino.routes
Class RegisterPost
java.lang.Object
io.github.sigmacasino.HTTPRoute
io.github.sigmacasino.PostRoute
io.github.sigmacasino.routes.RegisterPost
- All Implemented Interfaces:
spark.Route
The RegisterPost class handles the POST request for processing the registration form submission.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate org.slf4j.Logger
The logger for this class.private Random
A random number generator for generating salts.Fields inherited from class io.github.sigmacasino.HTTPRoute
app, loginRequired, path
-
Constructor Summary
ConstructorsConstructorDescriptionRegisterPost
(App app) Constructs a RegisterPost route with the specified application. -
Method Summary
Modifier and TypeMethodDescriptionboolean
checkValidUsername
(String username) Checks if the username is valid.Generates a random salt for password hashing.void
handlePost
(spark.Request request, spark.Response response) Handles the POST request for the registration form submission.Methods inherited from class io.github.sigmacasino.PostRoute
handle, parseBodyParams, registerSparkRoute
-
Field Details
-
saltGenerator
A random number generator for generating salts. -
logger
private org.slf4j.Logger loggerThe logger for this class.
-
-
Constructor Details
-
RegisterPost
Constructs a RegisterPost route with the specified application.- Parameters:
app
- the application instance
-
-
Method Details
-
handlePost
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 classPostRoute
- Parameters:
request
- the HTTP requestresponse
- the HTTP response- Throws:
SQLException
- if an error occurs during request handling
-
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
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
-