From: Roland Haeder Date: Wed, 7 Oct 2015 10:13:58 +0000 (+0200) Subject: Continued: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=917486172bc419d0265b8041e8ef7cf63b0ab027;p=addressbook-war.git Continued: - added list for already registered email addresses - added fields for repeated email address and password - added field for user id - added missing language elements - introduced new method addUserNameEmailAddress() - introduced new method clearData() - added copying of missing fields - added @PostConstruct method init() for initializing email address/user name lists - introduced isEmailAddressRegistered() and isUserNameRegistered() - rewrote isRequiredPersonalDataSet() a little (better readable now) - introduced isSameEmailAddressEntered() and isSamePasswordEntered() for checking if repeated email address/password matches - added some missing language elements - added missing value="#{blaController.blub}" (really required, else no data is copied) - added a lot pre-checks for registration and newly added UserUtils.encryptPassword() for securely encryption of the password - added field loggedInUser which holds the logged-in user instance - sorted members a bit - updates jars Signed-off-by:Roland Häder --- diff --git a/lib/jcontacts-business-core.jar b/lib/jcontacts-business-core.jar index ffd6685d..a121a7c8 100644 Binary files a/lib/jcontacts-business-core.jar and b/lib/jcontacts-business-core.jar differ diff --git a/lib/jcontacts-core.jar b/lib/jcontacts-core.jar index 86d27519..3ad2c505 100644 Binary files a/lib/jcontacts-core.jar and b/lib/jcontacts-core.jar differ diff --git a/lib/jcontacts-lib.jar b/lib/jcontacts-lib.jar index b1ab3a7e..c8642f26 100644 Binary files a/lib/jcontacts-lib.jar and b/lib/jcontacts-lib.jar differ diff --git a/lib/juser-core.jar b/lib/juser-core.jar index fb01a7a3..791ee3aa 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 9dd0a507..6457e8da 100644 Binary files a/lib/juser-lib.jar and b/lib/juser-lib.jar differ diff --git a/src/java/org/mxchange/addressbook/beans/login/UserLoginWebBean.java b/src/java/org/mxchange/addressbook/beans/login/UserLoginWebBean.java index 88cb0319..7c22e547 100644 --- a/src/java/org/mxchange/addressbook/beans/login/UserLoginWebBean.java +++ b/src/java/org/mxchange/addressbook/beans/login/UserLoginWebBean.java @@ -39,6 +39,11 @@ import org.mxchange.jusercore.model.user.User; @SessionScoped public class UserLoginWebBean implements UserLoginWebController { + /** + * Serial number + */ + private static final long serialVersionUID = 47_828_986_719_691_592L; + /** * Reemote register session bean */ @@ -51,9 +56,9 @@ public class UserLoginWebBean implements UserLoginWebController { private UserWebController userController; /** - * Serial number + * Logged-in user instance */ - private static final long serialVersionUID = 47_828_986_719_691_592L; + private User loggedInUser; /** * Default constructor @@ -78,10 +83,23 @@ public class UserLoginWebBean implements UserLoginWebController { try { // Call bean - this.loginBean.loginUser(user); + User confirmedUser = this.loginBean.validateUserAccountStatus(user); + + // All fine here so set it here + this.setLoggedInUser(confirmedUser); } catch (final UserNotFoundException | UserStatusLockedException | UserStatusUnconfirmedException ex) { // Throw again throw new FaceletException(ex); } } + + @Override + public User getLoggedInUser () { + return this.loggedInUser; + } + + @Override + public void setLoggedInUser (final User loggedInUser) { + this.loggedInUser = loggedInUser; + } } diff --git a/src/java/org/mxchange/addressbook/beans/login/UserLoginWebController.java b/src/java/org/mxchange/addressbook/beans/login/UserLoginWebController.java index 81d90ba8..f02bae1b 100644 --- a/src/java/org/mxchange/addressbook/beans/login/UserLoginWebController.java +++ b/src/java/org/mxchange/addressbook/beans/login/UserLoginWebController.java @@ -17,6 +17,7 @@ package org.mxchange.addressbook.beans.login; import java.io.Serializable; +import org.mxchange.jusercore.model.user.User; /** * An interface for registration web controllers @@ -29,4 +30,18 @@ public interface UserLoginWebController extends Serializable { * Logins the user, if the account is found, confirmed and unlocked. */ public void doLogin (); + + /** + * Getter for logged-in user instance + *

+ * @return Logged-in user instance + */ + public User getLoggedInUser (); + + /** + * Setter for logged-in user instance + *

+ * @param loggedInUser Logged-in user instance + */ + public void setLoggedInUser (final User loggedInUser); } diff --git a/src/java/org/mxchange/addressbook/beans/register/UserRegisterWebBean.java b/src/java/org/mxchange/addressbook/beans/register/UserRegisterWebBean.java index 24dddcb4..6edf2af6 100644 --- a/src/java/org/mxchange/addressbook/beans/register/UserRegisterWebBean.java +++ b/src/java/org/mxchange/addressbook/beans/register/UserRegisterWebBean.java @@ -16,6 +16,7 @@ */ package org.mxchange.addressbook.beans.register; +import java.text.MessageFormat; import javax.enterprise.context.SessionScoped; import javax.faces.view.facelets.FaceletException; import javax.inject.Inject; @@ -24,10 +25,12 @@ import javax.naming.Context; import javax.naming.InitialContext; import javax.naming.NamingException; import org.mxchange.addressbook.beans.user.UserWebController; +import org.mxchange.jusercore.exceptions.DataRepeatMismatchException; import org.mxchange.jusercore.exceptions.EmailAddressAlreadyRegisteredException; import org.mxchange.jusercore.exceptions.UserNameAlreadyRegisteredException; import org.mxchange.jusercore.model.register.UserRegistrationSessionBeanRemote; import org.mxchange.jusercore.model.user.User; +import org.mxchange.jusercore.model.user.UserUtils; import org.mxchange.jusercore.model.user.status.UserAccountStatus; /** @@ -77,14 +80,29 @@ public class UserRegisterWebBean implements UserRegisterWebController { User user = this.userController.createUserInstance(); // Is the user already used? - if (this.userController.isUserNameRegistered(user.getUserName())) { + if (!this.userController.isRequiredPersonalDataSet()) { + // Not all required fields are set + throw new FaceletException("Not all required fields are set."); + } else if (this.userController.isUserNameRegistered(user.getUserName())) { // User name is already used throw new FaceletException(new UserNameAlreadyRegisteredException(user)); } else if (this.userController.isEmailAddressRegistered(user.getUserContact().getEmailAddress())) { // Email address has already been taken throw new FaceletException(new EmailAddressAlreadyRegisteredException(user)); + } else if (!this.userController.isSameEmailAddressEntered()) { + // Not same email address entered + throw new FaceletException(new DataRepeatMismatchException(MessageFormat.format("Email addresses not matching: {0} != {1}", this.userController.getEmailAddress(), this.userController.getEmailAddressRepeat()))); + } else if (!this.userController.isSamePasswordEntered()) { + // Not same password entered + throw new FaceletException(new DataRepeatMismatchException("Passwords not matching.")); } + // Encrypt password + String encryptedPassword = UserUtils.encryptPassword(this.userController.getUserPassword()); + + // Set it here + user.setUserEncryptedPassword(encryptedPassword); + // For debugging/programming only: user.setUserAccountStatus(UserAccountStatus.CONFIRMED); @@ -95,6 +113,12 @@ public class UserRegisterWebBean implements UserRegisterWebController { // Copy all data from registered->user this.userController.copyUser(registeredUser); + // Add user name and email address + this.userController.addUserNameEmailAddress(registeredUser); + + // Clear all data + this.userController.clearData(); + // All fine, redirect to proper page return "register_done"; //NOI18N } catch (final UserNameAlreadyRegisteredException | EmailAddressAlreadyRegisteredException ex) { diff --git a/src/java/org/mxchange/addressbook/beans/user/UserWebBean.java b/src/java/org/mxchange/addressbook/beans/user/UserWebBean.java index de5c6e05..ab9f5b65 100644 --- a/src/java/org/mxchange/addressbook/beans/user/UserWebBean.java +++ b/src/java/org/mxchange/addressbook/beans/user/UserWebBean.java @@ -16,8 +16,11 @@ */ package org.mxchange.addressbook.beans.user; +import java.text.MessageFormat; import java.util.Date; +import java.util.GregorianCalendar; import java.util.List; +import java.util.Objects; import javax.annotation.PostConstruct; import javax.enterprise.context.SessionScoped; import javax.faces.view.facelets.FaceletException; @@ -77,6 +80,16 @@ public class UserWebBean implements UserWebController { */ private String emailAddress; + /** + * Email address list + */ + private List emailAddressList; + + /** + * Email address repeated + */ + private String emailAddressRepeat; + /** * Family name */ @@ -102,11 +115,6 @@ public class UserWebBean implements UserWebController { */ private Short houseNumber; - /** - * User id - */ - private Long userId; - /** * Phone number */ @@ -122,30 +130,35 @@ public class UserWebBean implements UserWebController { */ private final UserSessionBeanRemote userBean; + /** + * User id + */ + private Long userId; + /** * User name */ private String userName; /** - * User password (unencrypted from web form) + * User name list */ - private String userPassword; + private List userNameList; /** - * ZIP code + * User password (unencrypted from web form) */ - private Integer zipCode; + private String userPassword; /** - * Email address list + * User password repeated (unencrypted from web form) */ - private List emailAddressList; + private String userPasswordRepeat; /** - * User name list + * ZIP code */ - private List userNameList; + private Integer zipCode; /** * Default constructor @@ -160,7 +173,7 @@ public class UserWebBean implements UserWebController { Context context = new InitialContext(); // Try to lookup - this.userBean = (UserSessionBeanRemote) context.lookup("ejb/stateless-user"); + this.userBean = (UserSessionBeanRemote) context.lookup("ejb/stateless-user"); //NOI18N } catch (final NamingException e) { // Throw again throw new FaceletException(e); @@ -168,22 +181,49 @@ public class UserWebBean implements UserWebController { } @Override - public boolean isEmailAddressRegistered (String emailAddress) { - return ((this.emailAddressList instanceof List) && (this.emailAddressList.contains(emailAddress))); + public void addUserNameEmailAddress (final User user) { + // Make sure the entry is not added yet + if (this.userNameList.contains(user.getUserName())) { + // Abort here + throw new IllegalArgumentException(MessageFormat.format("User name {0} already added.", user.getUserName())); + } else if (this.emailAddressList.contains(user.getUserContact().getEmailAddress())) { + // Already added + throw new IllegalArgumentException(MessageFormat.format("Email address {0} already added.", user.getUserContact().getEmailAddress())); + } + + // Add user name + this.userNameList.add(user.getUserName()); + + // Add email addres + this.emailAddressList.add(user.getUserContact().getEmailAddress()); } @Override - public boolean isUserNameRegistered (final String userName) { - return ((this.userNameList instanceof List) && (this.userNameList.contains(userName))); - } + public void clearData () { + // Clear all data + // - personal data + this.setUserId(null); + this.setGender(Gender.UNKNOWN); + this.setFirstName(null); + this.setFamilyName(null); + this.setStreet(null); + this.setHouseNumber(null); + this.setZipCode(null); + this.setCity(null); + this.setCountryCode(null); - @PostConstruct - public void init () { - // Get full user name list for reducing EJB calls - this.userNameList = this.userBean.getUserNameList(); + // - contact data + this.setEmailAddress(null); + this.setEmailAddressRepeat(null); + this.setPhoneNumber(null); + this.setCellphoneNumber(null); + this.setFaxNumber(null); - // Get full email address list for reducing EJB calls - this.emailAddressList = this.userBean.getEmailAddressList(); + // - other data + this.setBirthday(null); + this.setComment(null); + this.setUserPassword(null); + this.setUserPasswordRepeat(null); } @Override @@ -229,14 +269,21 @@ public class UserWebBean implements UserWebController { contact.setHouseNumber(this.getHouseNumber()); contact.setZipCode(this.getZipCode()); contact.setCity(this.getCity()); + contact.setCountryCode(this.getCountryCode()); + contact.setEmailAddress(this.getEmailAddress()); contact.setPhoneNumber(this.getPhoneNumber()); contact.setFaxNumber(this.getFaxNumber()); contact.setCellphoneNumber(this.getCellphoneNumber()); contact.setBirthday(this.getBirthday()); contact.setComment(this.getComment()); + // Created timestamp and ownContact + contact.setCreated(new GregorianCalendar()); + contact.setOwnContact(Boolean.TRUE); + // Set contact in user user.setUserContact(contact); + user.setUserCreated(new GregorianCalendar()); // Trace message //this.getLogger().logTrace(MessageFormat.format("createUserInstance: user={0} - EXIT!", user)); @@ -304,6 +351,16 @@ public class UserWebBean implements UserWebController { this.emailAddress = emailAddress; } + @Override + public String getEmailAddressRepeat () { + return this.emailAddressRepeat; + } + + @Override + public void setEmailAddressRepeat (final String emailAddressRepeat) { + this.emailAddressRepeat = emailAddressRepeat; + } + @Override public String getFamilyName () { return this.familyName; @@ -404,6 +461,16 @@ public class UserWebBean implements UserWebController { this.userPassword = userPassword; } + @Override + public String getUserPasswordRepeat () { + return this.userPasswordRepeat; + } + + @Override + public void setUserPasswordRepeat (final String userPasswordRepeat) { + this.userPasswordRepeat = userPasswordRepeat; + } + @Override public Integer getZipCode () { return this.zipCode; @@ -414,8 +481,48 @@ public class UserWebBean implements UserWebController { this.zipCode = zipCode; } + @PostConstruct + public void init () { + // Get full user name list for reducing EJB calls + this.userNameList = this.userBean.getUserNameList(); + + // Get full email address list for reducing EJB calls + this.emailAddressList = this.userBean.getEmailAddressList(); + } + + @Override + public boolean isEmailAddressRegistered (final String emailAddress) { + return ((this.emailAddressList instanceof List) && (this.emailAddressList.contains(emailAddress))); + } + @Override public boolean isRequiredPersonalDataSet () { - return ((this.getUserName() != null) && (this.getGender() != null) && (this.getFirstName() != null) && (this.getFamilyName() != null) && (this.getStreet() != null) && (this.getHouseNumber() != null) && (this.getZipCode() != null) && (this.getCity() != null)); + return ((this.getUserName() != null) + && (this.getGender() != null) + && (this.getFirstName() != null) + && (this.getFamilyName() != null) + && (this.getStreet() != null) + && (this.getHouseNumber() != null) + && (this.getZipCode() != null) + && (this.getCity() != null) + && (this.getEmailAddress() != null) + && (this.getEmailAddressRepeat() != null) + && (this.getUserPassword() != null) + && (this.getUserPasswordRepeat() != null)); + } + + @Override + public boolean isSameEmailAddressEntered () { + return (Objects.equals(this.getEmailAddress(), this.getEmailAddressRepeat())); + } + + @Override + public boolean isSamePasswordEntered () { + return (Objects.equals(this.getUserPassword(), this.getUserPasswordRepeat())); + } + + @Override + public boolean isUserNameRegistered (final String userName) { + return ((this.userNameList instanceof List) && (this.userNameList.contains(userName))); } } diff --git a/src/java/org/mxchange/addressbook/beans/user/UserWebController.java b/src/java/org/mxchange/addressbook/beans/user/UserWebController.java index cc7c9d16..b93bf115 100644 --- a/src/java/org/mxchange/addressbook/beans/user/UserWebController.java +++ b/src/java/org/mxchange/addressbook/beans/user/UserWebController.java @@ -29,34 +29,30 @@ import org.mxchange.jusercore.model.user.User; public interface UserWebController extends Serializable { /** - * Copies given user into the controller + * Adds user's name and email address to bean's internal list *

* @param user User instance */ - public void copyUser (final User user); + public void addUserNameEmailAddress (final User user); /** - * Creates an instance from all properties - *

- * @return A user instance + * Clears all data in this bean */ - public User createUserInstance (); + public void clearData (); /** - * Checks whether given user name is used + * Copies given user into the controller *

- * @param userName User name to check - * @return Whether it is already used + * @param user User instance */ - public boolean isUserNameRegistered (final String userName); + public void copyUser (final User user); /** - * Checks whether given email address is used + * Creates an instance from all properties *

- * @param emailAddress Email address to check - * @return Whether it is already used + * @return A user instance */ - public boolean isEmailAddressRegistered (final String emailAddress); + public User createUserInstance (); /** * Getter for birth day @@ -114,48 +110,6 @@ public interface UserWebController extends Serializable { */ public void setComment (final String comment); - /** - * Getter for user id - *

- * @return User id - */ - public Long getUserId (); - - /** - * Setter for user id - *

- * @param userId User id - */ - public void setUserId (final Long userId); - - /** - * Getter for user name - *

- * @return User name - */ - public String getUserName (); - - /** - * Setter for user name - *

- * @param userName User name - */ - public void setUserName (final String userName); - - /** - * Getter for unencrypted user password - *

- * @return Unencrypted user password - */ - public String getUserPassword (); - - /** - * Setter for unencrypted user password - *

- * @param userPassword Unencrypted user password - */ - public void setUserPassword (final String userPassword); - /** * Country code *

@@ -171,19 +125,33 @@ public interface UserWebController extends Serializable { public void setCountryCode (final String countryCode); /** - * Email address + * Getter for email address *

- * @return the emailAddress + * @return Email address */ public String getEmailAddress (); /** - * Email address + * Setter for email address *

- * @param emailAddress the emailAddress to set + * @param emailAddress Email address */ public void setEmailAddress (final String emailAddress); + /** + * Getter for email address, repeated + *

+ * @return the emailAddress, repeated + */ + public String getEmailAddressRepeat (); + + /** + * Setter for email address repeated + *

+ * @param emailAddressRepeat the emailAddress to set + */ + public void setEmailAddressRepeat (final String emailAddressRepeat); + /** * Family name *

@@ -282,6 +250,62 @@ public interface UserWebController extends Serializable { */ public void setStreet (final String street); + /** + * Getter for user id + *

+ * @return User id + */ + public Long getUserId (); + + /** + * Setter for user id + *

+ * @param userId User id + */ + public void setUserId (final Long userId); + + /** + * Getter for user name + *

+ * @return User name + */ + public String getUserName (); + + /** + * Setter for user name + *

+ * @param userName User name + */ + public void setUserName (final String userName); + + /** + * Getter for unencrypted user password + *

+ * @return Unencrypted user password + */ + public String getUserPassword (); + + /** + * Setter for unencrypted user password + *

+ * @param userPassword Unencrypted user password + */ + public void setUserPassword (final String userPassword); + + /** + * Getter for unencrypted user password repeated + *

+ * @return Unencrypted user password repeated + */ + public String getUserPasswordRepeat (); + + /** + * Setter for unencrypted user password repeated + *

+ * @param userPasswordRepeat Unencrypted user password repeated + */ + public void setUserPasswordRepeat (final String userPasswordRepeat); + /** * ZIP code *

@@ -296,10 +320,40 @@ public interface UserWebController extends Serializable { */ public void setZipCode (final Integer zipCode); + /** + * Checks whether given email address is used + *

+ * @param emailAddress Email address to check + * @return Whether it is already used + */ + public boolean isEmailAddressRegistered (final String emailAddress); + /** * Checks whether all required personal data is set *

* @return Whether the required personal data is set */ public boolean isRequiredPersonalDataSet (); + + /** + * Checks whether same email addresses have been entered + *

+ * @return Whether same email addresses have been entered + */ + public boolean isSameEmailAddressEntered (); + + /** + * Checks whether same passwords has been entered + *

+ * @return Whether same passwords has been entered + */ + public boolean isSamePasswordEntered (); + + /** + * Checks whether given user name is used + *

+ * @param userName User name to check + * @return Whether it is already used + */ + public boolean isUserNameRegistered (final String userName); } diff --git a/src/java/org/mxchange/localization/bundle_de_DE.properties b/src/java/org/mxchange/localization/bundle_de_DE.properties index ab0c613c..01d4628b 100644 --- a/src/java/org/mxchange/localization/bundle_de_DE.properties +++ b/src/java/org/mxchange/localization/bundle_de_DE.properties @@ -109,4 +109,7 @@ BUTTON_CONTINUE_STEP_2=Weiter zu Schritt 2 GUEST_REGISTRATION_ENTER_USER_NAME=Benutzernamen eingeben: GUEST_REGISTRATION_USER_NAME_NOTICE=Der Benutzername darf nur einmal vorkommen. LINK_GUEST_RESENT_CONFIRMATION_LINK=Nochmals den Best\u00e4tigungslink aussenden? -GUEST_REGISTRATION_COMPLETED=Die Anmeldung ist abgeschlossen und Ihr Account wartet auf Freischaltung. Es ist eine Email mit einem entsprechenden Best\u00e4tigungslink zu Ihnen unterwegs. Diesen m\u00fcssen Sie einmal anklicken oder in die Adresszeile des Browsers kopieren und dann aufrufen lassen. Danach ist Ihr Account freigegeben. +GUEST_USER_REGISTRATION_COMPLETED=Die Anmeldung ist abgeschlossen und Ihr Account wartet auf Freischaltung. Es ist eine Email mit einem entsprechenden Best\u00e4tigungslink zu Ihnen unterwegs. Diesen m\u00fcssen Sie einmal anklicken oder in die Adresszeile des Browsers kopieren und dann aufrufen lassen. Danach ist Ihr Account freigegeben. +PERSONAL_DATA_COUNTRY_CODE=L\u00e4ndercode: +PAGE_TITLE_USER_REGISTER_DONE=Anmeldung abgeschlossen +SUB_TITLE_USER_REGISTER_DONE=Die Anmeldung ist abgeschlossen: diff --git a/src/java/org/mxchange/localization/bundle_en_US.properties b/src/java/org/mxchange/localization/bundle_en_US.properties index 2f6c7127..761a8817 100644 --- a/src/java/org/mxchange/localization/bundle_en_US.properties +++ b/src/java/org/mxchange/localization/bundle_en_US.properties @@ -109,4 +109,7 @@ BUTTON_CONTINUE_STEP_2=Weiter zu Schritt 2 GUEST_REGISTRATION_ENTER_USER_NAME=Enter user name: GUEST_REGISTRATION_USER_NAME_NOTICE=The user name must only exist once. LINK_GUEST_RESENT_CONFIRMATION_LINK=Resend again the confirmation link? -GUEST_REGISTRATION_COMPLETED=The registration is completed and your account is pending confirmation. An email has been sent to you. There you will find a confirmation link which you have to click once or copy it into your browser's address bar and call it. +GUEST_USER_REGISTRATION_COMPLETED=The registration is completed and your account is pending confirmation. An email has been sent to you. There you will find a confirmation link which you have to click once or copy it into your browser's address bar and call it. +PERSONAL_DATA_COUNTRY_CODE=Country code: +PAGE_TITLE_USER_REGISTER_DONE=Registration completed +SUB_TITLE_USER_REGISTER_DONE=Registration is completed: diff --git a/web/WEB-INF/templates/guest/guest_personal_data.tpl b/web/WEB-INF/templates/guest/guest_personal_data.tpl index 4496e88d..a59ab7cf 100644 --- a/web/WEB-INF/templates/guest/guest_personal_data.tpl +++ b/web/WEB-INF/templates/guest/guest_personal_data.tpl @@ -107,6 +107,18 @@

+
+
+ +
+ +
+ +
+ +
+
+
diff --git a/web/WEB-INF/templates/guest/guest_registration_form.tpl b/web/WEB-INF/templates/guest/guest_registration_form.tpl index 30fad999..c92e59bd 100644 --- a/web/WEB-INF/templates/guest/guest_registration_form.tpl +++ b/web/WEB-INF/templates/guest/guest_registration_form.tpl @@ -48,7 +48,7 @@
- +
@@ -62,7 +62,7 @@
- +
@@ -74,7 +74,7 @@
- +