}
@Override
- public String doChangePersonalData () throws UserPasswordMismatchException {
+ public String doChangePersonalData () {
// This method shall only be called if the user is logged-in
if (!this.loginController.isUserLoggedIn()) {
// Not logged-in
throw new FaceletException("Not all required fields are set."); //NOI18N
} else if (!this.loginController.ifCurrentPasswordMatches()) {
// Password not matching
- throw new UserPasswordMismatchException(this.loginController.getLoggedInUser());
+ throw new FaceletException(new UserPasswordMismatchException(this.loginController.getLoggedInUser()));
}
// Get user instance
return "login_data_saved"; //NOI18N
}
+ @Override
+ public String doChangeEmailAddress () {
+ // This method shall only be called if the user is logged-in
+ if (!this.loginController.isUserLoggedIn()) {
+ // Not logged-in
+ throw new IllegalStateException("User is not logged-in"); //NOI18N
+ } else if (!this.isRequiredChangeEmailAddressSet()) {
+ // Not all required fields are set
+ throw new FaceletException("Not all required fields are set."); //NOI18N
+ } else if (!Objects.equals(this.getEmailAddress1(), this.getEmailAddress2())) {
+ // Email address 1+2 mismatch
+ throw new FaceletException("Email address 1/2 are mismatching."); //NOI18N
+ } else if (!this.loginController.ifCurrentPasswordMatches()) {
+ // Password not matching
+ throw new FaceletException(new UserPasswordMismatchException(this.loginController.getLoggedInUser()));
+ }
+
+ // Get user instance
+ User user = this.loginController.getLoggedInUser();
+
+ // It should be there, so run some tests on it
+ assert (user instanceof User) : "Instance loginController.loggedInUser is null";
+ assert (user.getUserId() instanceof Long) : "Instance loginController.loggedInUser.userId is null";
+ assert (user.getUserId() > 0) : MessageFormat.format("loginController.loggedInUser.userId={0} is invalid", user.getUserId());
+ assert (user.getUserContact() instanceof Contact) : "Instance loginController.loggedInUser.userContact is null";
+ assert (user.getUserContact().getContactId() instanceof Long) : "Instance loginController.userContact.contactId is null";
+ assert (user.getUserContact().getContactId() > 0) : MessageFormat.format("Instance loginController.userContact.contactId={0} is invalid", user.getUserContact().getContactId());
+
+ // Update email address
+ user.getUserContact().setContactEmailAddress(this.getEmailAddress1());
+
+ // Call EJB
+ this.userBean.updateEmailAddress(user);
+
+ // All fine
+ return "login_data_saved"; //NOI18N
+ }
+
@Override
public void afterRegistrationEvent (final @Observes UserRegisteredEvent event) {
// Trace message
(this.getCity() != null));
}
+ @Override
+ public boolean isRequiredChangeEmailAddressSet () {
+ return ((this.getEmailAddress1() != null) &&
+ (this.getEmailAddress2() != null));
+ }
+
@Override
public boolean isSameEmailAddressEntered () {
return (Objects.equals(this.getEmailAddress(), this.getEmailAddressRepeat()));
*/
boolean isRequiredChangePersonalDataSet ();
+ /**
+ * Checks whether all required are set for changing email address
+ * <p>
+ * @return Whether the required personal data is set
+ */
+ boolean isRequiredChangeEmailAddressSet ();
+
/**
* Checks whether same email addresses have been entered
* <p>
* <p>
* @throws UserPasswordMismatchException If the entered password doesn't match
*/
- String doChangePersonalData () throws UserPasswordMismatchException;
+ String doChangePersonalData ();
+
+ /**
+ * Changes logged-in user's email address if the current password matches.
+ * <p>
+ * @return New target page
+ */
+ String doChangeEmailAddress ();
}