Commits

Juan Carlos Picado Herrera committed 99bf29f

Flow on SignUp User, In progress

  • Participants
  • Parent commits 526f4d4

Comments (0)

Files changed (9)

encuestame-business/src/main/java/org/encuestame/business/service/SecurityService.java

 package org.encuestame.business.service;
 
 import java.util.ArrayList;
+import java.util.Calendar;
 import java.util.Collection;
 import java.util.Date;
 import java.util.HashSet;
     /** Anonnymous User. **/
     private static final String ANONYMOUS = EnMePermission.ENCUESTAME_ANONYMOUS.name();
 
+
+    private final Integer DEFAULT_LENGTH_PASSWORD = 8;
+
     /** Suspended Notification. **/
     private Boolean suspendedNotification;
 
      * @return {@link UnitUserBean}.
      */
     public UnitUserBean singupUser(final SignUpBean singUpBean){
+        log.debug("singupUser "+singUpBean.toString());
         final Account account = new Account();
         getAccountDao().saveOrUpdate(account);
         final UserAccount userAccount = new UserAccount();
         userAccount.setUsername(singUpBean.getUsername());
-        userAccount.setPassword(encodingPassword(singUpBean.getPassword()));
-        userAccount.setEnjoyDate(new Date());
+        userAccount.setPassword(encodingPassword(singUpBean.getPassword() == null
+                ? EnMePasswordUtils.createRandomPassword(this.DEFAULT_LENGTH_PASSWORD) : singUpBean.getPassword() ));
+        userAccount.setEnjoyDate(Calendar.getInstance().getTime()); //current date
         userAccount.setAccount(account);
         userAccount.setUserStatus(Boolean.TRUE);
         userAccount.setUserEmail(singUpBean.getEmail());
         userAccount.setCompleteName("");
-        userAccount.setInviteCode(""); //TODO: invite code?
+        userAccount.setInviteCode("12345678910");
         getAccountDao().saveOrUpdate(userAccount);
+        log.debug("singupUser created user account");
         //Add default permissions, if user is signup we should add admin access
         final Set<Permission> permissions = new HashSet<Permission>();
         permissions.add(getPermissionByName(SecurityService.DEFAULT));
         permissions.add(getPermissionByName(SecurityService.PUBLISHER));
         permissions.add(getPermissionByName(SecurityService.EDITOR));
         this.assingPermission(userAccount, permissions);
+        log.debug("singupUser assigned default user account");
         //Create login.
         setSpringSecurityAuthentication(singUpBean.getUsername(), singUpBean.getPassword(), permissions);
+        log.debug("singupUser autenticated");
         if(this.suspendedNotification){
             getServiceMail().sendPasswordConfirmationEmail(singUpBean);
         }
-        log.info("new user "+userAccount.getUsername());
-        log.info("Get Authoritie Name"+SecurityContextHolder.getContext().getAuthentication().getName());
+        log.debug("singupUser notificated");
+        log.debug("new user "+userAccount.getUsername());
+        log.debug("Get Authoritie Name"+SecurityContextHolder.getContext().getAuthentication().getName());
         return ConvertDomainBean.convertSecondaryUserToUserBean(userAccount);
     }
 
     /**
+     * User Account Is Activated.
+     * @param signUpBean
+     * @return
+     */
+    public Boolean isActivated(final SignUpBean signUpBean){
+        return true;
+    }
+
+    /**
      * Ecrypt Password with Jasypt.
      * @param password password
      * @return

encuestame-business/src/main/java/org/encuestame/business/service/imp/ISecurityService.java

      * @throws EnmeFailOperation
      */
     void changeUserStatus(final String username) throws EnmeFailOperation;
+
+    /**
+     * User Account Is Activated.
+     * @param signUpBean
+     * @return
+     */
+    Boolean isActivated(final SignUpBean signUpBean);
 }

encuestame-core/src/main/java/org/encuestame/core/security/util/EnMePasswordUtils.java

 
 package org.encuestame.core.security.util;
 
