import javax.naming.InitialContext;
import javax.naming.NamingException;
import org.mxchange.addressbook.beans.login.UserLoginWebController;
-import org.mxchange.addressbook.events.AddressbookLoadedEvent;
+import org.mxchange.addressbook.events.addressbook.AddressbookLoadedEvent;
import org.mxchange.addressbook.exceptions.AddressbookNameAlreadyUsedException;
import org.mxchange.addressbook.model.addressbook.Addressbook;
import org.mxchange.addressbook.model.addressbook.AddressbookSessionBeanRemote;
import org.mxchange.addressbook.model.addressbook.entry.AddressbookEntry;
import org.mxchange.addressbook.model.addressbook.shared.ShareableAddressbook;
import org.mxchange.addressbook.model.addressbook.status.AddressbokStatus;
+import org.mxchange.jusercore.events.login.UserLoggedInEvent;
import org.mxchange.jusercore.model.user.User;
/**
// Is the user logged-in?
if (this.loginController.isUserLoggedIn()) {
- // Fill list with entries
- this.usersAddressbooks = this.addressbookBean.getUsersList(this.loginController.getLoggedInUser());
+ // Initialize list
+ this.initAddressbookList();
}
// TODO Initialize list from bean with just one call
// Return status
return isFound;
}
+
+ @Override
+ public void afterLoginEvent (final @Observes UserLoggedInEvent event) {
+ // Is the user logged in?
+ if (null == event) {
+ // Is null
+ throw new NullPointerException("event is null");
+ } else if (event.getUser() == null) {
+ // user is null
+ throw new NullPointerException("event.user is null");
+ } else if (!event.getUser().equals(this.loginController.getLoggedInUser())) {
+ // Not matching
+ throw new IllegalStateException("event.user and loginController.loggedInUser don't match.");
+ } else if (!this.loginController.isUserLoggedIn()) {
+ // Not logged in
+ throw new FaceletException("This method can only be called as logged-in user."); //NOI18N
+ }
+
+ // Init user's address book list
+ this.initAddressbookList();
+ }
+
+ /**
+ * Initializes the user user's address book list
+ */
+ private void initAddressbookList () {
+ // Fill list with entries
+ this.usersAddressbooks = this.addressbookBean.getUsersList(this.loginController.getLoggedInUser());
+ }
}
import java.io.Serializable;
import java.util.Calendar;
import java.util.List;
-import org.mxchange.addressbook.events.AddressbookLoadedEvent;
+import org.mxchange.addressbook.events.addressbook.AddressbookLoadedEvent;
import org.mxchange.addressbook.model.addressbook.Addressbook;
import org.mxchange.addressbook.model.addressbook.entry.AddressbookEntry;
import org.mxchange.addressbook.model.addressbook.shared.ShareableAddressbook;
+import org.mxchange.jusercore.events.login.UserLoggedInEvent;
import org.mxchange.jusercore.model.user.User;
/**
* @return Count of user's shared address books
*/
Integer countAllUserSharedAddressbooks (final User user);
+
+ /**
+ * This method is called when a user has successfully logged in his/her
+ * account.
+ * <p>
+ * @param event
+ */
+ void afterLoginEvent (final UserLoggedInEvent event);
}
import java.util.Objects;
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 org.mxchange.addressbook.beans.user.UserWebController;
import org.mxchange.jusercore.container.login.LoginContainer;
import org.mxchange.jusercore.container.login.UserLoginContainer;
+import org.mxchange.jusercore.events.login.UserLoggedInEvent;
+import org.mxchange.jusercore.events.login.UserLoginEvent;
import org.mxchange.jusercore.exceptions.UserNotFoundException;
import org.mxchange.jusercore.exceptions.UserPasswordMismatchException;
import org.mxchange.jusercore.exceptions.UserStatusLockedException;
*/
private UserLoginSessionBeanRemote loginBean;
+ /**
+ * Event fired when user has logged in
+ */
+ @Inject
+ @Any
+ private Event<UserLoggedInEvent> loginEvent;
+
/**
* Template type for pages that might be displayed in guest area and login
* area. Default is guest area.
// Set template to "login"
this.setTemplateType("login"); //NOI18N
+ // Fire event away. Keep this last before return statement.
+ this.loginEvent.fire(new UserLoginEvent(confirmedUser));
+
// All fine
return "login"; //NOI18N
} catch (final UserNotFoundException | UserStatusLockedException | UserStatusUnconfirmedException | UserPasswordMismatchException ex) {
// Trace message
// NOISY: System.out.println(MessageFormat.format("UserLoginWebBean:isUserLoggedIn: this.userLoggedIn={0} - EXIT!", this.userLoggedIn));
-
// Return it
return this.userLoggedIn;
}