Class RegistrationModel
public class RegistrationModel extends FormBaseModel
This model implements the logic for the registration of a new user. It can deal with traditional username/password registration, or registration of pre-identified users using federated login.
The model exposes four fields:
- LoginNameField: the login name (used as an identity for the
Identity.LoginName
provider) – this can be an email if theAuthService
is configured to use email addresses as identity - ChoosePasswordField: the password
- RepeatPasswordField: the password (repeated)
- EmailField: if an email address is to be asked (and is not used as identity).
The largest complexity is in the handling of third party identity providers, which is
initiated with a call to registerIdentified()
.
When a user is re-identified with the same identity, then the model may require that the
(original) user confirms this new identity. The model indicates that this button should be made
visible with isConfirmUserButtonVisible()
,
the action to take is determined by getConfirmIsExistingUser()
, and existingUserConfirmed()
ends this process by merging the new identity into the existing user.
- See Also:
RegistrationWidget
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
RegistrationModel.EmailPolicy
Enumeration for an email policy.static class
RegistrationModel.IdentityConfirmationMethod
Method for confirming to be an existing user.Nested classes/interfaces inherited from class eu.webtoolkit.jwt.WObject
WObject.FormData
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
ChoosePasswordField
Choose Password field.static java.lang.String
EmailField
Email field (if login name is not email)static java.lang.String
RepeatPasswordField
Repeat password field.Fields inherited from class eu.webtoolkit.jwt.auth.FormBaseModel
LoginNameField
-
Constructor Summary
Constructors Constructor Description RegistrationModel(AuthService baseAuth, AbstractUserDatabase users, Login login)
Constructor.RegistrationModel(AuthService baseAuth, AbstractUserDatabase users, Login login, WObject parent)
Constructor. -
Method Summary
Modifier and Type Method Description void
checkUserExists(java.lang.String userName)
Verifies that a user with that name does not yet exist.User
doRegister()
Performs the registration process.void
existingUserConfirmed()
Confirms that the user is indeed an existing user.RegistrationModel.IdentityConfirmationMethod
getConfirmIsExistingUser()
Returns the method to be used to confirm to be an existing user.RegistrationModel.EmailPolicy
getEmailPolicy()
Returns the email policy.User
getExistingUser()
Returns the existing user that needs to be confirmed.Login
getLogin()
Returns the login object.int
getMinLoginNameLength()
Returns the minimum length for a login name.boolean
isConfirmUserButtonVisible()
Returns whether an existing user needs to be confirmed.boolean
isFederatedLoginVisible()
Returns whether federated login options can be shown.boolean
isReadOnly(java.lang.String field)
Returns whether a field is read only.boolean
isVisible(java.lang.String field)
Returns whether a field is visible.boolean
registerIdentified(Identity identity)
Register a user authenticated by an identity provider.void
reset()
Resets the model.void
setEmailPolicy(RegistrationModel.EmailPolicy policy)
Configures whether an email address needs to be entered.void
setMinLoginNameLength(int chars)
Configures a minimum length for a login name.boolean
validateField(java.lang.String field)
Validates a field.WString
validateLoginName(java.lang.String userName)
Validates the login name.static void
validatePasswordsMatchJS(WLineEdit password, WLineEdit password2, WText info2)
Methods inherited from class eu.webtoolkit.jwt.auth.FormBaseModel
addOAuth, addOAuth, addPasswordAuth, getBaseAuth, getOAuth, getPasswordAuth, getUsers, label, loginUser, loginUser, setValid, setValid
Methods inherited from class eu.webtoolkit.jwt.WFormModel
addField, addField, getFields, getValidation, getValidator, getValue, isValid, isValidated, removeField, setReadOnly, setValidated, setValidation, setValidator, setValue, setVisible, validate, valueText
Methods inherited from class eu.webtoolkit.jwt.WObject
addChild, getId, getObjectName, remove, setFormData, setObjectName, tr
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Field Details
-
ChoosePasswordField
public static final java.lang.String ChoosePasswordFieldChoose Password field.- See Also:
- Constant Field Values
-
RepeatPasswordField
public static final java.lang.String RepeatPasswordFieldRepeat password field.- See Also:
- Constant Field Values
-
EmailField
public static final java.lang.String EmailFieldEmail field (if login name is not email)- See Also:
- Constant Field Values
-
-
Constructor Details
-
RegistrationModel
public RegistrationModel(AuthService baseAuth, AbstractUserDatabase users, Login login, WObject parent)Constructor.Creates a new registration model, using a basic authentication service and user database.
The
login
object is used to indicate that an existing user was re-identified, and thus the registration process may be aborted. -
RegistrationModel
Constructor.
-
-
Method Details
-
reset
public void reset()Resets the model.This resets the model to initial values, clearing any entered information (login name, password, pre-identified identity).
- Overrides:
reset
in classWFormModel
-
getLogin
Returns the login object. -
setMinLoginNameLength
public void setMinLoginNameLength(int chars)Configures a minimum length for a login name.The default value is 4.
-
getMinLoginNameLength
public int getMinLoginNameLength()Returns the minimum length for a login name.- See Also:
setMinLoginNameLength(int chars)
-
setEmailPolicy
Configures whether an email address needs to be entered.You may specify whether you want the user to enter an email address.
This has no effect when the IdentityPolicy is EmailAddressIdentity.
The default policy is:
- EmailOptional when email address verification is enabled
- EmailDisabled otherwise
-
getEmailPolicy
Returns the email policy. -
registerIdentified
Register a user authenticated by an identity provider.Using a 3rd party authentication service such as OAuth, a user may be identified which is not yet registered with the web application.
Then, you may still need to allow the user to complete registration, but because the user already is identified and authenticated, this simplifies the registration form, since fields related to authentication can be dropped.
Returns
true
if the given identity was already registered, and has been logged in. -
getExistingUser
Returns the existing user that needs to be confirmed.When a user wishes to register with an identity that corresponds to an existing user, he may be allowd to confirm that he is in fact this existing user.
- See Also:
getConfirmIsExistingUser()
-
getConfirmIsExistingUser
Returns the method to be used to confirm to be an existing user.When the ConfirmExisting field is visible, this returns an appropriate method to use to let the user confirm that he is indeed the identified existing user.
The outcome of this method (if it is an online method, like a password prompt), if successful, should be indicated using
existingUserConfirmed()
.- See Also:
existingUserConfirmed()
-
existingUserConfirmed
public void existingUserConfirmed()Confirms that the user is indeed an existing user.The new identity is added to this existing user (if applicable), and the user is logged in.
-
validateLoginName
Validates the login name.This verifies that the login name is adequate (see also
setMinLoginNameLength()
). -
checkUserExists
public void checkUserExists(java.lang.String userName)Verifies that a user with that name does not yet exist.If a user with that name already exists, it may in fact be the same user that is trying to register again (perhaps using a different identification method). If possible, we allow the user to confirm his identity.
-
doRegister
Performs the registration process. -
isVisible
public boolean isVisible(java.lang.String field)Description copied from class:WFormModel
Returns whether a field is visible.In some cases not all fields of the model need to be shown. This may depend on values input for certain fields, and thus change dynamically. You may specialize this method to indicate that a certain field should be invisible.
The default implementation returns the value set by
setVisible()
.- Overrides:
isVisible
in classWFormModel
-
isReadOnly
public boolean isReadOnly(java.lang.String field)Description copied from class:WFormModel
Returns whether a field is read only.The default implementation returns the value set by
setReadOnly()
- Overrides:
isReadOnly
in classWFormModel
-
validateField
public boolean validateField(java.lang.String field)Description copied from class:WFormModel
Validates a field.The default implementation uses the validator configured for the field to validate the field contents, or if no validator has been configured assumes that the field is valid.
You will typically customize this method for more complex validation cases.
- Overrides:
validateField
in classWFormModel
- See Also:
WFormModel.validate()
-
isConfirmUserButtonVisible
public boolean isConfirmUserButtonVisible()Returns whether an existing user needs to be confirmed.This returns whether the user is being identified as an existing user and he can confirm that he is in fact the same user.
-
isFederatedLoginVisible
public boolean isFederatedLoginVisible()Returns whether federated login options can be shown.This returns whether fields for federated login (such as OAuth) should be shown. These are typically buttons corresponding to identity providers.
The result of a federated authentication procedure should be indicated to
registerIdentified()
. -
validatePasswordsMatchJS
-