+import java.util.Random;
+
+import org.apache.commons.lang.RandomStringUtils;
 import org.jasypt.util.password.StrongPasswordEncryptor;
 
 /**
 public class EnMePasswordUtils {
 
     /**
+     * Create Random Password.
+     * @param length
+     * @return
+     */
+    public final static String createRandomPassword(final int length){
+        return PasswordGenerator.getPassword(length);
+    }
+
+    /**
      * Encrypt the password.
      * @param password password
      * @return password encrypt

encuestame-utils/src/main/java/org/encuestame/utils/security/SignUpBean.java

     public void setCaptcha(String captcha) {
         this.captcha = captcha;
     }
+
+    /* (non-Javadoc)
+     * @see java.lang.Object#toString()
+     */
+    @Override
+    public String toString() {
+        StringBuilder builder = new StringBuilder();
+        builder.append("SignUpBean [fullName=").append(fullName)
+                .append(", username=").append(username).append(", password=")
+                .append(password).append(", email=").append(email)
+                .append(", captcha=").append(captcha).append("]");
+        return builder.toString();
+    }
 }

encuestame-war/src/main/webapp/WEB-INF/flows/signup/findFriends.jsp

         <div class="form">
             find friends.
         </div>
-        <form>
-            <a href="next">Next</a>
-        </form>
+         <form:form modelAttribute="signUpBean">
+            <input type="submit" name="_eventId_next" value="Next"/>
+        </form:form>
     </div>
 <%@ include file="/WEB-INF/jsp/includes/footer.jsp" %>

encuestame-war/src/main/webapp/WEB-INF/flows/signup/profile.jsp

         <div class="form">
             profile
         </div>
-        <form>
-            <a href="next">Next</a>
-        </form>
+        <form:form modelAttribute="signUpBean">
+            <input type="submit" name="_eventId_next" value="Next"/>
+        </form:form>
     </div>
 <%@ include file="/WEB-INF/jsp/includes/footer.jsp" %>

encuestame-war/src/main/webapp/WEB-INF/flows/signup/signup-flow.xml

 
     <var name="signUpBean" class="org.encuestame.utils.security.SignUpBean" />
 
-    <persistence-context />
-
     <view-state id="signup" model="signUpBean">
         <binder>
             <binding property="username" />
             <binding property="email" />
             <binding property="captcha" />
         </binder>
-        <transition on="saveUser" to="findFriends" />
-
-
+        <transition on="saveUser" to="findFriends" >
+               <evaluate expression="securityService.singupUser(signUpBean)" result="flowScope.userAccount"
+                         result-type="org.encuestame.utils.web.UnitUserBean"/>
+        </transition>
     </view-state>
 
     <view-state id="findFriends" model="signUpBean">
     </view-state>
 
     <view-state id="profile" model="signUpBean">
-        <transition on="next" to="profile" />
+        <transition on="next" to="isActivated" />
     </view-state>
 
-    <end-state id="profile"
-        view="externalRedirect:contextRelative:/account/dashboard" commit="false" />
+     <view-state id="noActivated" model="signUpBean">
+        <transition on="review" to="isActivated" />
+    </view-state>
+
+    <action-state id="isActivated">
+        <evaluate expression="securityService.isActivated(signUpBean)" />
+        <transition on="yes" to="dashboard">
+        </transition>
+        <transition on="no" to="noActivated" />
+    </action-state>
+
+    <end-state id="dashboard" view="externalRedirect:contextRelative:/account/dashboard.do"></end-state>
 
 
 </flow>

encuestame-war/src/main/webapp/WEB-INF/flows/signup/signup.jsp

                     <div class="recaptcha">
                         <c:out value="${signUpBean.captcha}" escapeXml="false" />
                         <br />
-                        <form:errors path="capcetcha" cssClass="error" />
+                        <form:errors path="captcha" cssClass="error" />
                     </div>
                     <div class="form-submit-buttons">
                         <input type="submit" id="saveUser" name="_eventId_saveUser" value="Sign Up"/>
             </activation>
             <properties>
                 <encuestame.logs.path>logs</encuestame.logs.path>
-                <surefire.failures.ignore>true</surefire.failures.ignore>
+                <surefire.failures.ignore>false</surefire.failures.ignore>
                 <app.proxypass>true</app.proxypass>
                 <!-- Encuestame Properties -->
                 <encuestame.properties.path>classpath:encuestame-config.properties</encuestame.properties.path>