From: Roland Haeder Date: Thu, 10 Mar 2016 19:11:27 +0000 (+0100) Subject: added methods for changing email address (partly unfinished) + updated jar(s) X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=1ca5f043e1ce77937f8dbd1fcfe9acaaa9db994d;p=jjobs-war.git added methods for changing email address (partly unfinished) + updated jar(s) --- diff --git a/lib/juser-lib.jar b/lib/juser-lib.jar index e9610b7b..93248266 100644 Binary files a/lib/juser-lib.jar and b/lib/juser-lib.jar differ diff --git a/src/java/org/mxchange/jjobs/beans/user/UserWebSessionBean.java b/src/java/org/mxchange/jjobs/beans/user/UserWebSessionBean.java index 9d705477..0729ac11 100644 --- a/src/java/org/mxchange/jjobs/beans/user/UserWebSessionBean.java +++ b/src/java/org/mxchange/jjobs/beans/user/UserWebSessionBean.java @@ -249,7 +249,7 @@ public class UserWebSessionBean implements UserWebSessionController { } @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 @@ -259,7 +259,7 @@ public class UserWebSessionBean implements UserWebSessionController { 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 @@ -321,6 +321,44 @@ public class UserWebSessionBean implements UserWebSessionController { 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 @@ -833,6 +871,12 @@ public class UserWebSessionBean implements UserWebSessionController { (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())); diff --git a/src/java/org/mxchange/jjobs/beans/user/UserWebSessionController.java b/src/java/org/mxchange/jjobs/beans/user/UserWebSessionController.java index 9b68c9c2..1794c3dc 100644 --- a/src/java/org/mxchange/jjobs/beans/user/UserWebSessionController.java +++ b/src/java/org/mxchange/jjobs/beans/user/UserWebSessionController.java @@ -477,6 +477,13 @@ public interface UserWebSessionController extends Serializable { */ boolean isRequiredChangePersonalDataSet (); + /** + * Checks whether all required are set for changing email address + *

+ * @return Whether the required personal data is set + */ + boolean isRequiredChangeEmailAddressSet (); + /** * Checks whether same email addresses have been entered *

@@ -523,5 +530,12 @@ public interface UserWebSessionController extends Serializable { *

* @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. + *

+ * @return New target page + */ + String doChangeEmailAddress (); }