]> git.mxchange.org Git - jjobs-war.git/blobdiff - src/java/org/mxchange/jjobs/beans/user/password/JobsUserPasswordWebRequestBean.java
Please cherry-pick:
[jjobs-war.git] / src / java / org / mxchange / jjobs / beans / user / password / JobsUserPasswordWebRequestBean.java
index e88410b401949d28aa90716bb83be8aecbd02377..42fa746f8e24474f374df169722aae2311582679 100644 (file)
@@ -21,7 +21,8 @@ import javax.ejb.EJB;
 import javax.enterprise.context.RequestScoped;
 import javax.enterprise.event.Event;
 import javax.enterprise.inject.Any;
-import javax.faces.view.facelets.FaceletException;
+import javax.faces.FacesException;
+import javax.faces.application.FacesMessage;
 import javax.inject.Inject;
 import javax.inject.Named;
 import org.mxchange.jcoreee.utils.FacesUtils;
@@ -115,16 +116,16 @@ public class JobsUserPasswordWebRequestBean extends BaseJobsBean implements Jobs
                        throw new IllegalStateException("User is not logged-in"); //NOI18N
                } else if (!this.isRequiredChangePasswordSet()) {
                        // Not all required fields are set
-                       throw new FaceletException("Not all required fields are set."); //NOI18N
+                       throw new FacesException("Not all required fields are set."); //NOI18N
                } else if (!this.userLoginController.ifCurrentPasswordMatches()) {
                        // Password not matching
-                       throw new FaceletException(new UserPasswordMismatchException(this.userLoginController.getLoggedInUser()));
+                       throw new FacesException(new UserPasswordMismatchException(this.userLoginController.getLoggedInUser()));
                } else if (!this.featureController.isFeatureEnabled("change_user_password")) { //NOI18N
                        // Editing is not allowed
                        throw new IllegalStateException("User tried to change password."); //NOI18N
                } else if (!UserLoginUtils.ifPasswordMatches(this.getUserCurrentPassword(), this.userLoginController.getLoggedInUser())) {
                        // Password mismatches
-                       this.showFacesMessage("form_user_change_password:userCurrentPassword", "Entered current password does not matched stored password."); //NOI18N
+                       this.showFacesMessage("form_user_change_password:userCurrentPassword", "Entered current password does not matched stored password.", FacesMessage.SEVERITY_WARN); //NOI18N
 
                        // Clear bean
                        this.clear();
@@ -133,7 +134,7 @@ public class JobsUserPasswordWebRequestBean extends BaseJobsBean implements Jobs
                        return ""; //NOI18N
                } else if (!Objects.equals(this.getUserPassword(), this.getUserPasswordRepeat())) {
                        // Both entered passwords don't match
-                       this.showFacesMessage("form_user_change_password:userPasswordRepeat", "Entered new passwords mismatch."); //NOI18N
+                       this.showFacesMessage("form_user_change_password:userPasswordRepeat", "Entered new passwords mismatch.", FacesMessage.SEVERITY_ERROR); //NOI18N
 
                        // Clear bean
                        this.clear();
@@ -142,7 +143,7 @@ public class JobsUserPasswordWebRequestBean extends BaseJobsBean implements Jobs
                        return ""; //NOI18N
                } else if (Objects.equals(this.getUserCurrentPassword(), this.getUserPassword())) {
                        // New password matches current
-                       this.showFacesMessage("form_user_change_password:userPassword", "Entered new password is same as current password."); //NOI18N
+                       this.showFacesMessage("form_user_change_password:userPassword", "Entered new password is same as current password.", FacesMessage.SEVERITY_WARN); //NOI18N
 
                        // Clear bean
                        this.clear();
@@ -151,7 +152,7 @@ public class JobsUserPasswordWebRequestBean extends BaseJobsBean implements Jobs
                        return ""; //NOI18N
                } else if (this.userLoginController.isPasswordInHistory(this.getUserPassword())) {
                        // Is already in list (to old passwords are ignored)
-                       this.showFacesMessage("form_user_change_password:userPassword", "Entered new password is has already been used some time ago."); //NOI18N
+                       this.showFacesMessage("form_user_change_password:userPassword", "Entered new password is has already been used some time ago.", FacesMessage.SEVERITY_WARN); //NOI18N
 
                        // Clear bean
                        this.clear();
@@ -169,23 +170,26 @@ public class JobsUserPasswordWebRequestBean extends BaseJobsBean implements Jobs
                // Set it in user
                user.setUserEncryptedPassword(encryptedPassword);
 
+               // Init variable
+               final PasswordHistory passwordHistory;
+
                try {
                        // Get base URL
                        final String baseUrl = FacesUtils.generateBaseUrl();
 
                        // All is set, then update password
-                       PasswordHistory passwordHistory = this.userBean.updateUserPassword(user, baseUrl);
-
-                       // Fire event
-                       this.userUpdatedPasswordEvent.fire(new UpdatedUserPasswordEvent(passwordHistory, this.getUserPassword()));
+                       passwordHistory = this.userBean.updateUserPassword(user, baseUrl);
                } catch (final UserNotFoundException | UserStatusUnconfirmedException | UserStatusLockedException ex) {
                        // Clear bean
                        this.clear();
 
                        // Throw again
-                       throw new FaceletException(ex);
+                       throw new FacesException(ex);
                }
 
+               // Fire event
+               this.userUpdatedPasswordEvent.fire(new UpdatedUserPasswordEvent(passwordHistory, this.getUserPassword()));
+
                // Clear bean
                this.clear();