]> git.mxchange.org Git - pizzaservice-war.git/commitdiff
Please cherry-pick:
authorRoland Häder <roland@mxchange.org>
Sun, 25 Sep 2022 09:13:21 +0000 (11:13 +0200)
committerRoland Häder <roland@mxchange.org>
Sun, 25 Sep 2022 09:17:28 +0000 (11:17 +0200)
- Variable 'password' can be final and no need for NULL, maybe an old leftover?

Signed-off-by: Roland Häder <roland@mxchange.org>
src/java/org/mxchange/pizzaapplication/beans/user/PizzaAdminUserWebRequestBean.java

index 78d7f4617a6587de7a4cc850943ee30ab0972a94..93b2d0469f6f482953ddff15e970366fc2fd47bf 100644 (file)
@@ -732,6 +732,61 @@ public class PizzaAdminUserWebRequestBean extends BasePizzaBean implements Pizza
                this.setUserLockReason(null);
                this.setUserMustChangePassword(null);
                this.setUserName(null);
+               this.setUserPassword(null);
+               this.setUserPasswordRepeat(null);
+               this.setUserProfileMode(null);
+
+       }
+
+       /**
+        * Creates a new user instance from all currently saved data from this bean
+        * <p>
+        * @return New user instance
+        */
+       private User createUserInstance () {
+               // Init variable for password and contact
+               final String password;
+               final Contact userContact;
+
+               // Is a contact instance in helper set?
+               if ((this.getUserPassword() == null && (this.getUserPasswordRepeat() == null)) || ((this.getUserPassword().isEmpty()) && (this.getUserPasswordRepeat().isEmpty()))) {
+                       // Empty password entered, then generate one
+                       password = UserLoginUtils.createRandomPassword(FinancialsUserWebRequestController.MINIMUM_PASSWORD_LENGTH);
+               } else if (!this.isSamePasswordEntered()) {
+                       // Both passwords don't match
+                       throw new FacesException(new UserPasswordRepeatMismatchException());
+               } else {
+                       // Both match, so get it from this bean
+                       password = this.getUserPassword();
+               }
+
+               // Is contact instance given? Else create one
+               if (this.getContact() instanceof Contact) {
+                       // Then use it for contact linking
+                       userContact = this.getContact();
+               } else {
+                       // Create contact instance
+                       userContact = this.contactController.createContactInstance();
+               }
+
+               // Create new instance
+               final User newUser = new LoginUser(
+                                  this.getUserName(),
+                                  this.getUserProfileMode(),
+                                  this.getUserMustChangePassword(),
+                                  UserLoginUtils.encryptPassword(password),
+                                  UserAccountStatus.CONFIRMED,
+                                  userContact
+                  );
+
+               // Get locale from view-root
+               final Locale locale = FacesContext.getCurrentInstance().getViewRoot().getLocale();
+
+               // Copy user locale
+               newUser.setUserLocale(locale);
+
+               // Return it
+               return newUser;
        }
 
        /**