From: Roland Häder Date: Sun, 25 Sep 2022 09:13:21 +0000 (+0200) Subject: Please cherry-pick: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=0d21ea8112407575596efe6c27d72c2df8202f81;p=pizzaservice-war.git Please cherry-pick: - Variable 'password' can be final and no need for NULL, maybe an old leftover? Signed-off-by: Roland Häder --- diff --git a/src/java/org/mxchange/pizzaapplication/beans/user/PizzaAdminUserWebRequestBean.java b/src/java/org/mxchange/pizzaapplication/beans/user/PizzaAdminUserWebRequestBean.java index 78d7f461..93b2d046 100644 --- a/src/java/org/mxchange/pizzaapplication/beans/user/PizzaAdminUserWebRequestBean.java +++ b/src/java/org/mxchange/pizzaapplication/beans/user/PizzaAdminUserWebRequestBean.java @@ -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 + *

+ * @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; } /**