]> git.mxchange.org Git - jjobs-war.git/commitdiff
added methods for changing email address (partly unfinished) + updated jar(s)
authorRoland Haeder <roland@mxchange.org>
Thu, 10 Mar 2016 19:11:27 +0000 (20:11 +0100)
committerRoland Haeder <roland@mxchange.org>
Thu, 10 Mar 2016 19:11:27 +0000 (20:11 +0100)
lib/juser-lib.jar
src/java/org/mxchange/jjobs/beans/user/UserWebSessionBean.java
src/java/org/mxchange/jjobs/beans/user/UserWebSessionController.java

index e9610b7b5e6631e07a8b3214791e637e4363fc42..93248266d4eebd8afd5d1c428b3b196b1de2d19c 100644 (file)
Binary files a/lib/juser-lib.jar and b/lib/juser-lib.jar differ
index 9d7054774392eaa58bc6787b823f9ee50d39fc12..0729ac1116182915a01f0c92dd248a3632ccb218 100644 (file)
@@ -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()));
index 9b68c9c28a6959ed328af113570916c062ecb93a..1794c3dc1878567f73bcbab0bfa2c628ac55160e 100644 (file)
@@ -477,6 +477,13 @@ public interface UserWebSessionController extends Serializable {
         */
        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>
@@ -523,5 +530,12 @@ public interface UserWebSessionController extends Serializable {
         * <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 ();
 }