From 0d21ea8112407575596efe6c27d72c2df8202f81 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Sun, 25 Sep 2022 11:13:21 +0200 Subject: [PATCH] Please cherry-pick: - Variable 'password' can be final and no need for NULL, maybe an old leftover? MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- .../user/PizzaAdminUserWebRequestBean.java | 55 +++++++++++++++++++ 1 file changed, 55 insertions(+) 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; } /** -- 2.39.5