From: Roland Haeder Date: Sat, 5 Mar 2016 15:34:15 +0000 (+0100) Subject: Continued with updating personal data: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=4dbdd08d2b4c118e76153bea6a1b8321fa18d524;p=addressbook-war.git Continued with updating personal data: - added user password validator (from jjobs-war) - added missing message strings - added check if all required fields are set - added preparing user instance and sending it to the EJB - doChangeFoo() all need to return a string for next target page (not added yet) - updated jar(s) --- diff --git a/lib/juser-core.jar b/lib/juser-core.jar index 40c22b79..dab75846 100644 Binary files a/lib/juser-core.jar and b/lib/juser-core.jar differ diff --git a/lib/juser-lib.jar b/lib/juser-lib.jar index 35588bb0..03505911 100644 Binary files a/lib/juser-lib.jar and b/lib/juser-lib.jar differ diff --git a/nbproject/faces-config.NavData b/nbproject/faces-config.NavData index 077c7ff6..882010c1 100644 --- a/nbproject/faces-config.NavData +++ b/nbproject/faces-config.NavData @@ -17,7 +17,6 @@ - @@ -26,17 +25,17 @@ - + + - diff --git a/src/java/org/mxchange/addressbook/validators/password/UserPasswordValidator.java b/src/java/org/mxchange/addressbook/validators/password/UserPasswordValidator.java new file mode 100644 index 00000000..fa5fce37 --- /dev/null +++ b/src/java/org/mxchange/addressbook/validators/password/UserPasswordValidator.java @@ -0,0 +1,72 @@ +/* + * Copyright (C) 2016 quix0r + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package org.mxchange.addressbook.validators.password; + +import javax.faces.application.FacesMessage; +import javax.faces.component.UIComponent; +import javax.faces.context.FacesContext; +import javax.faces.validator.Validator; +import javax.faces.validator.ValidatorException; +import javax.inject.Inject; +import org.mxchange.addressbook.beans.login.UserLoginWebSessionController; +import org.mxchange.jcoreee.validator.string.BaseStringValidator; +import org.mxchange.jusercore.container.login.LoginContainer; +import org.mxchange.jusercore.container.login.UserLoginContainer; +import org.mxchange.jusercore.model.user.UserUtils; + +/** + * A validator for validating passwords (if they match with stored) + *

+ * @author Roland Haeder + */ +public class UserPasswordValidator extends BaseStringValidator implements Validator { + + /** + * Serial number + */ + private static final long serialVersionUID = 48_581_795_687_317L; + + /** + * User login controller + */ + @Inject + private UserLoginWebSessionController loginController; + + @Override + public void validate (final FacesContext context, final UIComponent component, final Object value) throws ValidatorException { + // Trace message + //this.getLogger().logTrace(MessageFormat.format("validate: context={0},component={1},value={2} - CALLED!", context, component, value)); //NOI18N + + // The required field + String[] requiredFileds = {"currentPassword"}; //NOI18N + + // Pre-validation (example: not null, not a string, empty string ...) + super.preValidate(context, component, value, requiredFileds, false); + + // value is known to be an entered password, so instance login container + LoginContainer container = new UserLoginContainer(this.loginController.getLoggedInUser(), (String) value); + + // Test it here + if (!UserUtils.ifPasswordMatches(container, this.loginController.getLoggedInUser())) { + // Password mismatches + throw new ValidatorException(new FacesMessage(FacesMessage.SEVERITY_ERROR, "Password mismatching.", "The password the user has entered does not match the stored password.")); //NOI18N + } + + // Trace message + //this.getLogger().logTrace("validate: EXIT!"); //NOI18N + } +} diff --git a/src/java/org/mxchange/localization/bundle_de_DE.properties b/src/java/org/mxchange/localization/bundle_de_DE.properties index fa62ad34..69786442 100644 --- a/src/java/org/mxchange/localization/bundle_de_DE.properties +++ b/src/java/org/mxchange/localization/bundle_de_DE.properties @@ -285,3 +285,4 @@ LOGIN_ENTER_CURRENT_PASSWORD_CONFIRM=Derzeitiges Passwort: BUTTON_CHANGE_PERSONAL_DATA=Persoenliche Daten aendern #TODO: Please fix German umlaut! LOGIN_CHANGE_PERSONAL_DATA_TITLE=Persoenliche Daten aendern: +ERROR_CURRENT_PASSWORD_MISMATCHING=Ihr eingegebenes Passwort entspricht nicht dem aktuell gespeicherten Passwort. diff --git a/src/java/org/mxchange/localization/bundle_en_US.properties b/src/java/org/mxchange/localization/bundle_en_US.properties index 59bc76f0..da62220a 100644 --- a/src/java/org/mxchange/localization/bundle_en_US.properties +++ b/src/java/org/mxchange/localization/bundle_en_US.properties @@ -270,3 +270,4 @@ LOGIN_ENTER_CURRENT_PASSWORD_CONFIRMATION_LEGEND_TITLE=Please enter your current LOGIN_ENTER_CURRENT_PASSWORD_CONFIRM=Current password: BUTTON_CHANGE_PERSONAL_DATA=Change personal data LOGIN_CHANGE_PERSONAL_DATA_TITLE=Change personal data: +ERROR_CURRENT_PASSWORD_MISMATCHING=Your entered password doesn't match the currently stored one. diff --git a/web/WEB-INF/faces-config.xml b/web/WEB-INF/faces-config.xml index 9bb8d1f8..d5b62294 100644 --- a/web/WEB-INF/faces-config.xml +++ b/web/WEB-INF/faces-config.xml @@ -37,6 +37,10 @@ UserIdValidator org.mxchange.addressbook.validator.user.UserIdValidator + + UserPasswordValidator + org.mxchange.addressbook.validators.password.UserPasswordValidator + * diff --git a/web/WEB-INF/templates/login/login_enter_current_password.tpl b/web/WEB-INF/templates/login/login_enter_current_password.tpl index b218c729..26206e4c 100644 --- a/web/WEB-INF/templates/login/login_enter_current_password.tpl +++ b/web/WEB-INF/templates/login/login_enter_current_password.tpl @@ -14,7 +14,10 @@

- + + + +
diff --git a/web/login/login_change_personal_data.xhtml b/web/login/login_change_personal_data.xhtml index e1711f0d..b441a304 100644 --- a/web/login/login_change_personal_data.xhtml +++ b/web/login/login_change_personal_data.xhtml @@ -29,7 +29,7 @@