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.user.PizzaUserWebSessionController;
+import org.mxchange.pizzaapplication.beans.BasePizzaBean;
+import org.mxchange.pizzaapplication.beans.user.PizzaUserWebRequestController;
/**
* A web request bean for confirmation link handling
*/
@Named ("userConfirmationLinkController")
@RequestScoped
-public class PizzaConfirmationLinkWebRequestBean extends BasePizzaController implements PizzaConfirmationLinkWebRequestController {
+public class PizzaConfirmationLinkWebRequestBean extends BasePizzaBean implements PizzaConfirmationLinkWebRequestController {
/**
* Serial number
* User controller
*/
@Inject
- private PizzaUserWebSessionController userController;
+ private PizzaUserWebRequestController userController;
/**
* Event for when a user instance was created
@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
+ final List<User> users = this.userController.allUsers();
// Get iterator from it
- Iterator<User> iterator = users.iterator();
+ final Iterator<User> iterator = users.iterator();
// Init instance
User user = null;
// Then loop through all
while (iterator.hasNext()) {
// 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
+ final User next = iterator.next();
// 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
// Try to confirm it
this.confirmUserAccount(user);
}
-
- // Trace message
- System.out.println(MessageFormat.format("{0}.maybeConfirmAccount: EXIT!", this.getClass().getSimpleName())); //NOI18N
}
/**
* @param user User instance
*/
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
}
// Updated user instance
- User updatedUser;
+ final User updatedUser;
try {
// Get base URL
- String baseUrl = FacesUtils.generateBaseUrl();
-
- // Debug message
- System.out.println(MessageFormat.format("{0}.confirmUserAccount: baseUrl={1}", this.getClass().getSimpleName(), baseUrl)); //NOI18N
+ final String baseUrl = FacesUtils.generateBaseUrl();
// 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));
- // 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
}
}