From: Roland Haeder Date: Sat, 5 Mar 2016 15:09:36 +0000 (+0100) Subject: Continued with user profile data: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=0100b40cbbeb0d5b7581abeb9a5802434aa01add;p=jjobs-war.git Continued with user profile data: - renamed changeFoo() to doChangeFoo() to match with naming convention - added doChangePersonalData() which throws a checked exception - that method does currently only check if the user is logged-in and if the password matches - the resulting error message would be not user-friendly, so better added a validator which outputs a new localizable message - added method ifCurrentPasswordMatches() which uses UserUtils to validate the entered password - renaming interface applied - updated juser-core.jar - added jcoreee.jar --- diff --git a/lib/jcoreee.jar b/lib/jcoreee.jar new file mode 100644 index 00000000..8fa7868d Binary files /dev/null and b/lib/jcoreee.jar differ 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/nbproject/build-impl.xml b/nbproject/build-impl.xml index 1804cc32..226dc27e 100644 --- a/nbproject/build-impl.xml +++ b/nbproject/build-impl.xml @@ -1033,6 +1033,7 @@ exists or setup the property manually. For example like this: + @@ -1046,6 +1047,7 @@ exists or setup the property manually. For example like this: + diff --git a/nbproject/faces-config.NavData b/nbproject/faces-config.NavData index 14f40311..9a3038d3 100644 --- a/nbproject/faces-config.NavData +++ b/nbproject/faces-config.NavData @@ -2,25 +2,24 @@ - - + - + - - + + diff --git a/nbproject/genfiles.properties b/nbproject/genfiles.properties index 224aeea4..5eb7f85f 100644 --- a/nbproject/genfiles.properties +++ b/nbproject/genfiles.properties @@ -1,8 +1,8 @@ -build.xml.data.CRC32=fafbc183 +build.xml.data.CRC32=b9ff954e build.xml.script.CRC32=fae72669 build.xml.stylesheet.CRC32=651128d4@1.75.1.1 # This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. # Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. -nbproject/build-impl.xml.data.CRC32=fafbc183 -nbproject/build-impl.xml.script.CRC32=d40bda24 +nbproject/build-impl.xml.data.CRC32=b9ff954e +nbproject/build-impl.xml.script.CRC32=fca932bd nbproject/build-impl.xml.stylesheet.CRC32=99ea4b56@1.75.1.1 diff --git a/nbproject/project.properties b/nbproject/project.properties index afaedba9..5179696b 100644 --- a/nbproject/project.properties +++ b/nbproject/project.properties @@ -38,6 +38,7 @@ excludes= file.reference.jcontacts-core.jar=lib/jcontacts-core.jar file.reference.jcore-logger-lib.jar=lib/jcore-logger-lib.jar file.reference.jcore.jar=lib/jcore.jar +file.reference.jcoreee.jar=lib/jcoreee.jar file.reference.jcountry-core.jar=lib/jcountry-core.jar file.reference.jcountry-lib.jar=lib/jcountry-lib.jar file.reference.jphone-core.jar=lib/jphone-core.jar @@ -60,6 +61,7 @@ javac.classpath=\ ${file.reference.jcontacts-core.jar}:\ ${file.reference.jcore.jar}:\ ${file.reference.jcore-logger-lib.jar}:\ + ${file.reference.jcoreee.jar}:\ ${file.reference.jcountry-core.jar}:\ ${file.reference.jcountry-lib.jar}:\ ${file.reference.jphone-core.jar}:\ @@ -108,6 +110,7 @@ source.encoding=UTF-8 source.reference.jcontacts-core.jar=../jcontacts-core/src/ source.reference.jcore-logger-lib.jar=../jcore-logger-lib/src/ source.reference.jcore.jar=../jcore/src/ +source.reference.jcoreee.jar=../jcoreee/src/ source.reference.jcountry-core.jar=../jcountry-core/src/ source.reference.jcountry-lib.jar=../jcountry-lib/src/ source.reference.jphone-core.jar=../jphone-core/src/ diff --git a/nbproject/project.xml b/nbproject/project.xml index f150bf9c..352befef 100644 --- a/nbproject/project.xml +++ b/nbproject/project.xml @@ -18,6 +18,10 @@ ${file.reference.jcore-logger-lib.jar} WEB-INF/lib + + ${file.reference.jcoreee.jar} + WEB-INF/lib + ${file.reference.jcountry-core.jar} WEB-INF/lib diff --git a/src/java/org/mxchange/jjobs/beans/country/CountryWebApplicationBean.java b/src/java/org/mxchange/jjobs/beans/country/CountryWebApplicationBean.java index 41d682b5..08811e2d 100644 --- a/src/java/org/mxchange/jjobs/beans/country/CountryWebApplicationBean.java +++ b/src/java/org/mxchange/jjobs/beans/country/CountryWebApplicationBean.java @@ -25,8 +25,8 @@ import javax.inject.Named; import javax.naming.Context; import javax.naming.InitialContext; import javax.naming.NamingException; -import org.mxchange.jcountry.data.AddressbookCountrySingletonBeanRemote; import org.mxchange.jcountry.data.Country; +import org.mxchange.jcountry.data.JobsCountrySingletonBeanRemote; /** * A country bean @@ -45,7 +45,7 @@ public class CountryWebApplicationBean implements CountryWebApplicationControlle /** * Remote country EJB */ - private AddressbookCountrySingletonBeanRemote countryBean; + private JobsCountrySingletonBeanRemote countryBean; /** * List of all countries @@ -62,7 +62,7 @@ public class CountryWebApplicationBean implements CountryWebApplicationControlle Context context = new InitialContext(); // Try to lookup the bean - this.countryBean = (AddressbookCountrySingletonBeanRemote) context.lookup("ejb/jjobs-singleton-country"); //NOI18N + this.countryBean = (JobsCountrySingletonBeanRemote) context.lookup("ejb/jjobs-singleton-country"); //NOI18N } catch (final NamingException ex) { // Continue to throw throw new FaceletException(ex); diff --git a/src/java/org/mxchange/jjobs/beans/login/UserLoginWebSessionBean.java b/src/java/org/mxchange/jjobs/beans/login/UserLoginWebSessionBean.java index 449e4e60..4a9c1edf 100644 --- a/src/java/org/mxchange/jjobs/beans/login/UserLoginWebSessionBean.java +++ b/src/java/org/mxchange/jjobs/beans/login/UserLoginWebSessionBean.java @@ -37,6 +37,7 @@ import org.mxchange.jusercore.exceptions.UserStatusLockedException; import org.mxchange.jusercore.exceptions.UserStatusUnconfirmedException; import org.mxchange.jusercore.model.login.UserLoginSessionBeanRemote; import org.mxchange.jusercore.model.user.User; +import org.mxchange.jusercore.model.user.UserUtils; import org.mxchange.jusercore.model.user.profilemodes.ProfileMode; import org.mxchange.jusercore.model.user.status.UserAccountStatus; @@ -138,6 +139,24 @@ public class UserLoginWebSessionBean implements UserLoginWebSessionController { } } + @Override + public boolean ifCurrentPasswordMatches () { + // The current password must be set and not empty + if (this.getCurrentPassword() == null) { + // Is not set + throw new NullPointerException("this.currentPassword is null"); //NOI18N + } else if (this.getCurrentPassword().isEmpty()) { + // Is set empty + throw new IllegalStateException("this.currentPassword is empty."); //NOI18N + } + + // Create "container" + LoginContainer container = new UserLoginContainer(this.getLoggedInUser(), this.getCurrentPassword()); + + // Now check if it matches + return UserUtils.ifPasswordMatches(container, this.getLoggedInUser()); + } + @Override public String getCurrentPassword () { return currentPassword; @@ -195,7 +214,6 @@ public class UserLoginWebSessionBean implements UserLoginWebSessionController { // Trace message // NOISY-DEBUG System.out.println(MessageFormat.format("UserLoginWebSessionBean:isUserLoggedIn: this.userLoggedIn={0} - EXIT!", this.userLoggedIn)); - // Return it return this.userLoggedIn; } diff --git a/src/java/org/mxchange/jjobs/beans/login/UserLoginWebSessionController.java b/src/java/org/mxchange/jjobs/beans/login/UserLoginWebSessionController.java index b1454d39..4cf2358a 100644 --- a/src/java/org/mxchange/jjobs/beans/login/UserLoginWebSessionController.java +++ b/src/java/org/mxchange/jjobs/beans/login/UserLoginWebSessionController.java @@ -95,4 +95,12 @@ public interface UserLoginWebSessionController extends Serializable { * @return Current password */ String getCurrentPassword (); + + /** + * Checks whether the (previously entered) current password matches with from + * the user instance. + *

