*/
package org.mxchange.jjobs.beans.user.register;
-import java.text.MessageFormat;
import javax.annotation.PostConstruct;
import javax.enterprise.context.SessionScoped;
import javax.enterprise.event.Event;
import org.mxchange.jjobs.beans.features.JobsFeaturesWebApplicationController;
import org.mxchange.jjobs.beans.user.JobsAdminUserWebRequestController;
import org.mxchange.jjobs.beans.user.JobsUserWebSessionController;
-import org.mxchange.jusercore.events.registration.ObservableUserRegisteredEvent;
-import org.mxchange.jusercore.events.registration.UserRegisteredEvent;
+import org.mxchange.jusercore.events.user.clear.password.ClearUserPasswordEvent;
+import org.mxchange.jusercore.events.user.clear.password.ObservableClearUserPasswordEvent;
+import org.mxchange.jusercore.events.user.clear.username.ClearUserNameEvent;
+import org.mxchange.jusercore.events.user.clear.username.ObservableClearUserNameEvent;
import org.mxchange.jusercore.exceptions.DataRepeatMismatchException;
import org.mxchange.jusercore.exceptions.EmailAddressAlreadyRegisteredException;
import org.mxchange.jusercore.exceptions.UserNameAlreadyRegisteredException;
import org.mxchange.jusercore.model.user.User;
-import org.mxchange.jusercore.model.user.UserUtils;
-import org.mxchange.jusercore.model.user.register.UserRegistrationSessionBeanRemote;
+import org.mxchange.jusercore.model.user.password_history.PasswordHistory;
+import org.mxchange.jusercore.model.user.password_history.UserPasswordHistory;
import org.mxchange.jusercore.model.user.status.UserAccountStatus;
+import org.mxchange.juserlogincore.events.registration.ObservableUserRegisteredEvent;
+import org.mxchange.juserlogincore.events.registration.UserRegisteredEvent;
+import org.mxchange.juserlogincore.events.user.password_change.ObservableUpdatedUserPasswordEvent;
+import org.mxchange.juserlogincore.events.user.password_change.UpdatedUserPasswordEvent;
+import org.mxchange.juserlogincore.login.UserLoginUtils;
+import org.mxchange.juserlogincore.model.user.register.UserRegistrationSessionBeanRemote;
/**
* A web bean for user registration
private JobsUserWebSessionController userController;
/**
- * An en event fireable when a new user has registered
+ * An event being fired when a user password was changed
+ */
+ @Inject
+ @Any
+ private Event<ObservableUpdatedUserPasswordEvent> userPasswordChangedEvent;
+
+ /**
+ * An event being fired when a user name should be cleared
+ */
+ @Inject
+ @Any
+ private Event<ObservableClearUserNameEvent> clearUserNameEvent;
+
+ /**
+ * An event being fired when a user password should be cleared
+ */
+ @Inject
+ @Any
+ private Event<ObservableClearUserPasswordEvent> clearUserPasswordEvent;
+
+ /**
+ * An event being fired when a new user has registered
*/
@Inject
@Any
super();
}
- @Override
+ /**
+ * Registers the user, if not found. Otherwise this method should throw an
+ * exception.
+ * <p>
+ * @return Redirection target
+ */
public String doFinishRegistration () {
// Is registration enabled?
if (!this.featureController.isFeatureEnabled("user_registration")) { //NOI18N
} else if (!this.userController.isRequiredPersonalDataSet()) {
// Not all required fields are set
throw new FaceletException("Not all required fields are set."); //NOI18N
- } else if ((this.featureController.isFeatureEnabled("user_name_required")) && (this.userController.isUserNameRegistered(user))) { //NOI18N
+ } else if ((this.featureController.isFeatureEnabled("user_login_require_user_name")) && (this.userController.isUserNameRegistered(user))) { //NOI18N
// Is multi-page enabled?
if (this.featureController.isFeatureEnabled("user_register_multiple_page")) { //NOI18N
// User name is already used, should not happen here
throw new FaceletException(new UserNameAlreadyRegisteredException(user));
} else {
- // May happen here, reset field
- this.userController.setUserName(null);
+ // May happen here, fire event
+ this.clearUserNameEvent.fire(new ClearUserNameEvent());
+
+ // Output message
this.showFacesMessage("form_register_single:userName", "ERROR_USER_NAME_ALREADY_USED"); //NOI18N
return ""; //NOI18N
}
throw new FaceletException(new EmailAddressAlreadyRegisteredException(user));
} else {
// May happen here, reset fields
- this.contactController.setEmailAddress(null);
- this.contactController.setEmailAddressRepeat(null);
+ this.contactController.clearEmailAddresses();
this.showFacesMessage("form_register_single:emailAddressRepeat", "ERROR_EMAIL_ADDRESS_ALREADY_USED"); //NOI18N
return ""; //NOI18N
}
// Is multi-page enabled?
if (this.featureController.isFeatureEnabled("user_register_multiple_page")) { //NOI18N
// Not same email address entered, should not happen here
- throw new FaceletException(new DataRepeatMismatchException(MessageFormat.format("Email addresses not matching: {0} != {1}", this.contactController.getEmailAddress(), this.contactController.getEmailAddressRepeat()))); //NOI18N
+ throw new FaceletException(new DataRepeatMismatchException("Email addresses not matching.")); //NOI18N
} else {
// May happen here, reset fields
- this.contactController.setEmailAddress(null);
- this.contactController.setEmailAddressRepeat(null);
+ this.contactController.clearEmailAddresses();
this.showFacesMessage("form_register_single:emailAddressRepeat", "ERROR_EMAIL_ADDRESSES_MISMATCHING"); //NOI18N
return ""; //NOI18N
}
throw new FaceletException(new DataRepeatMismatchException("Passwords not matching.")); //NOI18N
} else if (this.userController.ifBothPasswordsEmptyAllowed()) {
// Both passwords are left empty and is allowed, then generate a random password
- randomPassword = UserUtils.createRandomPassword(JobsUserWebSessionController.MINIMUM_PASSWORD_LENGTH);
+ randomPassword = UserLoginUtils.createRandomPassword(JobsUserWebSessionController.MINIMUM_PASSWORD_LENGTH);
- // Set it in both fields
- this.userController.setUserPassword(randomPassword);
- this.userController.setUserPasswordRepeat(randomPassword);
+ // Generate (ignored) password-history
+ PasswordHistory passwordHistory = new UserPasswordHistory(randomPassword, user);
+
+ // Fire event
+ this.userPasswordChangedEvent.fire(new UpdatedUserPasswordEvent(passwordHistory, randomPassword));
}
}
// Encrypt password
- String encryptedPassword = UserUtils.encryptPassword(this.userController.getUserPassword());
+ String encryptedPassword = UserLoginUtils.encryptPassword(this.userController.getUserPassword());
// Set it here
user.setUserEncryptedPassword(encryptedPassword);
}
}
- @Override
+ /**
+ * Handles registration request send from first page. The (maybe) entered
+ * user name and email address is not used and that privacy and T&C are
+ * accepted.
+ * <p>
+ * @return Redirect
+ */
public String doRegisterMultiPage1 () {
// Is registration enabled?
if (!this.featureController.isFeatureEnabled("user_registration")) { //NOI18N
if (null == user) {
// user must be set
throw new NullPointerException("user is null after createUserInstance() was called"); //NOI18N
- } else if ((this.featureController.isFeatureEnabled("user_name_required")) && (this.userController.isUserNameRegistered(user))) { //NOI18N
+ } else if ((this.featureController.isFeatureEnabled("user_login_require_user_name")) && (this.userController.isUserNameRegistered(user))) { //NOI18N
// User name is already used, so clear it
- this.userController.setUserName(null);
+ this.clearUserNameEvent.fire(new ClearUserNameEvent());
+
+ // Output message
this.showFacesMessage("form_register_page1:userName", "ERROR_USER_NAME_ALREADY_USED"); //NOI18N
return ""; //NOI18N
} else if (!this.contactController.isSameEmailAddressEntered()) {
// Not same email address entered, clear both
- this.contactController.setEmailAddress(null);
- this.contactController.setEmailAddressRepeat(null);
+ this.contactController.clearEmailAddresses();
this.showFacesMessage("form_register_page1:emailAddressRepeat", "ERROR_EMAIL_ADDRESSES_MISMATCHING"); //NOI18N
return ""; //NOI18N
} else if (!this.userController.isSamePasswordEntered()) {
// Is multi-page enabled?
if (this.featureController.isFeatureEnabled("user_register_multiple_page")) { //NOI18N
// Unset both
- this.userController.setUserPassword(null);
- this.userController.setUserPasswordRepeat(null);
+ this.clearUserPasswordEvent.fire(new ClearUserPasswordEvent());
// Output faces message
this.showFacesMessage("form_register_page1:userPassword", "ERROR_USER_PASSWORD_EMPTY"); //NOI18N
return ""; //NOI18N
} else if (this.userController.ifBothPasswordsEmptyAllowed()) {
// Both passwords are left empty and is allowed, then generate a random password
- String randomPassword = UserUtils.createRandomPassword(JobsUserWebSessionController.MINIMUM_PASSWORD_LENGTH);
+ String randomPassword = UserLoginUtils.createRandomPassword(JobsUserWebSessionController.MINIMUM_PASSWORD_LENGTH);
+
+ // Generate (ignored) password-history
+ PasswordHistory passwordHistory = new UserPasswordHistory(randomPassword, user);
- // Set it in both fields
- this.userController.setUserPassword(randomPassword);
- this.userController.setUserPasswordRepeat(randomPassword);
+ // Fire event
+ this.userPasswordChangedEvent.fire(new UpdatedUserPasswordEvent(passwordHistory, randomPassword));
}
}
// Check if email address is registered
if (this.contactController.isEmailAddressRegistered(user.getUserContact())) {
// Email address has already been taken, clear both
- this.contactController.setEmailAddress(null);
- this.contactController.setEmailAddressRepeat(null);
+ this.contactController.clearEmailAddresses();
this.showFacesMessage("form_register_page1:emailAddress", "ERROR_EMAIL_ADDRESS_ALREADY_USED"); //NOI18N
return ""; //NOI18N
}
// Now only redirect to next page as the JSF does it
- return "register_page2"; //NOI18N
+ return "user_register_page2"; //NOI18N
}
/**
Context context = new InitialContext();
// Try to lookup
- this.registerBean = (UserRegistrationSessionBeanRemote) context.lookup("java:global/jjobs-ejb/register!org.mxchange.jusercore.model.register.UserRegistrationSessionBeanRemote"); //NOI18N
+ this.registerBean = (UserRegistrationSessionBeanRemote) context.lookup("java:global/jjobs-ejb/userRegistration!org.mxchange.juserlogincore.model.user.register.UserRegistrationSessionBeanRemote"); //NOI18N
} catch (final NamingException ex) {
// Continue to throw
throw new FaceletException(ex);