Class App

java.lang.Object
io.github.sigmacasino.App

public class App extends Object
The main class of the Sigma Casino application. This class initializes the database, Spark, Stripe, and routes. It also provides utility methods for reading resources and hashing passwords.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    The database connection used by the application.
    private String
    The domain of the application, e.g.
    private com.hubspot.jinjava.Jinjava
    The Jinjava template engine used by the application.
    private org.slf4j.Logger
    The logger for this class.
    The SHA-256 password hasher used by the application.
    private int
    The port on which the application will listen for incoming connections.
    private HTTPRoute[]
    An array of routes that the application will handle.
  • Constructor Summary

    Constructors
    Constructor
    Description
    App()
    The constructor of the App class.
  • Method Summary

    Modifier and Type
    Method
    Description
    private void
    Registers all routes in the routes array with Spark.
    boolean
    Checks if an email is valid by ensuring it contains an "@" and a "." and is between 5 and 100 characters long.
    Returns the database connection used by the application.
    Returns the domain of the application, e.g.
    com.hubspot.jinjava.Jinjava
    Returns the Jinjava template engine used by the application.
    hashPassword(String password, String salt)
    Hashes a password using the SHA-256 algorithm and a salt.
    private void
    Initializes the database connection using the environment variables.
    private void
    Initializes the Spark web server by setting the port and the static files location.
    private void
    Initializes the Stripe API with the secret key generated in the Dashboard.
    static void
    main(String[] args)
    The main method of the application.
    readResource(String fileName)
    Reads a resource file from the resources directory and returns its contents as a string.
    void
    run()
    Initializes the application by setting up the database, Spark, Stripe, and routes.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • domain

      private String domain
      The domain of the application, e.g. "sigmacasino.fly.dev". If the PUBLIC_IP environment variable is not set, the domain will default to "localhost".
    • port

      private int port
      The port on which the application will listen for incoming connections. The default value is 6969.
    • routes

      private HTTPRoute[] routes
      An array of routes that the application will handle. Each route is an instance of a class that extends the HTTPRoute class.
    • logger

      private org.slf4j.Logger logger
      The logger for this class.
    • db

      private LocalDatabase db
      The database connection used by the application.
    • jinjava

      private com.hubspot.jinjava.Jinjava jinjava
      The Jinjava template engine used by the application.
    • passwordHasher

      private MessageDigest passwordHasher
      The SHA-256 password hasher used by the application.
  • Constructor Details

    • App

      public App()
      The constructor of the App class. It initializes the password hasher with the SHA-256 algorithm.
  • Method Details

    • run

      public void run()
      Initializes the application by setting up the database, Spark, Stripe, and routes. This method should be called once at the beginning of the application's lifecycle.
    • initializeDatabase

      private void initializeDatabase()
      Initializes the database connection using the environment variables. If the POSTGRES_PASSWORD environment variable is not set, the password will default to an empty string. The tables are created if necessary by running the "database_init.sql" script.
    • initializeSpark

      private void initializeSpark()
      Initializes the Spark web server by setting the port and the static files location.
    • initializeStripe

      private void initializeStripe()
      Initializes the Stripe API with the secret key generated in the Dashboard. Also ensures that domain is set to a valid value for the Stripe API.
    • addRoutes

      private void addRoutes()
      Registers all routes in the routes array with Spark. Each route is registered by calling the registerSparkRoute method.
      See Also:
    • readResource

      public String readResource(String fileName)
      Reads a resource file from the resources directory and returns its contents as a string. If the file is not found, an error message is logged and an empty string is returned.
      Parameters:
      fileName - the name of the file to read
      Returns:
      the contents of the file as a string
    • getDatabase

      public LocalDatabase getDatabase()
      Returns the database connection used by the application.
      Returns:
      the database connection
    • getJinjava

      public com.hubspot.jinjava.Jinjava getJinjava()
      Returns the Jinjava template engine used by the application.
      Returns:
      the Jinjava template engine
    • getDomain

      public String getDomain()
      Returns the domain of the application, e.g. "http://sigmacasino.fly.dev".
      Returns:
      the domain of the application
    • hashPassword

      public String hashPassword(String password, String salt)
      Hashes a password using the SHA-256 algorithm and a salt. The salt is prepended to the password before hashing.
      Parameters:
      password - the password to hash
      salt - the salt to prepend to the password
      Returns:
      the hashed password as a hexadecimal lowercase string
    • checkValidEmail

      public boolean checkValidEmail(String email)
      Checks if an email is valid by ensuring it contains an "@" and a "." and is between 5 and 100 characters long.
      Parameters:
      email - the email to check
      Returns:
      true if the email is valid, false otherwise
    • main

      public static void main(String[] args)
      The main method of the application. It sets the name of the main thread and creates an instance of the App class. The run method is then called on the instance to initialize the application.
      Parameters:
      args - the command-line arguments, currently unused