import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
+import org.mxchange.jcoreee.events.helper.clear.HelperCleanupEvent;
+import org.mxchange.jcoreee.events.helper.clear.ObservableHelperCleanupEvent;
import org.mxchange.jcoreee.utils.FacesUtils;
-import org.mxchange.jusercore.events.confirmation.ObservableUserConfirmedAccountEvent;
-import org.mxchange.jusercore.events.confirmation.UserConfirmedAccountEvent;
+import org.mxchange.jusercore.events.user.created.CreatedUserEvent;
+import org.mxchange.jusercore.events.user.created.ObservableCreatedUserEvent;
import org.mxchange.jusercore.exceptions.UserStatusConfirmedException;
import org.mxchange.jusercore.exceptions.UserStatusLockedException;
import org.mxchange.jusercore.model.user.User;
import org.mxchange.jusercore.model.user.UserSessionBeanRemote;
import org.mxchange.jusercore.model.user.status.UserAccountStatus;
+import org.mxchange.juserlogincore.events.confirmation.ObservableUserConfirmedAccountEvent;
+import org.mxchange.juserlogincore.events.confirmation.UserConfirmedAccountEvent;
import org.mxchange.pizzaapplication.beans.BasePizzaController;
import org.mxchange.pizzaapplication.beans.helper.PizzaWebRequestHelperController;
import org.mxchange.pizzaapplication.beans.user.PizzaUserWebSessionController;
* <p>
* @author Roland Häder<roland@mxchange.org>
*/
-@Named ("confirmationLinkController")
+@Named ("userConfirmationLinkController")
@RequestScoped
public class PizzaConfirmationLinkWebRequestBean extends BasePizzaController implements PizzaConfirmationLinkWebRequestController {
@Inject
private PizzaWebRequestHelperController beanHelper;
+ /**
+ * Event being fired when a bean helper should be cleaned
+ */
+ @Inject
+ @Any
+ private Event<ObservableHelperCleanupEvent> cleanHelperEvent;
+
/**
* Confirmation key
*/
@Inject
private PizzaUserWebSessionController userController;
+ /**
+ * Event for when a user instance was created
+ */
+ @Any
+ @Inject
+ private Event<ObservableCreatedUserEvent> userCreatedEvent;
+
/**
* Default constructor
*/
@Override
public void maybeConfirmUserAccount () {
+ // Trace message
+ System.out.println(MessageFormat.format("{0}.maybeConfirmAccount: CALLED!", this.getClass().getSimpleName())); //NOI18N
+
// Is the confirmation key set?
if (this.getConfirmationKey() == null) {
// May be null if not set
// Now try to find the user in user list, first get the whole list
List<User> users = this.userController.allUsers();
+ // Debug message
+ System.out.println(MessageFormat.format("{0}.maybeConfirmAccount: users.size()={1}", this.getClass().getSimpleName(), users.size())); //NOI18N
+
// Get iterator from it
Iterator<User> iterator = users.iterator();
// Get next user
User next = iterator.next();
+ // Debug message
+ System.out.println(MessageFormat.format("{0}.maybeConfirmAccount: this.confirmationKey={1},next.confirmationKey={2}", this.getClass().getSimpleName(), this.getConfirmationKey(), next.getUserConfirmKey())); //NOI18N
+
// Same confirmation key?
if (Objects.equals(this.getConfirmationKey(), next.getUserConfirmKey())) {
+ // Debug message
+ System.out.println(MessageFormat.format("{0}.maybeConfirmAccount: next={1} - Aborting ...", this.getClass().getSimpleName(), next)); //NOI18N
+
// Found it, then set it and abort loop
user = next;
break;
}
}
+ // Debug message
+ System.out.println(MessageFormat.format("{0}.maybeConfirmAccount: user={1}", this.getClass().getSimpleName(), user)); //NOI18N
+
// Is the user instance null?
if ((null == user) || (user.getUserAccountStatus() != UserAccountStatus.UNCONFIRMED)) {
// Then clear this bean and the helper
- this.beanHelper.setUser(null);
+ this.cleanHelperEvent.fire(new HelperCleanupEvent());
} else {
- // Set user ...
- this.beanHelper.setUser(user);
-
- // ... and copy it to the controller
- this.beanHelper.copyUserToController();
-
// Try to confirm it
- this.confirmUserAccount();
+ this.confirmUserAccount(user);
}
+
+ // Trace message
+ System.out.println(MessageFormat.format("{0}.maybeConfirmAccount: EXIT!", this.getClass().getSimpleName())); //NOI18N
}
/**
* Tries to confirm the currently set user instance (in helper).
+ * <p>
+ * @param user User instance
*/
- private void confirmUserAccount () {
- // Get user instance
- User user = this.beanHelper.getUser();
+ private void confirmUserAccount (final User user) {
+ // Trace message
+ System.out.println(MessageFormat.format("{0}.confirmUserAccount: user={1} - CALLED!", this.getClass().getSimpleName(), user)); //NOI18N
// Should be set
if (null == user) {
// Throw NPE
- throw new NullPointerException("user is null");
+ throw new NullPointerException("user is null"); //NOI18N
} else if (user.getUserId() == null) {
// Abort here
throw new NullPointerException("user.userId is null"); //NOI18N
} else if (user.getUserConfirmKey() == null) {
// Throw NPE
throw new NullPointerException("user.userConfirmKey is null"); //NOI18N
+ } else if (user.getUserConfirmKey().isEmpty()) {
+ // Is empty string
+ throw new IllegalArgumentException("user.userConfirmKey is empty"); //NOI18N
}
// Updated user instance
// Get base URL
String baseUrl = FacesUtils.generateBaseUrl();
+ // Debug message
+ System.out.println(MessageFormat.format("{0}.confirmUserAccount: baseUrl={1}", this.getClass().getSimpleName(), baseUrl)); //NOI18N
+
// Confirm account
updatedUser = this.userBean.confirmAccount(user, baseUrl);
+
+ // Debug message
+ System.out.println(MessageFormat.format("{0}.confirmUserAccount: updatedUser={1} - Returned from EJB", this.getClass().getSimpleName(), updatedUser)); //NOI18N
} catch (final UserStatusConfirmedException | UserStatusLockedException ex) {
// Something unexpected happened
throw new FaceletException(MessageFormat.format("Cannot confirm user account {0}", user.getUserName()), ex); //NOI18N
// Fire event that the user has confirmed account
this.userConfirmedEvent.fire(new UserConfirmedAccountEvent(updatedUser));
- // Set it again in helper
- this.beanHelper.setUser(updatedUser);
+ // Debug message
+ System.out.println(MessageFormat.format("{0}.confirmUserAccount: updatedUser={1}", this.getClass().getSimpleName(), updatedUser)); //NOI18N
+
+ // Fire event
+ this.userCreatedEvent.fire(new CreatedUserEvent(updatedUser));
+
+ // Trace message
+ System.out.println(MessageFormat.format("{0}.confirmUserAccount: EXIT!", this.getClass().getSimpleName())); //NOI18N
}
}