Package com.patreonshout.jpa
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 Summary
Fields Modifier and Type Field Description (package private) SecurityConfigurationsecurityConfigurationsecurityConfiguration is theSecurityConfigurationthat handles encrypting password withBCryptPasswordEncoderhashing(package private) WebAccountRepositorywebAccountRepositoryAn autowired Spring repository that handles all database CRUD operations with the webaccounts -
Constructor Summary
Constructors Constructor Description WebAccountFunctions() -
Method Summary
Modifier and Type Method Description voiddeleteLoginToken(java.lang.String loginToken)Removes a login token from aWebAccountprivate voidensurePasswordValidity(java.lang.String rawPassword)Checks if the given raw password meets our password requirementsWebAccountfindByWebAccountId(int webAccountId)Gets aWebAccountobject from a specified web account idWebAccountgetAccount(long id)Gets aWebAccountobject from an idWebAccountgetAccount(java.lang.String loginToken)Gets aWebAccountobject from a specified login tokenPatreonTokensgetPatreonTokens(java.lang.String loginToken)Attempts to acquire Patreon access and refresh tokens by checking for a matchingWebAccountFunctionswith the given login tokenSocialIntegrationgetSocialIntegration(java.lang.String loginToken)Gets aWebAccountfrom the given login token, then returns itsSocialIntegrationvoidputAccount(RegisterRequest registerRequest)Adds aWebAccountFunctionsto the databasevoidputNewPassword(java.lang.String loginToken, java.lang.String currentPassword, java.lang.String newPassword)Changes the password for aWebAccount.
Requirements loginToken matches an account currentPassword does not match newPassword currentPassword matches the current password on theWebAccountnewPassword does not match any of theOldPasswordsfor theWebAccountvoidputPatreonTokens(WebAccount webAccount, java.lang.String accessToken, java.lang.String refreshToken)voidputPatreonTokens(java.lang.String loginToken, java.lang.String accessToken, java.lang.String refreshToken)Attempts to add Patreon access and refresh tokens into aWebAccountby checking for a matching login tokenvoidputSocialIntegration(PutSocialIntegrationRequest putSocialIntegrationRequest)Adds a social integrationjava.lang.StringreadAccount(LoginRequest loginRequest)Adds a login token to aWebAccountFunctionsmatching the given username in the databasevoidsaveIntegration(PutSocialIntegrationRequest putSocialIntegrationRequest, SocialIntegration socialIntegration)Saves social integration data from a request into a givenSocialIntegrationobjectvoidtesty(java.lang.String loginToken)private voidvalidateSocialIntegration(PutSocialIntegrationRequest putSocialIntegrationRequest)Checks the validity of a social integration's type and given dataMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Field Details
-
webAccountRepository
An autowired Spring repository that handles all database CRUD operations with the webaccounts -
securityConfiguration
securityConfiguration is theSecurityConfigurationthat handles encrypting password withBCryptPasswordEncoderhashing
-
-
Constructor Details
-
WebAccountFunctions
public WebAccountFunctions()
-
-
Method Details
-
getAccount
Gets aWebAccountobject from a specified login token- Parameters:
loginToken- is the user's session login token used to validate the user- Returns:
WebAccountobject holding data corresponding to the provided login token- Throws:
PSException
-
getAccount
Gets aWebAccountobject from an id- Parameters:
id- is the webaccount's id- Returns:
WebAccountobject holding data corresponding to the provided login token- Throws:
PSException
-
putAccount
Adds aWebAccountFunctionsto the database- Parameters:
registerRequest-RegisterRequestobject that contains the desired login details for a newHttpStatus409 if the account already exists- Throws:
PSException
-
readAccount
Adds a login token to aWebAccountFunctionsmatching the given username in the database- Parameters:
loginRequest-LoginRequestobject that contains the desired login details to check- Throws:
PSException
-
deleteLoginToken
public void deleteLoginToken(java.lang.String loginToken)Removes a login token from aWebAccount- Parameters:
loginToken- Login token to delete from aWebAccount
-
putSocialIntegration
public void putSocialIntegration(PutSocialIntegrationRequest putSocialIntegrationRequest) throws PSExceptionAdds a social integration- Parameters:
putSocialIntegrationRequest-PutSocialIntegrationRequestIntegration request provided from RESTful call- Throws:
PSException
-
validateSocialIntegration
private void validateSocialIntegration(PutSocialIntegrationRequest putSocialIntegrationRequest) throws PSExceptionChecks the validity of a social integration's type and given data- Parameters:
putSocialIntegrationRequest-PutSocialIntegrationRequestobject containing the contents of this request- Throws:
PSException-HttpStatus.BAD_REQUESTif 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 givenSocialIntegrationobject- Parameters:
putSocialIntegrationRequest-PutSocialIntegrationRequestobject generated from SpringsocialIntegration-SocialIntegrationbelonging to a currentWebAccount
-
getSocialIntegration
Gets aWebAccountfrom the given login token, then returns itsSocialIntegration- Parameters:
loginToken-WebAccountlogin token- Returns:
SocialIntegrationbelonging to a login token'sWebAccount- Throws:
PSException
-
putPatreonTokens
public void putPatreonTokens(java.lang.String loginToken, java.lang.String accessToken, java.lang.String refreshToken) throws PSExceptionAttempts to add Patreon access and refresh tokens into aWebAccountby checking for a matching login token- Parameters:
loginToken-WebAccountlogin tokenaccessToken- Patreon access token - can be nullrefreshToken- 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
Attempts to acquire Patreon access and refresh tokens by checking for a matchingWebAccountFunctionswith the given login token- Parameters:
loginToken- login token belonging to aWebAccountFunctions- Returns:
PatreonTokenscontaining the access and refresh tokens for theWebAccountFunctionsthat contains the given login token- Throws:
PSException
-
putNewPassword
public void putNewPassword(java.lang.String loginToken, java.lang.String currentPassword, java.lang.String newPassword) throws PSExceptionChanges the password for aWebAccount.
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
OldPasswordsfor theWebAccount
- Parameters:
loginToken- login token belonging to aWebAccountcurrentPassword- current password for theWebAccountnewPassword- desired new password for theWebAccount- Throws:
PSException-HttpStatus.UNAUTHORIZEDif the given current password is incorrect for the given account, or it does not meet our password requirements.HttpStatus.CONFLICTif the new password matches the current password, or any of the previous three passwords for the account.
-
testy
- Throws:
PSException
-
ensurePasswordValidity
Checks if the given raw password meets our password requirements- Parameters:
rawPassword- password to check- Throws:
PSException-HttpStatus.UNAUTHORIZEDif the password does not meet our password requirements
-
findByWebAccountId
Gets aWebAccountobject from a specified web account id- Parameters:
webAccountId- is the id of the web account- Returns:
WebAccountobject holding data corresponding to the provided web account id
-