+ * @return If current password matches + */ + boolean ifCurrentPasswordMatches (); } diff --git a/src/java/org/mxchange/jjobs/beans/user/UserWebSessionBean.java b/src/java/org/mxchange/jjobs/beans/user/UserWebSessionBean.java index bb122ea7..61363cfd 100644 --- a/src/java/org/mxchange/jjobs/beans/user/UserWebSessionBean.java +++ b/src/java/org/mxchange/jjobs/beans/user/UserWebSessionBean.java @@ -47,6 +47,7 @@ import org.mxchange.jphone.phonenumbers.smsprovider.SmsProvider; import org.mxchange.jusercore.events.login.UserLoggedInEvent; import org.mxchange.jusercore.events.registration.UserRegisteredEvent; import org.mxchange.jusercore.exceptions.UserNotFoundException; +import org.mxchange.jusercore.exceptions.UserPasswordMismatchException; import org.mxchange.jusercore.model.user.LoginUser; import org.mxchange.jusercore.model.user.User; import org.mxchange.jusercore.model.user.UserSessionBeanRemote; @@ -66,7 +67,6 @@ public class UserWebSessionBean implements UserWebSessionController { */ private static final long serialVersionUID = 542_145_347_916L; - /////////////////////// Properties ///////////////////// /** * Birth day */ @@ -238,6 +238,18 @@ public class UserWebSessionBean implements UserWebSessionController { } } + @Override + public void doChangePersonalData () throws UserPasswordMismatchException { + // This method shall only be called if the user is logged-in + if (!this.loginController.isUserLoggedIn()) { + // Not logged-in + throw new IllegalStateException("User is not logged-in"); //NOI18N + } else if (!this.loginController.ifCurrentPasswordMatches()) { + // Password not matching + throw new UserPasswordMismatchException(this.loginController.getLoggedInUser()); + } + } + @Override public void afterRegistrationEvent (final @Observes UserRegisteredEvent event) { // Trace message diff --git a/src/java/org/mxchange/jjobs/beans/user/UserWebSessionController.java b/src/java/org/mxchange/jjobs/beans/user/UserWebSessionController.java index 9917eab5..cbb933fd 100644 --- a/src/java/org/mxchange/jjobs/beans/user/UserWebSessionController.java +++ b/src/java/org/mxchange/jjobs/beans/user/UserWebSessionController.java @@ -25,6 +25,7 @@ import org.mxchange.jphone.phonenumbers.smsprovider.SmsProvider; import org.mxchange.jusercore.events.login.UserLoggedInEvent; import org.mxchange.jusercore.events.registration.UserRegisteredEvent; import org.mxchange.jusercore.exceptions.UserNotFoundException; +import org.mxchange.jusercore.exceptions.UserPasswordMismatchException; import org.mxchange.jusercore.model.user.User; import org.mxchange.jusercore.model.user.profilemodes.ProfileMode; @@ -478,4 +479,12 @@ public interface UserWebSessionController extends Serializable { * @return Whether the user id is empty */ boolean isUserIdEmpty (); + + /** + * Changes logged-in user's personal data if the current password matches + * and TAC + privacy statement has been accepted. + *

+ * @throws UserPasswordMismatchException If the entered password doesn't match + */ + void doChangePersonalData () throws UserPasswordMismatchException; } diff --git a/src/java/org/mxchange/jjobs/converter/country/CountryConverter.java b/src/java/org/mxchange/jjobs/converter/country/CountryConverter.java index 12f96e1b..f27b5c83 100644 --- a/src/java/org/mxchange/jjobs/converter/country/CountryConverter.java +++ b/src/java/org/mxchange/jjobs/converter/country/CountryConverter.java @@ -28,7 +28,7 @@ import javax.naming.InitialContext; import javax.naming.NamingException; import org.mxchange.jcoreeelogger.beans.local.logger.Log; import org.mxchange.jcoreeelogger.beans.local.logger.LoggerBeanLocal; -import org.mxchange.jcountry.data.AddressbookCountrySingletonBeanRemote; +import org.mxchange.jcountry.data.JobsCountrySingletonBeanRemote; import org.mxchange.jcountry.data.Country; /** @@ -42,7 +42,7 @@ public class CountryConverter implements Converter { /** * Country bean */ - private AddressbookCountrySingletonBeanRemote countryController; + private JobsCountrySingletonBeanRemote countryController; /** * Logger instance @@ -63,7 +63,7 @@ public class CountryConverter implements Converter { this.loggerBeanLocal = (LoggerBeanLocal) context.lookup("java:global/jcore-logger-ejb/logger!org.mxchange.jcoreeelogger.beans.local.logger.LoggerBeanLocal"); //NOI18N // ... and country controller - this.countryController = (AddressbookCountrySingletonBeanRemote) context.lookup("java:global/jjobs-ejb/country!org.mxchange.jcountry.data.AddressbookCountrySingletonBeanRemote"); //NOI18N + this.countryController = (JobsCountrySingletonBeanRemote) context.lookup("java:global/jjobs-ejb/country!org.mxchange.jcountry.data.JobsCountrySingletonBeanRemote"); //NOI18N } catch (final NamingException ex) { // Continue to throw it throw new RuntimeException("context.lookup() failed.", ex); //NOI18N diff --git a/src/java/org/mxchange/jjobs/validators/password/UserPasswordValidator.java b/src/java/org/mxchange/jjobs/validators/password/UserPasswordValidator.java new file mode 100644 index 00000000..e1d90441 --- /dev/null +++ b/src/java/org/mxchange/jjobs/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.jjobs.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.jcoreee.validator.string.BaseStringValidator; +import org.mxchange.jjobs.beans.login.UserLoginWebSessionController; +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 473217eb..9c3dca0a 100644 --- a/src/java/org/mxchange/localization/bundle_de_DE.properties +++ b/src/java/org/mxchange/localization/bundle_de_DE.properties @@ -256,3 +256,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 032df0c2..a348ece0 100644 --- a/src/java/org/mxchange/localization/bundle_en_US.properties +++ b/src/java/org/mxchange/localization/bundle_en_US.properties @@ -240,3 +240,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 83579c01..25547658 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.jjobs.validators.password.UserPasswordValidator + * @@ -140,19 +144,19 @@ /user/show_addressbook_entries.xhtml - - /login/login_edit_user_data.xhtml - - login_change_email_address - /login/login_change_email_address.xhtml - - - login_change_password - /login/login_change_password.xhtml - - - login_change_personal_data - /login/login_change_personal_data.xhtml - - + + /login/login_edit_user_data.xhtml + + login_change_email_address + /login/login_change_email_address.xhtml + + + login_change_password + /login/login_change_password.xhtml + + + login_change_personal_data + /login/login_change_personal_data.xhtml + + 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..517870e1 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/WEB-INF/templates/login/login_footer.tpl b/web/WEB-INF/templates/login/login_footer.tpl index ffe77f49..a951a4dc 100644 --- a/web/WEB-INF/templates/login/login_footer.tpl +++ b/web/WEB-INF/templates/login/login_footer.tpl @@ -9,12 +9,15 @@ + + + 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 @@