]> git.mxchange.org Git - addressbook-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:16:32 +0000 (11:16 +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/addressbook/beans/user/AddressbookAdminUserWebRequestBean.java

index ec35e555fd36b7b804f3098ee4f407ee06108c5f..7fb17ad336b70b15c381de03315fbadbee5c3ff9 100644 (file)
@@ -730,6 +730,61 @@ public class AddressbookAdminUserWebRequestBean extends BaseAddressbookBean impl
                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;
        }
 
        /**