import java.text.MessageFormat;
import javax.enterprise.context.SessionScoped;
+import javax.enterprise.event.Event;
+import javax.enterprise.inject.Any;
import javax.faces.view.facelets.FaceletException;
import javax.inject.Inject;
import javax.inject.Named;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import org.mxchange.addressbook.beans.user.UserWebController;
+import org.mxchange.jusercore.events.registration.RegisteredUserEvent;
+import org.mxchange.jusercore.events.registration.UserRegisteredEvent;
import org.mxchange.jusercore.exceptions.DataRepeatMismatchException;
import org.mxchange.jusercore.exceptions.EmailAddressAlreadyRegisteredException;
import org.mxchange.jusercore.exceptions.UserNameAlreadyRegisteredException;
@Inject
private UserWebController userController;
+ /**
+ * An en event fireable when a new user has registered
+ */
+ @Inject
+ @Any
+ private Event<UserRegisteredEvent> registeredEvent;
+
/**
* Default constructor
*/
// Call bean
User registeredUser = this.registerBean.registerUser(user);
- // Copy all data from registered->user
- this.userController.copyUser(registeredUser);
-
- // Add user name and email address
- this.userController.addUserNameEmailAddress(registeredUser);
-
- // Clear all data
- this.userController.clearData();
-
- // Set user id again
- this.userController.setUserId(registeredUser.getUserId());
+ // Fire event
+ this.registeredEvent.fire(new RegisteredUserEvent(registeredUser));
// All fine, redirect to proper page
return "register_done"; //NOI18N
import java.util.Objects;
import javax.annotation.PostConstruct;
import javax.enterprise.context.SessionScoped;
+import javax.enterprise.event.Observes;
import javax.faces.view.facelets.FaceletException;
import javax.inject.Named;
import javax.naming.Context;
import org.mxchange.jphone.phonenumbers.landline.DialableLandLineNumber;
import org.mxchange.jphone.phonenumbers.landline.LandLineNumber;
import org.mxchange.jphone.phonenumbers.smsprovider.SmsProvider;
+import org.mxchange.jusercore.events.registration.UserRegisteredEvent;
import org.mxchange.jusercore.model.user.LoginUser;
import org.mxchange.jusercore.model.user.User;
import org.mxchange.jusercore.model.user.UserSessionBeanRemote;
*/
private String userPasswordRepeat;
-
/**
* Whether the user wants a public profile
*/
}
}
- @Override
- public void addUserNameEmailAddress (final User user) {
+ /**
+ * Adds user's name and email address to bean's internal list. It also
+ * updates the public user list if the user has decided to have a public
+ * profile on registration.
+ * <p>
+ * @param user User instance
+ */
+ private void addUserNameEmailAddress (final User user) {
// Make sure the entry is not added yet
if (this.userNameList.contains(user.getUserName())) {
// Abort here
return Collections.unmodifiableList(this.publicUserList);
}
- @Override
- public void clearData () {
+ /**
+ * Clears all data in this bean
+ */
+ private void clearData () {
// Clear all data
// - personal data
this.setUserId(null);
this.setUserPasswordRepeat(null);
}
- @Override
- public void copyUser (final User user) {
+ /**
+ * Copies given user into the controller
+ * <p>
+ * @param user User instance
+ */
+ private void copyUser (final User user) {
// Copy all fields:
// - base data
this.setUserId(user.getUserId());
return user;
}
+ @Override
+ public void afterRegistration (final @Observes UserRegisteredEvent event) {
+ // event should not be null
+ if (null == event) {
+ // Throw NPE
+ throw new NullPointerException("event is null");
+ } else if (event.getUser() == null) {
+ // Throw NPE again
+ throw new NullPointerException("event.user is null");
+ } else if (event.getUser().getUserId() == null) {
+ // userId is null
+ throw new NullPointerException("event.user.userId is null");
+ } else if (event.getUser().getUserId() < 1) {
+ // Not avalid id
+ throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getUser(), event.getUser().getUserId()));
+ }
+
+ // Get user instance
+ User registeredUser = event.getUser();
+
+ // Copy all data from registered->user
+ this.copyUser(registeredUser);
+
+ // Add user name and email address
+ this.addUserNameEmailAddress(registeredUser);
+
+ // Clear all data
+ this.clearData();
+
+ // Set user id again
+ this.setUserId(registeredUser.getUserId());
+ }
+
@Override
public Date getBirthday () {
return this.birthday;
import org.mxchange.jcontacts.contact.gender.Gender;
import org.mxchange.jcountry.data.Country;
import org.mxchange.jphone.phonenumbers.smsprovider.SmsProvider;
+import org.mxchange.jusercore.events.registration.UserRegisteredEvent;
import org.mxchange.jusercore.model.user.User;
/**
*/
public interface UserWebController extends Serializable {
- /**
- * Adds user's name and email address to bean's internal list. It also
- * updates the public user list if the user has decided to have a public
- * profile on registration.
- * <p>
- * @param user User instance
- */
- void addUserNameEmailAddress (final User user);
-
/**
* All public user profiles
* <p>
*/
List<User> allPublicUsers ();
- /**
- * Clears all data in this bean
- */
- void clearData ();
-
- /**
- * Copies given user into the controller
- * <p>
- * @param user User instance
- */
- void copyUser (final User user);
-
/**
* Creates an instance from all properties
* <p>
* @return Whether at least one user has a public profile
*/
boolean isPublicUserRegistered ();
+
+ /**
+ * Event observer for new user registrations
+ * <p>
+ * @param event User registration event
+ */
+ void afterRegistration (final UserRegisteredEvent event);
}