Class WebAccountFunctions

java.lang.Object
com.patreonshout.jpa.WebAccountFunctions

@Component
public class WebAccountFunctions
extends java.lang.Object
Component that contains functions for WebAccount endpoints that allow interaction with the database
  • Field Details

    • webAccountRepository

      @Autowired WebAccountRepository webAccountRepository
      An autowired Spring repository that handles all database CRUD operations with the webaccounts
    • securityConfiguration

      @Autowired SecurityConfiguration securityConfiguration
      securityConfiguration is the SecurityConfiguration that handles encrypting password with BCryptPasswordEncoder hashing
  • Constructor Details

    • WebAccountFunctions

      public WebAccountFunctions()
  • Method Details

    • getAccount

      public WebAccount getAccount​(java.lang.String loginToken) throws PSException
      Gets a WebAccount object from a specified login token
      Parameters:
      loginToken - is the user's session login token used to validate the user
      Returns:
      WebAccount object holding data corresponding to the provided login token
      Throws:
      PSException
    • getAccount

      public WebAccount getAccount​(long id) throws PSException
      Gets a WebAccount object from an id
      Parameters:
      id - is the webaccount's id
      Returns:
      WebAccount object holding data corresponding to the provided login token
      Throws:
      PSException
    • putAccount

      public void putAccount​(RegisterRequest registerRequest) throws PSException
      Adds a WebAccountFunctions to the database
      Parameters:
      registerRequest - RegisterRequest object that contains the desired login details for a new HttpStatus 409 if the account already exists
      Throws:
      PSException
    • readAccount

      public java.lang.String readAccount​(LoginRequest loginRequest) throws PSException
      Adds a login token to a WebAccountFunctions matching the given username in the database
      Parameters:
      loginRequest - LoginRequest object that contains the desired login details to check
      Throws:
      PSException
    • deleteLoginToken

      public void deleteLoginToken​(java.lang.String loginToken)
      Removes a login token from a WebAccount
      Parameters:
      loginToken - Login token to delete from a WebAccount
    • putSocialIntegration

      public void putSocialIntegration​(PutSocialIntegrationRequest putSocialIntegrationRequest) throws PSException
      Adds a social integration
      Parameters:
      putSocialIntegrationRequest - PutSocialIntegrationRequest Integration request provided from RESTful call
      Throws:
      PSException
    • validateSocialIntegration

      private void validateSocialIntegration​(PutSocialIntegrationRequest putSocialIntegrationRequest) throws PSException
      Checks the validity of a social integration's type and given data
      Parameters:
      putSocialIntegrationRequest - PutSocialIntegrationRequest object containing the contents of this request
      Throws:
      PSException - HttpStatus.BAD_REQUEST if the integration type given was null, or the data did not pass the validity checks
    • saveIntegration

      public void saveIntegration​(PutSocialIntegrationRequest putSocialIntegrationRequest, SocialIntegration socialIntegration)
      Saves social integration data from a request into a given SocialIntegration object
      Parameters:
      putSocialIntegrationRequest - PutSocialIntegrationRequest object generated from Spring
      socialIntegration - SocialIntegration belonging to a current WebAccount
    • getSocialIntegration

      public SocialIntegration getSocialIntegration​(java.lang.String loginToken) throws PSException
      Gets a WebAccount from the given login token, then returns its SocialIntegration
      Parameters:
      loginToken - WebAccount login token
      Returns:
      SocialIntegration belonging to a login token's WebAccount
      Throws:
      PSException
    • putPatreonTokens

      public void putPatreonTokens​(java.lang.String loginToken, java.lang.String accessToken, java.lang.String refreshToken) throws PSException
      Attempts to add Patreon access and refresh tokens into a WebAccount by checking for a matching login token
      Parameters:
      loginToken - WebAccount login token
      accessToken - Patreon access token - can be null
      refreshToken - Patreon refresh token - can be null
      Throws:
      PSException
    • putPatreonTokens

      public void putPatreonTokens​(WebAccount webAccount, java.lang.String accessToken, java.lang.String refreshToken) throws PSException
      Throws:
      PSException
    • getPatreonTokens

      public PatreonTokens getPatreonTokens​(java.lang.String loginToken) throws PSException
      Attempts to acquire Patreon access and refresh tokens by checking for a matching WebAccountFunctions with the given login token
      Parameters:
      loginToken - login token belonging to a WebAccountFunctions
      Returns:
      PatreonTokens containing the access and refresh tokens for the WebAccountFunctions that contains the given login token
      Throws:
      PSException
    • putNewPassword

      public void putNewPassword​(java.lang.String loginToken, java.lang.String currentPassword, java.lang.String newPassword) throws PSException
      Changes the password for a WebAccount.

      Requirements
      • loginToken matches an account
      • currentPassword does not match newPassword
      • currentPassword matches the current password on the WebAccount
      • newPassword does not match any of the OldPasswords for the WebAccount
      Parameters:
      loginToken - login token belonging to a WebAccount
      currentPassword - current password for the WebAccount
      newPassword - desired new password for the WebAccount
      Throws:
      PSException - HttpStatus.UNAUTHORIZED if the given current password is incorrect for the given account, or it does not meet our password requirements. HttpStatus.CONFLICT if the new password matches the current password, or any of the previous three passwords for the account.
    • testy

      public void testy​(java.lang.String loginToken) throws PSException
      Throws:
      PSException
    • ensurePasswordValidity

      private void ensurePasswordValidity​(java.lang.String rawPassword) throws PSException
      Checks if the given raw password meets our password requirements
      Parameters:
      rawPassword - password to check
      Throws:
      PSException - HttpStatus.UNAUTHORIZED if the password does not meet our password requirements
    • findByWebAccountId

      public WebAccount findByWebAccountId​(int webAccountId)
      Gets a WebAccount object from a specified web account id
      Parameters:
      webAccountId - is the id of the web account
      Returns:
      WebAccount object holding data corresponding to the provided web account id