Package org.ametys.web.usermanagement
Class UserSignupManager
- java.lang.Object
-
- org.ametys.runtime.plugin.component.AbstractLogEnabled
-
- org.ametys.core.datasource.AbstractMyBatisDAO
-
- org.ametys.web.usermanagement.UserSignupManager
-
- All Implemented Interfaces:
LogEnabled,PluginAware,Component,Configurable,Contextualizable,Serviceable
- Direct Known Subclasses:
UserSignupManager
public class UserSignupManager extends AbstractMyBatisDAO
Manages registration and password recovery of users.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classUserSignupManager.LostPasswordErrorEnumeration for different cases of lost password errorsstatic classUserSignupManager.TempUserBean representing a user sign-up request.
-
Field Summary
Fields Modifier and Type Field Description protected I18nUtils_i18nUtilsThe i18n utils.protected URIResolver_pageUriResolverThe page URI resolver.protected PopulationContextHelper_populationContextHelperThe population context helper.protected String_pwdChangeTableThe password change table.protected AmetysObjectResolver_resolverThe ametys object resolver.protected SiteConfigurationExtensionPoint_siteConfThe site configuration extension point.protected SiteManager_siteManagerThe site manager.protected String_tempUsersTableThe temporary users table.protected URIResolverExtensionPoint_uriResolverEPThe ametys object resolver.protected UserManager_userManagerThe user manager.protected UserPopulationDAO_userPopulationDAOThe DAO for user populationsprotected UserSignUpConfiguration_userSignUpConfigurationThe user sign up configurationstatic StringROLEThe component role.static intSIGNUP_ERRORToken return code: undefined error.static intSIGNUP_ERROR_TEMP_EMAIL_ALREADY_EXISTSTemporary signup return code: a user tried to sign-up but the e-mail already exists in the temporary table.static intSIGNUP_ERROR_USER_ALREADY_EXISTSTemporary signup return code: a user tried to sign-up but the FO UsersManager already possesses a user with this e-mail as login.static intSIGNUP_NO_ERRORReturn code which indicates no error.static intSIGNUP_RESET_ERROR_EMAIL_UNKNOWNReset token return code: a user asked for a new token, but no subscription request can be found with this e-mail.static intSIGNUP_TOKEN_EXPIREDToken return code: a user provided a token, but it isn't valid anymore.static intSIGNUP_TOKEN_UNKNOWNToken return code: a user provided a token, but it doesn't exist.-
Fields inherited from class org.ametys.core.datasource.AbstractMyBatisDAO
_manager
-
-
Constructor Summary
Constructors Constructor Description UserSignupManager()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidadditionalSignupOperations(User createdUser, Multimap<String,I18nizableText> errors)Process additional operations after creation of userprotected voidaddPasswordToken(String siteName, String login, String token, String population)Create a user password change request in the database.protected intaddTemporaryUser(String siteName, String email, String token, String population, String userDirectoryId)Create a user sign-up request ("temporary" user) in the database.intchangeUserPassword(String siteName, String login, String token, String newPassword, String population)Change the user password.intcheckPasswordToken(String siteName, String login, String token, String population)Check the password change request token.protected voidcheckPublicSignup(String siteName)Verify that public sign-up is allowed.intcheckToken(String siteName, String email, String token, String population, String userDirectoryId)Check the sign-up request token.voidconfigure(Configuration configuration)ContentgetGTUContent(ZoneItem zoneItem)Get the GTU content Returns null if not found or emptyPagegetGTUPage(ZoneItem zoneItem)Get the GTU page Returns null if not found or emptyPagegetPwdChangePage(String siteName, String language)Get the password change page in a given site and sitemap.AmetysObjectIterable<Page>getPwdChangePages(String siteName, String language)Get all the pages tagged "password change".PagegetSignupPage(String siteName, String language)Get the sign-up page in a given site and sitemap.
If more than one page are tagged "sign-up", return the first.AmetysObjectIterable<Page>getSignupPages(String siteName, String language)Get all the pages tagged "sign-up".ContentgetSuccessContent(ZoneItem zoneItem)Get the success content Returns null if not found or emptyPagegetSuccessPage(ZoneItem zoneItem)Get the GTU page Returns null if not found or emptyprotected UserSignupManager.TempUsergetTempUser(String siteName, String email, String population, String userDirectoryId)Get a temporary user from his site name and e-mail.protected UserSignupManager.TempUsergetTempUser(String siteName, String email, String token, String population, String userDirectoryId)Get a temporary user from his site name, e-mail and/or token.StringgetToken(String siteName, String email, String population, String userDirectoryId)Get a token for temp userbooleanisPublicSignupAllowed(String siteName)Test if public signup is allowed in a site.voidremoveExpiredPasswordTokens()Remove the expired change password request tokens.voidremoveExpiredTokens()Remove the expired sign-up request tokens.protected voidremovePasswordToken(String siteName, String login, String token, String population)Remove the password change request.protected voidremoveTempUser(String siteName, String email, String token, String population, String userDirectoryId)Remove the temporary .UserSignupManager.LostPasswordErrorresetPassword(String siteName, String language, String loginOrEmail, String populationId)Create a reset password request and send a confirmation e-mail.intresetTempSignup(String siteName, String language, String email, String population, String userDirectoryId)Reset a sign-up request: generate a new token and re-send the confirmation e-mail.protected voidsendResetPasswordMail(String siteName, String language, User user, String token)Send a sign-up confirmation link by e-mail.protected voidsendSignupConfirmMail(String siteName, String language, String email, String token)Send a sign-up confirmation link by e-mail.protected voidsendSignupValidatedMail(String siteName, String language, User user)Send a sign-up confirmation link by e-mail.voidservice(ServiceManager serviceManager)intsignup(String siteName, String language, String firstname, String lastname, String email, String token, String password, String population, String userDirectoryId, Multimap<String,I18nizableText> errors)Create the user in the FO UsersManager from his temporary request.inttemporarySignup(String siteName, String language, String email, String population, String userDirectoryId)Validate and store a sign-up request and send a confirmation e-mail.inttemporarySignup(String siteName, String language, String email, String population, String userDirectoryId, boolean sendMail)Validate and store a sign-up request and send a confirmation e-mail.protected voidupdateTempToken(String siteName, String email, String newToken, String population, String userDirectoryId)Update the sign-up request token: reset the date and set a new token.booleanuserExists(String email, String siteName)Tests if the user already exists in the populationsMap<String,Errors>validate(String siteName, String email, Map<String,String> additionalValues)Validate the user subscription data.Map<String,Errors>validatePassword(String siteName, String password, String login, String population)Validate the user password.voidvalidationBeforeSignup(Multimap<String,I18nizableText> errors)Do some validation before signup-
Methods inherited from class org.ametys.core.datasource.AbstractMyBatisDAO
_configureDatasource, _getDataSourceId, _getMyBatisConfiguration, contextualize, getSession, getSession, reload, setPluginInfo
-
Methods inherited from class org.ametys.runtime.plugin.component.AbstractLogEnabled
getLogger, setLogger
-
-
-
-
Field Detail
-
SIGNUP_NO_ERROR
public static final int SIGNUP_NO_ERROR
Return code which indicates no error.- See Also:
- Constant Field Values
-
SIGNUP_ERROR_TEMP_EMAIL_ALREADY_EXISTS
public static final int SIGNUP_ERROR_TEMP_EMAIL_ALREADY_EXISTS
Temporary signup return code: a user tried to sign-up but the e-mail already exists in the temporary table.- See Also:
- Constant Field Values
-
SIGNUP_ERROR_USER_ALREADY_EXISTS
public static final int SIGNUP_ERROR_USER_ALREADY_EXISTS
Temporary signup return code: a user tried to sign-up but the FO UsersManager already possesses a user with this e-mail as login.- See Also:
- Constant Field Values
-
SIGNUP_TOKEN_UNKNOWN
public static final int SIGNUP_TOKEN_UNKNOWN
Token return code: a user provided a token, but it doesn't exist.- See Also:
- Constant Field Values
-
SIGNUP_TOKEN_EXPIRED
public static final int SIGNUP_TOKEN_EXPIRED
Token return code: a user provided a token, but it isn't valid anymore.- See Also:
- Constant Field Values
-
SIGNUP_ERROR
public static final int SIGNUP_ERROR
Token return code: undefined error.- See Also:
- Constant Field Values
-
SIGNUP_RESET_ERROR_EMAIL_UNKNOWN
public static final int SIGNUP_RESET_ERROR_EMAIL_UNKNOWN
Reset token return code: a user asked for a new token, but no subscription request can be found with this e-mail.- See Also:
- Constant Field Values
-
_userManager
protected UserManager _userManager
The user manager.
-
_userPopulationDAO
protected UserPopulationDAO _userPopulationDAO
The DAO for user populations
-
_siteManager
protected SiteManager _siteManager
The site manager.
-
_siteConf
protected SiteConfigurationExtensionPoint _siteConf
The site configuration extension point.
-
_resolver
protected AmetysObjectResolver _resolver
The ametys object resolver.
-
_uriResolverEP
protected URIResolverExtensionPoint _uriResolverEP
The ametys object resolver.
-
_pageUriResolver
protected URIResolver _pageUriResolver
The page URI resolver.
-
_i18nUtils
protected I18nUtils _i18nUtils
The i18n utils.
-
_userSignUpConfiguration
protected UserSignUpConfiguration _userSignUpConfiguration
The user sign up configuration
-
_tempUsersTable
protected String _tempUsersTable
The temporary users table.
-
_pwdChangeTable
protected String _pwdChangeTable
The password change table.
-
_populationContextHelper
protected PopulationContextHelper _populationContextHelper
The population context helper.
-
-
Constructor Detail
-
UserSignupManager
public UserSignupManager()
-
-
Method Detail
-
service
public void service(ServiceManager serviceManager) throws ServiceException
- Specified by:
servicein interfaceServiceable- Overrides:
servicein classAbstractMyBatisDAO- Throws:
ServiceException
-
configure
public void configure(Configuration configuration) throws ConfigurationException
- Specified by:
configurein interfaceConfigurable- Overrides:
configurein classAbstractMyBatisDAO- Throws:
ConfigurationException
-
isPublicSignupAllowed
public boolean isPublicSignupAllowed(String siteName)
Test if public signup is allowed in a site.- Parameters:
siteName- the site to test.- Returns:
- true if public signup is allowed, false otherwise.
-
getSignupPage
public Page getSignupPage(String siteName, String language)
Get the sign-up page in a given site and sitemap.
If more than one page are tagged "sign-up", return the first.- Parameters:
siteName- the site name.language- the sitemap name.- Returns:
- the sign-up page or null if not found.
-
getSignupPages
public AmetysObjectIterable<Page> getSignupPages(String siteName, String language)
Get all the pages tagged "sign-up".- Parameters:
siteName- the site name.language- the sitemap name.- Returns:
- an iterable on all the pages tagged "sign-up".
-
getPwdChangePage
public Page getPwdChangePage(String siteName, String language)
Get the password change page in a given site and sitemap. If more than one page are tagged "password change", return the first.- Parameters:
siteName- the site name.language- the sitemap name.- Returns:
- the password change page or null if not found.
-
getGTUPage
public Page getGTUPage(ZoneItem zoneItem)
Get the GTU page Returns null if not found or empty- Parameters:
zoneItem- the zone item- Returns:
- the GTU page or null.
-
getGTUContent
public Content getGTUContent(ZoneItem zoneItem)
Get the GTU content Returns null if not found or empty- Parameters:
zoneItem- the zone item- Returns:
- the GTU content or null.
-
getSuccessPage
public Page getSuccessPage(ZoneItem zoneItem)
Get the GTU page Returns null if not found or empty- Parameters:
zoneItem- the zone item- Returns:
- the success page or null.
-
getSuccessContent
public Content getSuccessContent(ZoneItem zoneItem)
Get the success content Returns null if not found or empty- Parameters:
zoneItem- the zone item- Returns:
- the success content or null.
-
getPwdChangePages
public AmetysObjectIterable<Page> getPwdChangePages(String siteName, String language)
Get all the pages tagged "password change".- Parameters:
siteName- the site name.language- the sitemap name.- Returns:
- an iterable on all the pages tagged "password change".
-
userExists
public boolean userExists(String email, String siteName) throws UserManagementException
Tests if the user already exists in the populations- Parameters:
email- the e-mail to test.siteName- The site name- Returns:
- true if the user exists, false otherwise.
- Throws:
UserManagementException- if an error occurs.
-
validate
public Map<String,Errors> validate(String siteName, String email, Map<String,String> additionalValues) throws UserManagementException
Validate the user subscription data.- Parameters:
siteName- the site name.email- the user e-mail.additionalValues- the additional user values.- Returns:
- a Map of the Errors by field.
- Throws:
UserManagementException- if an error occurs.
-
validatePassword
public Map<String,Errors> validatePassword(String siteName, String password, String login, String population) throws UserManagementException
Validate the user password.- Parameters:
siteName- the site name.password- the password to validate.login- the login of the userpopulation- The id of the population- Returns:
- a Map of the Errors by field.
- Throws:
UserManagementException- if an error occurs.
-
temporarySignup
public int temporarySignup(String siteName, String language, String email, String population, String userDirectoryId) throws UserManagementException
Validate and store a sign-up request and send a confirmation e-mail.- Parameters:
siteName- the site name.language- the sitemap name.email- the user e-mail address.population- the populationuserDirectoryId- the id of the user directory of the population- Returns:
- a status code indicating success or error.
- Throws:
UserManagementException- if an error occurs.
-
temporarySignup
public int temporarySignup(String siteName, String language, String email, String population, String userDirectoryId, boolean sendMail) throws UserManagementException
Validate and store a sign-up request and send a confirmation e-mail.- Parameters:
siteName- the site name.language- the sitemap name.email- the user e-mail address.population- the populationuserDirectoryId- the id of the user directory of the populationsendMail- Set to false to not send mail at end of process- Returns:
- a status code indicating success or error.
- Throws:
UserManagementException- if an error occurs.
-
getToken
public String getToken(String siteName, String email, String population, String userDirectoryId) throws UserManagementException
Get a token for temp user- Parameters:
siteName- the site name.email- the user e-mail address.population- The id of the populationuserDirectoryId- The id of the user directory of the population- Returns:
- the user token or null if not found
- Throws:
UserManagementException- if an error occurs.
-
resetTempSignup
public int resetTempSignup(String siteName, String language, String email, String population, String userDirectoryId) throws UserManagementException
Reset a sign-up request: generate a new token and re-send the confirmation e-mail.- Parameters:
siteName- the site name.language- the sitemap name.email- the user e-mail address.population- The id of the populationuserDirectoryId- The id of the user directory of the population- Returns:
- a status code indicating success or error.
- Throws:
UserManagementException- if an error occurs.
-
signup
public int signup(String siteName, String language, String firstname, String lastname, String email, String token, String password, String population, String userDirectoryId, Multimap<String,I18nizableText> errors) throws UserManagementException
Create the user in the FO UsersManager from his temporary request.- Parameters:
siteName- the site name.language- the current languagefirstname- the user firstnamelastname- the user lastnameemail- the user e-mail address.token- the request token.password- the user password.population- The id of the populationuserDirectoryId- The id of the user directory of the populationerrors- the errors- Returns:
- a status code indicating success or error.
- Throws:
UserManagementException- if an error occurs.
-
validationBeforeSignup
public void validationBeforeSignup(Multimap<String,I18nizableText> errors)
Do some validation before signup- Parameters:
errors- the map of errors to fill in cause of errors during validation
-
additionalSignupOperations
public void additionalSignupOperations(User createdUser, Multimap<String,I18nizableText> errors) throws UserManagementException
Process additional operations after creation of user- Parameters:
createdUser- the created usererrors- the map of errors to fill in case of errors during additional operations- Throws:
UserManagementException- if an error occurs.
-
resetPassword
public UserSignupManager.LostPasswordError resetPassword(String siteName, String language, String loginOrEmail, String populationId) throws UserManagementException
Create a reset password request and send a confirmation e-mail.- Parameters:
siteName- the site name.language- the sitemap name.loginOrEmail- the user login or email.populationId- the population- Returns:
- a status code indicating success or error.
- Throws:
UserManagementException- if an error occurs.
-
changeUserPassword
public int changeUserPassword(String siteName, String login, String token, String newPassword, String population) throws UserManagementException
Change the user password.- Parameters:
siteName- the site name.login- the user login.token- the password change request token.newPassword- the new password.population- the population- Returns:
- a status code indicating success or error.
- Throws:
UserManagementException- if an error occurs.
-
checkToken
public int checkToken(String siteName, String email, String token, String population, String userDirectoryId) throws UserManagementException
Check the sign-up request token.- Parameters:
siteName- the site name.email- the user e-mail.token- the sign-up request token.population- The id of the populationuserDirectoryId- The id of the user directory of the population- Returns:
- a status code indicating success or error.
- Throws:
UserManagementException- if an error occurs.
-
checkPasswordToken
public int checkPasswordToken(String siteName, String login, String token, String population) throws UserManagementException
Check the password change request token.- Parameters:
siteName- the site name.login- the user login.token- the password change request token.population- the population- Returns:
- a status code indicating success or error.
- Throws:
UserManagementException- if an error occurs.
-
removeExpiredTokens
public void removeExpiredTokens() throws UserManagementException
Remove the expired sign-up request tokens.- Throws:
UserManagementException- if an error occurs.
-
removeExpiredPasswordTokens
public void removeExpiredPasswordTokens() throws UserManagementException
Remove the expired change password request tokens.- Throws:
UserManagementException- if an error occurs.
-
checkPublicSignup
protected void checkPublicSignup(String siteName) throws UserManagementException
Verify that public sign-up is allowed. If not, throw an exception.- Parameters:
siteName- the site name.- Throws:
UserManagementException- if public sign-up is not enabled.
-
addTemporaryUser
protected int addTemporaryUser(String siteName, String email, String token, String population, String userDirectoryId) throws UserManagementException
Create a user sign-up request ("temporary" user) in the database.- Parameters:
siteName- the site name.email- the user e-mail.token- the generated token.population- the populationuserDirectoryId- the id of the user directory of the population- Returns:
- a status code indicating success or error.
- Throws:
UserManagementException- if an error occurs.
-
sendSignupConfirmMail
protected void sendSignupConfirmMail(String siteName, String language, String email, String token) throws UserManagementException
Send a sign-up confirmation link by e-mail.- Parameters:
siteName- the site name.language- the e-mail language.email- the user e-mail.token- the generated token.- Throws:
UserManagementException- if an error occurs.
-
sendSignupValidatedMail
protected void sendSignupValidatedMail(String siteName, String language, User user) throws UserManagementException
Send a sign-up confirmation link by e-mail.- Parameters:
siteName- the site name.language- the e-mail language.user- the created user- Throws:
UserManagementException- if an error occurs.
-
updateTempToken
protected void updateTempToken(String siteName, String email, String newToken, String population, String userDirectoryId) throws UserManagementException
Update the sign-up request token: reset the date and set a new token.- Parameters:
siteName- the site name.email- the user e-mail.newToken- the new token.population- The id of the populationuserDirectoryId- The id of the user directory of the population- Throws:
UserManagementException- if an error occurs.
-
addPasswordToken
protected void addPasswordToken(String siteName, String login, String token, String population) throws UserManagementException
Create a user password change request in the database.- Parameters:
siteName- the site name.login- the user login.token- the generated token.population- the population- Throws:
UserManagementException- if an error occurs.
-
getTempUser
protected UserSignupManager.TempUser getTempUser(String siteName, String email, String population, String userDirectoryId) throws UserManagementException
Get a temporary user from his site name and e-mail.- Parameters:
siteName- the site name.email- The temporary user e-mail. Cannot be null.population- the populationuserDirectoryId- the id of the user directory of the population- Returns:
- the temporary user or null if not found.
- Throws:
UserManagementException- if an error occurs.
-
getTempUser
protected UserSignupManager.TempUser getTempUser(String siteName, String email, String token, String population, String userDirectoryId) throws UserManagementException
Get a temporary user from his site name, e-mail and/or token. At least one of e-mail and token must be provided.- Parameters:
siteName- the site name.email- The temporary user e-mail. Can be null.token- The temporary user token. Can be null.population- the population. Must be not null if email is not nulluserDirectoryId- the id of the user directory of the population. Must be not null if email is not null- Returns:
- the temporary user or null if not found.
- Throws:
UserManagementException- if an error occurs.
-
removeTempUser
protected void removeTempUser(String siteName, String email, String token, String population, String userDirectoryId) throws UserManagementException
Remove the temporary .- Parameters:
siteName- the site name.email- the user e-mail address.token- the request token.population- the populationuserDirectoryId- the id of the user directory of the population- Throws:
UserManagementException- if an error occurs.
-
removePasswordToken
protected void removePasswordToken(String siteName, String login, String token, String population) throws UserManagementException
Remove the password change request.- Parameters:
siteName- the site name.login- the user login.token- the request token.population- the population- Throws:
UserManagementException- if an error occurs.
-
sendResetPasswordMail
protected void sendResetPasswordMail(String siteName, String language, User user, String token) throws UserManagementException
Send a sign-up confirmation link by e-mail.- Parameters:
siteName- the site name.language- the e-mail language.user- the user object.token- the generated token.- Throws:
UserManagementException- if an error occurs.
-
-