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
Manages registration and password recovery of users.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic enum
Enumeration for different cases of lost password errorsstatic class
Bean representing a user sign-up request. -
Field Summary
Modifier and TypeFieldDescriptionprotected I18nUtils
The i18n utils.protected URIResolver
The page URI resolver.protected PopulationContextHelper
The population context helper.protected String
The password change table.protected AmetysObjectResolver
The ametys object resolver.protected SiteConfigurationExtensionPoint
The site configuration extension point.protected SiteManager
The site manager.protected String
The temporary users table.protected URIResolverExtensionPoint
The ametys object resolver.protected UserManager
The user manager.protected UserPopulationDAO
The DAO for user populationsprotected UserSignUpConfiguration
The user sign up configurationstatic final String
The component role.static final int
Token return code: undefined error.static final int
Temporary signup return code: a user tried to sign-up but the e-mail already exists in the temporary table.static final int
Temporary signup return code: a user tried to sign-up but the FO UsersManager already possesses a user with this e-mail as login.static final int
Return code which indicates no error.static final int
Reset token return code: a user asked for a new token, but no subscription request can be found with this e-mail.static final int
Token return code: a user provided a token, but it isn't valid anymore.static final int
Token return code: a user provided a token, but it doesn't exist.Fields inherited from class org.ametys.core.datasource.AbstractMyBatisDAO
_manager
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
additionalSignupOperations
(User createdUser, Multimap<String, I18nizableText> errors) Process additional operations after creation of userprotected void
addPasswordToken
(String siteName, String login, String token, String population) Create a user password change request in the database.protected int
addTemporaryUser
(String siteName, String email, String token, String population, String userDirectoryId) Create a user sign-up request ("temporary" user) in the database.int
changeUserPassword
(String siteName, String login, String token, String newPassword, String population) Change the user password.int
checkPasswordToken
(String siteName, String login, String token, String population) Check the password change request token.protected void
checkPublicSignup
(String siteName) Verify that public sign-up is allowed.int
Check the sign-up request token.void
configure
(Configuration configuration) getGTUContent
(ZoneItem zoneItem) Get the GTU content Returns null if not found or emptygetGTUPage
(ZoneItem zoneItem) Get the GTU page Returns null if not found or emptygetPwdChangePage
(String siteName, String language) Get the password change page in a given site and sitemap.getPwdChangePages
(String siteName, String language) Get all the pages tagged "password change".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.getSignupPages
(String siteName, String language) Get all the pages tagged "sign-up".getSuccessContent
(ZoneItem zoneItem) Get the success content Returns null if not found or emptygetSuccessPage
(ZoneItem zoneItem) Get the GTU page Returns null if not found or emptyprotected UserSignupManager.TempUser
getTempUser
(String siteName, String email, String population, String userDirectoryId) Get a temporary user from his site name and e-mail.protected UserSignupManager.TempUser
Get a temporary user from his site name, e-mail and/or token.Get a token for temp usergetUserIfHeExists
(String email, String siteName) Get the user from email if he/she exists in the populationsboolean
isPublicSignupAllowed
(String siteName) Test if public signup is allowed in a site.void
Remove the expired change password request tokens.void
Remove the expired sign-up request tokens.protected void
removePasswordToken
(String siteName, String login, String token, String population) Remove the password change request.protected void
removeTempUser
(String siteName, String email, String token, String population, String userDirectoryId) Remove the temporary .resetPassword
(String siteName, String language, String loginOrEmail, String populationId) Create a reset password request and send a confirmation e-mail.int
resetTempSignup
(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 void
sendResetPasswordMail
(String siteName, String language, User user, String token) Send a sign-up confirmation link by e-mail.protected void
sendSignupConfirmMail
(String siteName, String language, String email, String token) Send a sign-up confirmation link by e-mail.protected void
sendSignupValidatedMail
(String siteName, String language, User user) Send a sign-up confirmation link by e-mail.void
service
(ServiceManager serviceManager) int
signup
(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.int
temporarySignup
(String siteName, String language, String email, String population, String userDirectoryId) Validate and store a sign-up request and send a confirmation e-mail.int
temporarySignup
(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 void
updateTempToken
(String siteName, String email, String newToken, String population, String userDirectoryId) Update the sign-up request token: reset the date and set a new token.boolean
userExists
(String email, String siteName) Tests if the user already exists in the populationsValidate the user subscription data.validatePassword
(String siteName, String password, String login, String population) Validate the user password.void
Do some validation before signupMethods 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 Details
-
ROLE
The component role. -
SIGNUP_NO_ERROR
Return code which indicates no error.- See Also:
-
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:
-
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:
-
SIGNUP_TOKEN_UNKNOWN
Token return code: a user provided a token, but it doesn't exist.- See Also:
-
SIGNUP_TOKEN_EXPIRED
Token return code: a user provided a token, but it isn't valid anymore.- See Also:
-
SIGNUP_ERROR
Token return code: undefined error.- See Also:
-
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:
-
_userManager
The user manager. -
_userPopulationDAO
The DAO for user populations -
_siteManager
The site manager. -
_siteConf
The site configuration extension point. -
_resolver
The ametys object resolver. -
_uriResolverEP
The ametys object resolver. -
_pageUriResolver
The page URI resolver. -
_i18nUtils
The i18n utils. -
_userSignUpConfiguration
The user sign up configuration -
_tempUsersTable
The temporary users table. -
_pwdChangeTable
The password change table. -
_populationContextHelper
The population context helper.
-
-
Constructor Details
-
UserSignupManager
public UserSignupManager()
-
-
Method Details
-
service
- Specified by:
service
in interfaceServiceable
- Overrides:
service
in classAbstractMyBatisDAO
- Throws:
ServiceException
-
configure
- Specified by:
configure
in interfaceConfigurable
- Overrides:
configure
in classAbstractMyBatisDAO
- Throws:
ConfigurationException
-
isPublicSignupAllowed
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
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
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
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
Get the GTU page Returns null if not found or empty- Parameters:
zoneItem
- the zone item- Returns:
- the GTU page or null.
-
getGTUContent
Get the GTU content Returns null if not found or empty- Parameters:
zoneItem
- the zone item- Returns:
- the GTU content or null.
-
getSuccessPage
Get the GTU page Returns null if not found or empty- Parameters:
zoneItem
- the zone item- Returns:
- the success page or null.
-
getSuccessContent
Get the success content Returns null if not found or empty- Parameters:
zoneItem
- the zone item- Returns:
- the success content or null.
-
getPwdChangePages
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".
-
getUserIfHeExists
public Optional<User> getUserIfHeExists(String email, String siteName) throws UserManagementException, NotUniqueUserException Get the user from email if he/she exists in the populations- Parameters:
email
- the e-mail to test.siteName
- The site name- Returns:
- the user if the user exists, empty otherwise.
- Throws:
UserManagementException
- if an error occurs.NotUniqueUserException
- if several user respond to the email
-
userExists
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 UserManagementExceptionValidate 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 UserManagementExceptionCreate 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
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 UserManagementExceptionProcess 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
Remove the expired sign-up request tokens.- Throws:
UserManagementException
- if an error occurs.
-
removeExpiredPasswordTokens
Remove the expired change password request tokens.- Throws:
UserManagementException
- if an error occurs.
-
checkPublicSignup
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.
-