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) SecurityConfiguration
securityConfiguration
securityConfiguration is theSecurityConfiguration
that handles encrypting password withBCryptPasswordEncoder
hashing(package private) WebAccountRepository
webAccountRepository
An 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 void
deleteLoginToken(java.lang.String loginToken)
Removes a login token from aWebAccount
private void
ensurePasswordValidity(java.lang.String rawPassword)
Checks if the given raw password meets our password requirementsWebAccount
findByWebAccountId(int webAccountId)
Gets aWebAccount
object from a specified web account idWebAccount
getAccount(long id)
Gets aWebAccount
object from an idWebAccount
getAccount(java.lang.String loginToken)
Gets aWebAccount
object from a specified login tokenPatreonTokens
getPatreonTokens(java.lang.String loginToken)
Attempts to acquire Patreon access and refresh tokens by checking for a matchingWebAccountFunctions
with the given login tokenSocialIntegration
getSocialIntegration(java.lang.String loginToken)
Gets aWebAccount
from the given login token, then returns itsSocialIntegration
void
putAccount(RegisterRequest registerRequest)
Adds aWebAccountFunctions
to the databasevoid
putNewPassword(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 theWebAccount
newPassword does not match any of theOldPasswords
for theWebAccount
void
putPatreonTokens(WebAccount webAccount, java.lang.String accessToken, java.lang.String refreshToken)
void
putPatreonTokens(java.lang.String loginToken, java.lang.String accessToken, java.lang.String refreshToken)
Attempts to add Patreon access and refresh tokens into aWebAccount
by checking for a matching login tokenvoid
putSocialIntegration(PutSocialIntegrationRequest putSocialIntegrationRequest)
Adds a social integrationjava.lang.String
readAccount(LoginRequest loginRequest)
Adds a login token to aWebAccountFunctions
matching the given username in the databasevoid
saveIntegration(PutSocialIntegrationRequest putSocialIntegrationRequest, SocialIntegration socialIntegration)
Saves social integration data from a request into a givenSocialIntegration
objectvoid
testy(java.lang.String loginToken)
private void
validateSocialIntegration(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 theSecurityConfiguration
that handles encrypting password withBCryptPasswordEncoder
hashing
-
-
Constructor Details
-
WebAccountFunctions
public WebAccountFunctions()
-
-
Method Details
-
getAccount
Gets aWebAccount
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
Gets aWebAccount
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
Adds aWebAccountFunctions
to the database- Parameters:
registerRequest
-RegisterRequest
object that contains the desired login details for a newHttpStatus
409 if the account already exists- Throws:
PSException
-
readAccount
Adds a login token to aWebAccountFunctions
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 aWebAccount
- Parameters:
loginToken
- Login token to delete from aWebAccount
-
putSocialIntegration
public void putSocialIntegration(PutSocialIntegrationRequest putSocialIntegrationRequest) throws PSExceptionAdds a social integration- Parameters:
putSocialIntegrationRequest
-PutSocialIntegrationRequest
Integration 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
-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 givenSocialIntegration
object- Parameters:
putSocialIntegrationRequest
-PutSocialIntegrationRequest
object generated from SpringsocialIntegration
-SocialIntegration
belonging to a currentWebAccount
-
getSocialIntegration
Gets aWebAccount
from the given login token, then returns itsSocialIntegration
- Parameters:
loginToken
-WebAccount
login token- Returns:
SocialIntegration
belonging 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 aWebAccount
by checking for a matching login token- Parameters:
loginToken
-WebAccount
login 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 matchingWebAccountFunctions
with the given login token- Parameters:
loginToken
- login token belonging to aWebAccountFunctions
- Returns:
PatreonTokens
containing the access and refresh tokens for theWebAccountFunctions
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 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
OldPasswords
for theWebAccount
- Parameters:
loginToken
- login token belonging to aWebAccount
currentPassword
- current password for theWebAccount
newPassword
- desired new password for theWebAccount
- 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
- Throws:
PSException
-
ensurePasswordValidity
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
Gets aWebAccount
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
-