rave-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ja...@apache.org
Subject svn commit: r1162748 - in /incubator/rave/trunk: rave-portal/src/main/java/org/apache/rave/portal/model/ rave-portal/src/main/java/org/apache/rave/portal/repository/ rave-portal/src/main/java/org/apache/rave/portal/service/ rave-portal/src/main/java/or...
Date Mon, 29 Aug 2011 11:28:22 GMT
Author: jasha
Date: Mon Aug 29 11:28:22 2011
New Revision: 1162748

URL: http://svn.apache.org/viewvc?rev=1162748&view=rev
Log:
RAVE-37 make email address a required field in the registration process (for future 'forgot
password' functionality)

Modified:
    incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/portal/model/NewUser.java
    incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/portal/model/User.java
    incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/portal/repository/UserRepository.java
    incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/portal/service/NewAccountService.java
    incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/portal/service/UserService.java
    incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/portal/web/controller/NewAccountController.java
    incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/portal/web/validator/NewAccountValidator.java
    incubator/rave/trunk/rave-portal/src/main/resources/initial_data.sql
    incubator/rave/trunk/rave-portal/src/main/resources/messages.properties
    incubator/rave/trunk/rave-portal/src/main/webapp/WEB-INF/views/newaccount.jsp
    incubator/rave/trunk/rave-portal/src/test/java/org/apache/rave/portal/repository/JpaUserRepositoryTest.java
    incubator/rave/trunk/rave-portal/src/test/java/org/apache/rave/portal/service/NewAccountServiceTest.java
    incubator/rave/trunk/rave-portal/src/test/java/org/apache/rave/portal/web/validator/NewAccountValidatorTest.java
    incubator/rave/trunk/rave-shindig/src/main/resources/initial_data.sql

Modified: incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/portal/model/NewUser.java
URL: http://svn.apache.org/viewvc/incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/portal/model/NewUser.java?rev=1162748&r1=1162747&r2=1162748&view=diff
==============================================================================
--- incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/portal/model/NewUser.java
(original)
+++ incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/portal/model/NewUser.java
Mon Aug 29 11:28:22 2011
@@ -33,6 +33,8 @@ public class NewUser {
 	
 	private String pageLayout;
 
+    private String email;
+
 	public NewUser(){
 	}
 	
@@ -67,5 +69,12 @@ public class NewUser {
 	public void setPageLayout(String pageLayout) {
 		this.pageLayout = pageLayout;
 	}
-	
+
+    public String getEmail() {
+        return email;
+    }
+
+    public void setEmail(String email) {
+        this.email = email;
+    }
 }
\ No newline at end of file

Modified: incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/portal/model/User.java
URL: http://svn.apache.org/viewvc/incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/portal/model/User.java?rev=1162748&r1=1162747&r2=1162748&view=diff
==============================================================================
--- incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/portal/model/User.java
(original)
+++ incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/portal/model/User.java
Mon Aug 29 11:28:22 2011
@@ -45,7 +45,7 @@ public class User implements UserDetails
     @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "userIdSeq")
     private Long id;
 
-    @Basic @Column(name = "username")
+    @Basic @Column(name = "username", unique = true)
     private String username;
 
     @Basic @Column(name = "password")
@@ -60,12 +60,13 @@ public class User implements UserDetails
     @Basic @Column(name = "enabled")
     private boolean enabled;
 
-    @Basic @Column(name="email")
+    @Basic @Column(name="email", unique = true)
     private String email;
 
     @Basic @Column(name="openid")
     private String openId;
 
+    @Transient
     private String confirmPassword;
 
     public User() {

Modified: incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/portal/repository/UserRepository.java
URL: http://svn.apache.org/viewvc/incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/portal/repository/UserRepository.java?rev=1162748&r1=1162747&r2=1162748&view=diff
==============================================================================
--- incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/portal/repository/UserRepository.java
(original)
+++ incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/portal/repository/UserRepository.java
Mon Aug 29 11:28:22 2011
@@ -22,6 +22,20 @@ import org.apache.rave.persistence.Repos
 import org.apache.rave.portal.model.User;
 
 public interface UserRepository extends Repository<User> {
+
+    /**
+     * Gets a {@link User} by its username
+     *
+     * @param username the (unique) name of the user
+     * @return {@link User} if one exists, otherwise {@literal null}
+     */
     User getByUsername(String username);
-	 User getByUserEmail(String userEmail);
+
+    /**
+     * Gets a {@link User} by its email address
+     *
+     * @param userEmail the (unique) email address of the user
+     * @return {@link User} if one exists, otherwise {@literal null}
+     */
+    User getByUserEmail(String userEmail);
 }

Modified: incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/portal/service/NewAccountService.java
URL: http://svn.apache.org/viewvc/incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/portal/service/NewAccountService.java?rev=1162748&r1=1162747&r2=1162748&view=diff
==============================================================================
--- incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/portal/service/NewAccountService.java
(original)
+++ incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/portal/service/NewAccountService.java
Mon Aug 29 11:28:22 2011
@@ -19,12 +19,15 @@
 package org.apache.rave.portal.service;
 
 
+import org.apache.rave.portal.model.NewUser;
+
 public interface NewAccountService {
 
-	 /**
-	  * Creates a new account using several other Rave services.
-	  * @param userName is the user name of the new account.
-	  * @param password is the account's password.
-	  */
-	 public void createNewAccount(String userName, String password, String pageLayout) throws
Exception;
+    /**
+     * Creates a new account using several other Rave services.
+     *
+     * @param newUser the {@link NewUser} from which a new {@link org.apache.rave.portal.model.User}
can be created
+     * @throws Exception in case something goes wrong
+     */
+    public void createNewAccount(NewUser newUser) throws Exception;
 }
\ No newline at end of file

Modified: incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/portal/service/UserService.java
URL: http://svn.apache.org/viewvc/incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/portal/service/UserService.java?rev=1162748&r1=1162747&r2=1162748&view=diff
==============================================================================
--- incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/portal/service/UserService.java
(original)
+++ incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/portal/service/UserService.java
Mon Aug 29 11:28:22 2011
@@ -48,20 +48,29 @@ public interface UserService extends Use
 	  */
 	 void registerNewUser(User user);
 
-	 /**
-	  * Return the requested user object using the user's name.
-	  */ 
-	 User getUserByUsername(String userName);
-	 
-	 /**
-	  * Return a user object by the user ID.
-	  */
-	 User getUserById(Long id);
+    /**
+     * Return the requested user object using the user's name.
+     *
+     * @param userName (unique) name of the user
+     * @return {@link User} if one exists, otherwise {@literal null}
+     */
+    User getUserByUsername(String userName);
 
-	 /**
-	  * Return a user object by the user email.
-	  */
-	 User getUserByEmail(String userEmail);
+    /**
+     * Return a user object by the user ID.
+     *
+     * @param id the user ID
+     * @return {@link User} if one exists, otherwise {@literal null}
+     */
+    User getUserById(Long id);
+
+    /**
+     * Return a user object by the user email.
+     *
+     * @param userEmail email address of the user
+     * @return {@link User} if one exists, otherwise {@literal null}
+     */
+    User getUserByEmail(String userEmail);
 
 	 /**
 	  * Update the user profile information.

Modified: incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/portal/web/controller/NewAccountController.java
URL: http://svn.apache.org/viewvc/incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/portal/web/controller/NewAccountController.java?rev=1162748&r1=1162747&r2=1162748&view=diff
==============================================================================
--- incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/portal/web/controller/NewAccountController.java
(original)
+++ incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/portal/web/controller/NewAccountController.java
Mon Aug 29 11:28:22 2011
@@ -71,8 +71,7 @@ public class NewAccountController {
 		  //Now attempt to create the account.
 		  try {
 			    logger.debug("newaccount.jsp: passed form validation");
-			    newAccountService.createNewAccount(newUser.getUsername(),newUser.getPassword(),
-                        newUser.getPageLayout());
+			    newAccountService.createNewAccount(newUser);
 				return ViewNames.REDIRECT;
 		  } catch (org.springframework.dao.IncorrectResultSizeDataAccessException ex) {
 				//This exception is thrown if the account already exists.

Modified: incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/portal/web/validator/NewAccountValidator.java
URL: http://svn.apache.org/viewvc/incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/portal/web/validator/NewAccountValidator.java?rev=1162748&r1=1162747&r2=1162748&view=diff
==============================================================================
--- incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/portal/web/validator/NewAccountValidator.java
(original)
+++ incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/portal/web/validator/NewAccountValidator.java
Mon Aug 29 11:28:22 2011
@@ -20,6 +20,7 @@
 package org.apache.rave.portal.web.validator;
 
 import org.apache.commons.lang.StringUtils;
+import org.apache.commons.validator.EmailValidator;
 import org.apache.rave.portal.model.NewUser;
 import org.apache.rave.portal.service.UserService;
 import org.slf4j.Logger;
@@ -31,6 +32,11 @@ import org.springframework.validation.Va
 
 public class NewAccountValidator implements Validator {
 
+    private static final int MINIMUM_PASSWORD_LENGTH = 4;
+    private static final String FIELD_USERNAME = "username";
+    private static final String FIELD_PASSWORD = "password";
+    private static final String FIELD_CONFIRM_PASSWORD = "confirmPassword";
+    private static final String FIELD_EMAIL = "email";
     private final Logger logger = LoggerFactory.getLogger(getClass());
 
     private static final String USERNAME_PATTERN = "[\\w\\+\\-\\.@]{2,}";
@@ -49,55 +55,80 @@ public class NewAccountValidator impleme
         logger.debug("Validator called");
         NewUser newUser = (NewUser) obj;
 
-        //check if the username is null or empty
+        validateUsername(errors, newUser);
+        validatePassword(errors, newUser);
+        validateConfirmPassword(errors, newUser);
+        validateEmail(errors, newUser);
+
+        writeResultToLog(errors);
+    }
+
+    private void validateUsername(Errors errors, NewUser newUser) {
         final String username = newUser.getUsername();
         if (StringUtils.isBlank(username)) {
-            errors.rejectValue("username", "username.required");
+            errors.rejectValue(FIELD_USERNAME, "username.required");
             logger.info("Username required");
-        }
-
-        // at least 2 characters of the following: a-z A-Z 0-9 _ - + . @
-        else if (!username.matches(USERNAME_PATTERN)) {
-            errors.rejectValue("username", "username.invalid.pattern");
-            logger.info("Username must be atleast 2 characters long");
-        }
-
-        //check if username is already in use
-        else if (userService.getUserByUsername(username) != null) {
-            errors.rejectValue("username", "username.exits");
+        } else if (!username.matches(USERNAME_PATTERN)) {
+            errors.rejectValue(FIELD_USERNAME, "username.invalid.pattern");
+            logger.info("Username has invalid pattern");
+        } else if (isExistingUsername(username)) {
+            errors.rejectValue(FIELD_USERNAME, "username.exists");
             logger.info("Username already exists");
         }
+    }
 
+    private boolean isExistingUsername(String username) {
+        return userService.getUserByUsername(username) != null;
+    }
 
-        //check if the password is null
+    private void validatePassword(Errors errors, NewUser newUser) {
         if (StringUtils.isBlank(newUser.getPassword())) {
-            errors.rejectValue("password", "password.required");
+            errors.rejectValue(FIELD_PASSWORD, "password.required");
             logger.info("Password required");
+        } else if (newUser.getPassword().length() < MINIMUM_PASSWORD_LENGTH) {
+            errors.rejectValue(FIELD_PASSWORD, "password.invalid.length");
+            logger.info("Password must be at least {} characters long", MINIMUM_PASSWORD_LENGTH);
         }
+    }
 
-        //check if the password length is less than 4
-        else if (newUser.getPassword().length() < 4) {
-            errors.rejectValue("password", "password.invalid.lenght");
-            logger.info("Password must be atleast 4 characters long");
-        }
-
-        //check if the confirm password is null
+    private void validateConfirmPassword(Errors errors, NewUser newUser) {
         if (StringUtils.isBlank(newUser.getConfirmPassword())) {
-            errors.rejectValue("confirmPassword", "confirmPassword.required");
+            errors.rejectValue(FIELD_CONFIRM_PASSWORD, "confirmPassword.required");
             logger.info("Confirm Password required");
+        } else if (isConfirmPasswordDifferentThanPassword(newUser)) {
+            errors.rejectValue(FIELD_CONFIRM_PASSWORD, "confirmPassword.mismatch");
+            logger.info("Password mismatch");
         }
+    }
 
-        //check if the confirm password matches the previous entered password
-        //first check for null
-        if (newUser.getConfirmPassword() != null &&
-                !(newUser.getConfirmPassword().equals(newUser.getPassword()))) {
-            errors.rejectValue("confirmPassword", "confirmPassword.mismatch");
-            logger.info("Password mismatch");
+    private boolean isConfirmPasswordDifferentThanPassword(NewUser newUser) {
+        return !(newUser.getConfirmPassword().equals(newUser.getPassword()));
+    }
+
+    private void validateEmail(Errors errors, NewUser newUser) {
+        if (StringUtils.isBlank(newUser.getEmail())) {
+            errors.rejectValue(FIELD_EMAIL, "email.required");
+        } else if (isInvalidEmailAddress(newUser.getEmail())) {
+            errors.rejectValue(FIELD_EMAIL, "email.invalid");
+        } else if (isExistingEmailAddress(newUser.getEmail())) {
+            errors.rejectValue(FIELD_EMAIL, "email.exists");
         }
+    }
+
+    private boolean isInvalidEmailAddress(String emailAddress) {
+        return !EmailValidator.getInstance().isValid(emailAddress);
+    }
+
+    private boolean isExistingEmailAddress(String email) {
+        return userService.getUserByEmail(email) != null;
+    }
 
+    private void writeResultToLog(Errors errors) {
         if (errors.hasErrors()) {
-            for (ObjectError error : errors.getAllErrors()) {
-                logger.info("Validation error: " + error.toString());
+            if (logger.isInfoEnabled()) {
+                for (ObjectError error : errors.getAllErrors()) {
+                    logger.info("Validation error: {}", error.toString());
+                }
             }
         } else {
             logger.debug("Validation successful");

Modified: incubator/rave/trunk/rave-portal/src/main/resources/initial_data.sql
URL: http://svn.apache.org/viewvc/incubator/rave/trunk/rave-portal/src/main/resources/initial_data.sql?rev=1162748&r1=1162747&r2=1162748&view=diff
==============================================================================
--- incubator/rave/trunk/rave-portal/src/main/resources/initial_data.sql (original)
+++ incubator/rave/trunk/rave-portal/src/main/resources/initial_data.sql Mon Aug 29 11:28:22
2011
@@ -17,43 +17,43 @@
 
 --  --- start user data ---
 insert into user (user_id, username, password, expired, locked, enabled, email)
-values (set(@user_id_1, next value for user_id_seq), 'canonical', 'b97fd0fa25ba8a504309be2b6651ac6dee167ded',
'N', 'N', 'Y','canonical@test.com');
+values (set(@user_id_1, next value for user_id_seq), 'canonical', 'b97fd0fa25ba8a504309be2b6651ac6dee167ded',
'N', 'N', 'Y','canonical@example.com');
 
 insert into user (user_id, username, password, expired, locked, enabled, email)
-values (set(@user_id_2, next value for user_id_seq), 'john.doe', '49e5f5c7c7ae8372af9b3063c493f080d16411f5',
'N', 'N', 'Y',' ');
+values (set(@user_id_2, next value for user_id_seq), 'john.doe', '49e5f5c7c7ae8372af9b3063c493f080d16411f5',
'N', 'N', 'Y','john.doe@example.com');
 
 insert into user (user_id, username, password, expired, locked, enabled, email)
-values (set(@user_id_3, next value for user_id_seq), 'jane.doe', '30dd37e81704bbbd4e235c22990802ae25b187da',
'N', 'N', 'Y',' ');
+values (set(@user_id_3, next value for user_id_seq), 'jane.doe', '30dd37e81704bbbd4e235c22990802ae25b187da',
'N', 'N', 'Y','jane.doe@example.net');
 
 insert into user (user_id, username, password, expired, locked, enabled, email)
-values (set(@user_id_4, next value for user_id_seq), 'george.doe', '452802e3f2ff8b7b28785f50dfaaaaf80fc1430f',
'N', 'N', 'Y',' ');
+values (set(@user_id_4, next value for user_id_seq), 'george.doe', '452802e3f2ff8b7b28785f50dfaaaaf80fc1430f',
'N', 'N', 'Y','george.doe@example.org');
 
 insert into user (user_id, username, password, expired, locked, enabled, email)
-values (set(@user_id_5, next value for user_id_seq),'mario.rossi', '8aadae9f6e73a479cb8a565bcfa6e8de2b074e89',
'N', 'N', 'Y',' ');
+values (set(@user_id_5, next value for user_id_seq),'mario.rossi', '8aadae9f6e73a479cb8a565bcfa6e8de2b074e89',
'N', 'N', 'Y','mario.rossi@example.com');
 
 insert into user (user_id, username, password, expired, locked, enabled, email)
-values (set(@user_id_6, next value for user_id_seq), 'maija.m', '18550acca1b36af6cfa41c82e1caab12073475a1',
'N', 'N', 'Y',' ');
+values (set(@user_id_6, next value for user_id_seq), 'maija.m', '18550acca1b36af6cfa41c82e1caab12073475a1',
'N', 'N', 'Y','maijam@example.com');
 
 insert into user (user_id, username, password, expired, locked, enabled, email)
-values (set(@user_id_6, next value for user_id_seq), 'http://rave2011.myopenid.com/', 'cdf15c184b7d2539b0cfc29ee9f10bad62793d50',
'N', 'N', 'Y',' ');
+values (set(@user_id_6, next value for user_id_seq), 'http://rave2011.myopenid.com/', 'cdf15c184b7d2539b0cfc29ee9f10bad62793d50',
'N', 'N', 'Y','rave2011_openid@example.org');
 
 insert into user (user_id, username, password, expired, locked, enabled, email)
-values (set(@user_id_7, next value for user_id_seq), 'one.col', '07acee6193e84ba9ae2f7b2bf26538f2d6e4b0a1',
'N', 'N', 'Y',' ');
+values (set(@user_id_7, next value for user_id_seq), 'one.col', '07acee6193e84ba9ae2f7b2bf26538f2d6e4b0a1',
'N', 'N', 'Y','one.col@example.com');
 
 insert into user (user_id, username, password, expired, locked, enabled, email)
-values (set(@user_id_8, next value for user_id_seq), 'twown.col', '24159ea43cbcecb50021cd14a1d41a8079fd9714',
'N', 'N', 'Y',' ');
+values (set(@user_id_8, next value for user_id_seq), 'twown.col', '24159ea43cbcecb50021cd14a1d41a8079fd9714',
'N', 'N', 'Y','twown.col@example.com');
 
 insert into user (user_id, username, password, expired, locked, enabled, email)
-values (set(@user_id_9, next value for user_id_seq), 'three.col', 'c736434430af90772bfd4351bffa3da04cec0403',
'N', 'N', 'Y',' ');
+values (set(@user_id_9, next value for user_id_seq), 'three.col', 'c736434430af90772bfd4351bffa3da04cec0403',
'N', 'N', 'Y','three.col@example.com');
 
 insert into user (user_id, username, password, expired, locked, enabled, email)
-values (set(@user_id_10, next value for user_id_seq), 'threewn.col', 'ad67065a5bc25f86036508971a09a58e9c9131e8',
'N', 'N', 'Y',' ');
+values (set(@user_id_10, next value for user_id_seq), 'threewn.col', 'ad67065a5bc25f86036508971a09a58e9c9131e8',
'N', 'N', 'Y','threewn.col@example.com');
 
 insert into user (user_id, username, password, expired, locked, enabled, email)
-values (set(@user_id_11, next value for user_id_seq), 'four.col', 'c875ce4416fc56cd34c01bd366a3af5468137155',
'N', 'N', 'Y',' ');
+values (set(@user_id_11, next value for user_id_seq), 'four.col', 'c875ce4416fc56cd34c01bd366a3af5468137155',
'N', 'N', 'Y','four.col@example.com');
 
 insert into user (user_id, username, password, expired, locked, enabled, email)
-values (set(@user_id_12, next value for user_id_seq), 'fourwn.col', 'eb0b450eff79a33027a41a05051f5609a83667e8',
'N', 'N', 'Y',' ');
+values (set(@user_id_12, next value for user_id_seq), 'fourwn.col', 'eb0b450eff79a33027a41a05051f5609a83667e8',
'N', 'N', 'Y','fourwn.col@example.com');
 --- end user data ---
 
 --- gadget data ---

Modified: incubator/rave/trunk/rave-portal/src/main/resources/messages.properties
URL: http://svn.apache.org/viewvc/incubator/rave/trunk/rave-portal/src/main/resources/messages.properties?rev=1162748&r1=1162747&r2=1162748&view=diff
==============================================================================
--- incubator/rave/trunk/rave-portal/src/main/resources/messages.properties (original)
+++ incubator/rave/trunk/rave-portal/src/main/resources/messages.properties Mon Aug 29 11:28:22
2011
@@ -21,14 +21,18 @@ username.required=Username required
 username.invalid.length=Username must be atleast 2 characters long
 username.invalid.pattern=Username must be at least 2 characters long and may only contain
letters, numbers, \
   _-+.@
-username.exits=Username already exists
+username.exists=Username already exists
 
 password.required=Password required
-password.invalid.lenght=Password must be atleast 4 characters long
+password.invalid.length=Password must be at least 4 characters long
 
 confirmPassword.required=Confirm Password required
 confirmPassword.mismatch=Password mismatch
 
+email.required=Email required
+email.invalid=This is not a valid email address
+email.exists=This email address already exists for a user
+
 form.some.fields.required=Field marked with * are required
 
 page.general.back=Back to Rave

Modified: incubator/rave/trunk/rave-portal/src/main/webapp/WEB-INF/views/newaccount.jsp
URL: http://svn.apache.org/viewvc/incubator/rave/trunk/rave-portal/src/main/webapp/WEB-INF/views/newaccount.jsp?rev=1162748&r1=1162747&r2=1162748&view=diff
==============================================================================
--- incubator/rave/trunk/rave-portal/src/main/webapp/WEB-INF/views/newaccount.jsp (original)
+++ incubator/rave/trunk/rave-portal/src/main/webapp/WEB-INF/views/newaccount.jsp Mon Aug
29 11:28:22 2011
@@ -44,6 +44,13 @@
                 <form:errors path="confirmPassword" cssClass="error" />
             </p>
             <p>
+              <label for="emailField">Email address:</label>
+              <spring:bind path="email">
+                <input type="email" name="email" id="emailField" required="required"/>
+              </spring:bind>
+              <form:errors path="email" cssClass="error"/>
+            </p>
+            <p>
                 <label for="pageLayoutField">Select Page Layout:</label>
                 <form:select path="pageLayout" id="pageLayoutField">
                     <form:option value="columns_1" id="columns_1_id">One Column</form:option>

Modified: incubator/rave/trunk/rave-portal/src/test/java/org/apache/rave/portal/repository/JpaUserRepositoryTest.java
URL: http://svn.apache.org/viewvc/incubator/rave/trunk/rave-portal/src/test/java/org/apache/rave/portal/repository/JpaUserRepositoryTest.java?rev=1162748&r1=1162747&r2=1162748&view=diff
==============================================================================
--- incubator/rave/trunk/rave-portal/src/test/java/org/apache/rave/portal/repository/JpaUserRepositoryTest.java
(original)
+++ incubator/rave/trunk/rave-portal/src/test/java/org/apache/rave/portal/repository/JpaUserRepositoryTest.java
Mon Aug 29 11:28:22 2011
@@ -50,7 +50,7 @@ public class JpaUserRepositoryTest {
     //may need updating in the future.
     private static final String HASHED_SALTED_PASSWORD="b97fd0fa25ba8a504309be2b6651ac6dee167ded";
     private static final Long INVALID_USER = -2L;
-	 private static final String USER_EMAIL = "canonical@test.com";
+	 private static final String USER_EMAIL = "canonical@example.com";
 
     @Autowired
     private UserRepository repository;

Modified: incubator/rave/trunk/rave-portal/src/test/java/org/apache/rave/portal/service/NewAccountServiceTest.java
URL: http://svn.apache.org/viewvc/incubator/rave/trunk/rave-portal/src/test/java/org/apache/rave/portal/service/NewAccountServiceTest.java?rev=1162748&r1=1162747&r2=1162748&view=diff
==============================================================================
--- incubator/rave/trunk/rave-portal/src/test/java/org/apache/rave/portal/service/NewAccountServiceTest.java
(original)
+++ incubator/rave/trunk/rave-portal/src/test/java/org/apache/rave/portal/service/NewAccountServiceTest.java
Mon Aug 29 11:28:22 2011
@@ -19,6 +19,7 @@
 
 package org.apache.rave.portal.service;
 
+import org.apache.rave.portal.model.NewUser;
 import org.apache.rave.portal.model.PageLayout;
 import org.apache.rave.portal.model.User;
 import org.apache.rave.portal.service.impl.DefaultNewAccountService;
@@ -52,14 +53,13 @@ public class NewAccountServiceTest {
         String validUser = "valid.user";
         String validPass = "valid.password";
         String validLayout = "valid.layout";
+        String validEmail = "valid.email";
 
-        User newUser = new User();
+        NewUser newUser = new NewUser();
         newUser.setUsername(validUser);
         newUser.setPassword(validPass);
         newUser.setConfirmPassword(validPass);
-        newUser.setExpired(false);
-        newUser.setLocked(false);
-        newUser.setEnabled(true);
+        newUser.setEmail(validEmail);
 
 
         SaltSource saltSource = createNiceMock(SaltSource.class);
@@ -80,12 +80,14 @@ public class NewAccountServiceTest {
         expect(pageLayoutService.getPageLayoutByCode(validLayout)).andReturn(pageLayout);
         replay(userService, pageLayoutService);
 
-        newAccountService.createNewAccount(validUser, validPass, validLayout);
+        newAccountService.createNewAccount(newUser);
     }
 
     @Test
-    public void failedAccountCreationTest() throws Exception {
+    public void failedAccountCreationTest_duplicateUsername() throws Exception {
         String duplicateUserName = "duplicateUserName";
+        NewUser newUser = new NewUser();
+        newUser.setUsername(duplicateUserName);
         User existingUser = new User();
         existingUser.setUsername(duplicateUserName);
 
@@ -93,13 +95,35 @@ public class NewAccountServiceTest {
         replay(userService);
 
         try {
-            newAccountService.createNewAccount(duplicateUserName, "", "");
+            newAccountService.createNewAccount(newUser);
             fail();
         } catch (IllegalArgumentException e) {
             logger.debug("Expected failure of account creation due to duplicate name");
         }
     }
 
+    @Test
+    public void failedAccountCreationTest_duplicateEmail() throws Exception {
+        String duplicateEmail = "duplicateEmail";
+        NewUser newUser = new NewUser();
+        newUser.setUsername("newUser");
+        newUser.setEmail(duplicateEmail);
+        User existingUser = new User();
+        existingUser.setEmail(duplicateEmail);
+
+        expect(userService.getUserByUsername("newUser")).andReturn(null);
+        expect(userService.getUserByEmail(duplicateEmail)).andReturn(existingUser);
+        replay(userService);
+
+        try {
+            newAccountService.createNewAccount(newUser);
+            fail();
+        } catch (IllegalArgumentException e) {
+            logger.debug("Expected failure of account creation due to duplicate email");
+        }
+    }
+
+
     @Before
     public void setup() {
         userService = createNiceMock(UserService.class);

Modified: incubator/rave/trunk/rave-portal/src/test/java/org/apache/rave/portal/web/validator/NewAccountValidatorTest.java
URL: http://svn.apache.org/viewvc/incubator/rave/trunk/rave-portal/src/test/java/org/apache/rave/portal/web/validator/NewAccountValidatorTest.java?rev=1162748&r1=1162747&r2=1162748&view=diff
==============================================================================
--- incubator/rave/trunk/rave-portal/src/test/java/org/apache/rave/portal/web/validator/NewAccountValidatorTest.java
(original)
+++ incubator/rave/trunk/rave-portal/src/test/java/org/apache/rave/portal/web/validator/NewAccountValidatorTest.java
Mon Aug 29 11:28:22 2011
@@ -27,6 +27,7 @@ import org.junit.Test;
 import org.springframework.validation.BindException;
 import org.springframework.validation.Errors;
 
+import static junit.framework.Assert.assertEquals;
 import static junit.framework.Assert.assertFalse;
 import static junit.framework.Assert.assertNotNull;
 import static junit.framework.Assert.assertTrue;
@@ -41,9 +42,11 @@ public class NewAccountValidatorTest {
     private static final String VALID_NAME = "valid.name";
     private static final String VALID_PASSWORD = "valid.password";
     private static final String VALID_PAGELAYOUT = "valid.pagelayout";
+    private static final String VALID_EMAIL = "valid.email@example.com";
     private static final String FIELD_USERNAME = "username";
     private static final String FIELD_PASSWORD = "password";
     private static final String FIELD_CONFIRM_PASSWORD = "confirmPassword";
+    private static final String FIELD_EMAIL = "email";
     private static final String NEW_USER = "newUser";
 
     private NewAccountValidator newAccountValidator;
@@ -62,9 +65,11 @@ public class NewAccountValidatorTest {
         newUser.setPassword(VALID_PASSWORD);
         newUser.setConfirmPassword(VALID_PASSWORD);
         newUser.setPageLayout(VALID_PAGELAYOUT);
+        newUser.setEmail(VALID_EMAIL);
         Errors errors = new BindException(newUser, NEW_USER);
 
-        expect(mockUserService.getUserByUsername("valid.name")).andReturn(null);
+        expect(mockUserService.getUserByUsername(VALID_NAME)).andReturn(null);
+        expect(mockUserService.getUserByEmail(VALID_EMAIL)).andReturn(null);
         replay(mockUserService);
 
         newAccountValidator.validate(newUser, errors);
@@ -81,10 +86,11 @@ public class NewAccountValidatorTest {
 
         newAccountValidator.validate(newUser, errors);
 
-        assertTrue("Validation errors", errors.hasErrors());
+        assertEquals("4 Validation errors", 4, errors.getErrorCount());
         assertNotNull(errors.getFieldError(FIELD_USERNAME));
         assertNotNull(errors.getFieldError(FIELD_PASSWORD));
         assertNotNull(errors.getFieldError(FIELD_CONFIRM_PASSWORD));
+        assertNotNull(errors.getFieldError(FIELD_EMAIL));
 
     }
 
@@ -96,18 +102,41 @@ public class NewAccountValidatorTest {
         newUser.setPassword(VALID_PASSWORD);
         newUser.setConfirmPassword(VALID_PASSWORD);
         newUser.setPageLayout(VALID_PAGELAYOUT);
+        newUser.setEmail(VALID_EMAIL);
         Errors errors = new BindException(newUser, NEW_USER);
 
         User user = createMock(User.class);
         expect(mockUserService.getUserByUsername("ExistingUser")).andReturn(user);
+        expect(mockUserService.getUserByEmail(VALID_EMAIL)).andReturn(null);
         replay(mockUserService);
 
         newAccountValidator.validate(newUser, errors);
 
-        assertTrue("Validation errors", errors.hasErrors());
+        assertEquals("1 Validation error", 1, errors.getErrorCount());
         assertNotNull(errors.getFieldError(FIELD_USERNAME));
     }
 
+    @Test
+    public void testValidationFailsOnExistingEmail() throws Exception {
+        NewUser newUser = new NewUser();
+        newUser.setUsername(VALID_NAME);
+        newUser.setPassword(VALID_PASSWORD);
+        newUser.setConfirmPassword(VALID_PASSWORD);
+        newUser.setPageLayout(VALID_PAGELAYOUT);
+        newUser.setEmail("existing@localhost");
+        Errors errors = new BindException(newUser, NEW_USER);
+
+        User user = createMock(User.class);
+        expect(mockUserService.getUserByUsername(VALID_NAME)).andReturn(null);
+        expect(mockUserService.getUserByEmail("existing@localhost")).andReturn(user);
+        replay(mockUserService);
+
+        newAccountValidator.validate(newUser, errors);
+
+        assertEquals("1 Validation error", 1, errors.getErrorCount());
+        assertNotNull(errors.getFieldError(FIELD_EMAIL));
+    }
+
 
     @Test
     public void testValidationFailsOnShortUserName() throws Exception {
@@ -116,31 +145,35 @@ public class NewAccountValidatorTest {
         newUser.setPassword(VALID_PASSWORD);
         newUser.setConfirmPassword(VALID_PASSWORD);
         newUser.setPageLayout(VALID_PAGELAYOUT);
+        newUser.setEmail(VALID_EMAIL);
         Errors errors = new BindException(newUser, NEW_USER);
         expect(mockUserService.getUserByUsername("A")).andReturn(null);
+        expect(mockUserService.getUserByEmail(VALID_EMAIL)).andReturn(null);
         replay(mockUserService);
 
         newAccountValidator.validate(newUser, errors);
 
-        assertTrue("Validation errors", errors.hasErrors());
+        assertEquals("1 Validation error", 1, errors.getErrorCount());
         assertNotNull(errors.getFieldError(FIELD_USERNAME));
     }
 
     @Test
-    public void testValidationFailsOnIllegalCharacters() throws Exception {
+    public void testValidationFailsOnIllegalUsername() throws Exception {
         NewUser newUser = new NewUser();
         final String badUsername = "x'; DROP TABLE members; --";
         newUser.setUsername(badUsername);
         newUser.setPassword(VALID_PASSWORD);
         newUser.setConfirmPassword(VALID_PASSWORD);
         newUser.setPageLayout(VALID_PAGELAYOUT);
+        newUser.setEmail(VALID_EMAIL);
         Errors errors = new BindException(newUser, NEW_USER);
         expect(mockUserService.getUserByUsername(badUsername)).andReturn(null);
+        expect(mockUserService.getUserByEmail(VALID_EMAIL)).andReturn(null);
         replay(mockUserService);
 
         newAccountValidator.validate(newUser, errors);
 
-        assertTrue("Validation errors", errors.hasErrors());
+        assertEquals("1 Validation error", 1, errors.getErrorCount());
         assertNotNull(errors.getFieldError(FIELD_USERNAME));
     }
 
@@ -151,13 +184,15 @@ public class NewAccountValidatorTest {
         newUser.setPassword("123");
         newUser.setConfirmPassword("123");
         newUser.setPageLayout(VALID_PAGELAYOUT);
+        newUser.setEmail(VALID_EMAIL);
         Errors errors = new BindException(newUser, NEW_USER);
         expect(mockUserService.getUserByUsername(VALID_NAME)).andReturn(null);
+        expect(mockUserService.getUserByEmail(VALID_EMAIL)).andReturn(null);
         replay(mockUserService);
 
         newAccountValidator.validate(newUser, errors);
 
-        assertTrue("Validation errors", errors.hasErrors());
+        assertEquals("1 Validation error", 1, errors.getErrorCount());
         assertNotNull(errors.getFieldError(FIELD_PASSWORD));
     }
 
@@ -168,13 +203,15 @@ public class NewAccountValidatorTest {
         newUser.setPassword(VALID_PASSWORD);
         newUser.setConfirmPassword("doesnotmatch");
         newUser.setPageLayout(VALID_PAGELAYOUT);
+        newUser.setEmail(VALID_EMAIL);
         Errors errors = new BindException(newUser, NEW_USER);
         expect(mockUserService.getUserByUsername(VALID_NAME)).andReturn(null);
+        expect(mockUserService.getUserByEmail(VALID_EMAIL)).andReturn(null);
         replay(mockUserService);
 
         newAccountValidator.validate(newUser, errors);
 
-        assertTrue("Validation errors", errors.hasErrors());
+        assertEquals("1 Validation error", 1, errors.getErrorCount());
         assertNotNull(errors.getFieldError(FIELD_CONFIRM_PASSWORD));
     }
 

Modified: incubator/rave/trunk/rave-shindig/src/main/resources/initial_data.sql
URL: http://svn.apache.org/viewvc/incubator/rave/trunk/rave-shindig/src/main/resources/initial_data.sql?rev=1162748&r1=1162747&r2=1162748&view=diff
==============================================================================
--- incubator/rave/trunk/rave-shindig/src/main/resources/initial_data.sql (original)
+++ incubator/rave/trunk/rave-shindig/src/main/resources/initial_data.sql Mon Aug 29 11:28:22
2011
@@ -21,11 +21,9 @@ VALUES (set(@person_id_1, next value for
 INSERT INTO person(id, username, display_name, gender)
 VALUES (set(@person_id_2, next value for person_id_seq), 'john.doe', 'John Doe', 'male');
 
-
 INSERT INTO person(id, username, display_name, gender)
 VALUES (set(@person_id_3, next value for person_id_seq), 'jane.doe', 'Jane Doe', 'female');
 
-
 INSERT INTO person(id, username, display_name)
 VALUES (set(@person_id_4, next value for person_id_seq), 'george.doe', 'George Doe');
 



Mime
View raw message