Class ConnectionHandler

java.lang.Object
net.minheur.potoflux.login.ConnectionHandler

public class ConnectionHandler extends Object
Handles all things related to connecting you to your account, disconnecting you, and keeping your account
It synchronizes multiple other classes to do so
  • Field Details

    • account

      public static Account account
      Account of the user currently connected
    • isLogged

      public static boolean isLogged
      If there is a user connected.
      If this is false, account should be null
    • isAccountCreationEnabled

      public static boolean isAccountCreationEnabled
      Easy access to the account self-creation autorisation
  • Constructor Details

    • ConnectionHandler

      public ConnectionHandler()
  • Method Details

    • logWith

      public static void logWith(String email, String password)
      Logs in with an email and a password.
      Done when the user connects / reconnects to its account using its IDs
      Parameters:
      email - of the user
      password - of the account
    • accountFor

      public static void accountFor(String token)
      Logs in with a token. Calls displayInfoError(InfoResponse) if the authentication fails
      Used when auto-logging on startup
      Parameters:
      token - actually stored for the account
    • fillPerms

      public static Perms[] fillPerms(String[] perms)
      Helper that transform a String array (SQL codes) into a Perms array
      If a code isn't known, it gets ignored
      Parameters:
      perms - array of SQL codes sent by the database
      Returns:
      the array of Perms corresponding the SQL codes.
    • getToken

      @Nullable public static String getToken(String email, String password)
      Sends a request to the server, getting a connection token for specified IDs
      If the connection fails, it will call displayLoggingError(LoginResponse) and return null
      Parameters:
      email - of the target account
      password - of the account
      Returns:
      the token sent by the database or null if failed
    • reloadAccountCreationPermission

      public static void reloadAccountCreationPermission()
      Sends a request, getting / regetting weather the account creation is allowed
    • sendAccountCreationLockRequest

      public static void sendAccountCreationLockRequest(boolean isAllowed)
      Sends a request to allow or not the creation of account
      Parameters:
      isAllowed - weather account self-creation is allowed
    • checkAndRemoveExistingToken

      public static void checkAndRemoveExistingToken()
      If there's a token stored in the system, sends a request to remove it on the server.
      Weather it succeeds of fails, will clear local token
    • performAuthAction

      public static void performAuthAction()
      Runs logout() if isLogged is true, else calls login().
      Once the right one is run, follows by reloadAuthUi()
    • reloadAuthUi

      public static void reloadAuthUi()
      Reloads UI related to account state
    • logout

      public static void logout()
      If not already so, remove the online and local token, then clears account and set isLogged to false
    • login

      public static void login()
      Displays a connection dialog, then if confirmed logout() then logWith(String, String)
    • getAuthButtonStatus

      public static String getAuthButtonStatus()
      Helper to get the text to apply to connection button, changing is isLogged is true or false
      Returns:
      the correct text for the auth buttton