1. Juan Carlos Picado Herrera
  2. encuestame

Commits

Juan Carlos Picado Herrera  committed 81839bc

Refactored Login and Forgot Page

  • Participants
  • Parent commits 3e822d9
  • Branches master

Comments (0)

Files changed (11)

File encuestame-mvc/src/main/java/org/encuestame/mvc/controller/security/ForgetPasswordController.java

View file
 
 import org.apache.log4j.Logger;
 import org.encuestame.core.security.util.PasswordGenerator;
+import org.encuestame.core.util.ConvertDomainBean;
 import org.encuestame.mvc.validator.ValidateOperations;
+import org.encuestame.persistence.domain.security.UserAccount;
+import org.encuestame.persistence.exception.EnMeExpcetion;
 import org.encuestame.persistence.exception.EnMeNoResultsFoundException;
 import org.encuestame.utils.captcha.ReCaptchaResponse;
 import org.encuestame.utils.security.ForgotPasswordBean;
                 req.getRemoteAddr(), challenge, response);
         final ValidateOperations validation = new ValidateOperations(
                 getSecurityService());
-        if (validation.validateUserEmail((email == null ? "" : email),
-                getUserAccount())) {
+        final UserAccount userValidate = validation.checkifEmailExist((email == null ? "" : email));
+        if (userValidate == null) {
             result.rejectValue("email", "secure.email.notvalid",
                     new Object[] { user.getEmail() }, "");
         }
-        validation.validateCaptcha(reCaptchaResponse, result);
-        log.info("reCaptchaResponse " + reCaptchaResponse.getErrorMessage());
         log.info("reCaptchaResponse " + reCaptchaResponse.isValid());
+        //validate reCaptcha
+        validation.validateCaptcha(reCaptchaResponse, result);
+        if(reCaptchaResponse.getErrorMessage() != null) {
+            log.fatal("reCaptcha Fatal Error: "+reCaptchaResponse.getErrorMessage());
+        }
         log.info("result.hasErrors() " + result.hasErrors());
         if (result.hasErrors()) {
             return "forgot";
         } else {
             final String password = PasswordGenerator.getPassword(6);
-            // try {
-            // //getSecurityService().renewPassword(unitUserBean, password);
-            // //TODO: refactor this method.
-            // log.debug("foo");
-            // } catch (EnMeExpcetion e) {
-            // log.error("Error Renewd password "+e.getMessage());
-            // return "forgot";
-            // }
+            try {
+                /*
+                 * Stuffs to change;
+                 * 1. user should be to change own password, not auto generate
+                 * 2. instead redirect to sign in page, should be to success page.
+                 */
+                getSecurityService().renewPassword(
+                                ConvertDomainBean
+                                        .convertBasicSecondaryUserToUserBean(userValidate),
+                                password);
+                log.debug("foo");
+            } catch (EnMeExpcetion e) {
+                log.error("Error Renewd password " + e.getMessage());
+                return "forgot";
+            }
             status.setComplete();
-            log.info("password generated " + password);
-            return "redirect:/user/signup";
+            log.info("password generated: " + password);
+            return "redirect:/user/signin";
         }
     }
 }

File encuestame-mvc/src/main/java/org/encuestame/mvc/validator/ValidateOperations.java

View file
     }
 
     /**
+     *
+     * @param email
+     * @return
+     */
+    public UserAccount checkifEmailExist(final String email) {
+        log.debug("checkifEmailExist email... ->"+email);
+        final UserAccount user = getSecurityService().findUserAccountByEmail(email);
+        return user;
+    }
+
+    /**
      * Validate user email.
      * @param email
      * @param user

File encuestame-utils/src/main/java/org/encuestame/utils/captcha/ReCaptchaImpl.java

View file
 import java.util.Enumeration;
 import java.util.Properties;
 
+import org.apache.log4j.Logger;
 import org.encuestame.utils.captcha.http.HttpLoader;
 import org.encuestame.utils.captcha.http.SimpleHttpLoader;
 
 
 public class ReCaptchaImpl implements ReCaptcha {
 
+    /**
+     * Log.
+     */
+    private Logger log = Logger.getLogger(this.getClass());
+
     public static final String PROPERTY_THEME = "theme";
     public static final String ENCODE = "UTF-8";
     public static final String PROPERTY_TABINDEX = "tabindex";
     private boolean includeNoscript = false;
     private HttpLoader httpLoader = new SimpleHttpLoader();
 
+    /**
+     *
+     * @param privateKey
+     */
     public void setPrivateKey(String privateKey) {
         this.privateKey = privateKey;
     }
+
+    /**
+     *
+     * @param publicKey
+     */
     public void setPublicKey(String publicKey) {
         this.publicKey = publicKey;
     }
+
+    /**
+     *
+     * @param recaptchaServer
+     */
     public void setRecaptchaServer(String recaptchaServer) {
         this.recaptchaServer = recaptchaServer;
     }
+
+    /**
+     *
+     * @param includeNoscript
+     */
     public void setIncludeNoscript(boolean includeNoscript) {
         this.includeNoscript = includeNoscript;
     }
+
+    /**
+     *
+     * @param verifyUrl
+     */
     public void setVerifyUrl(String verifyUrl) {
         this.verifyUrl = verifyUrl;
     }
+
+    /**
+     *
+     * @param httpLoader
+     */
     public void setHttpLoader(HttpLoader httpLoader) {
         this.httpLoader  = httpLoader;
     }
 
-    public ReCaptchaResponse checkAnswer(String remoteAddr, String challenge, String response) {
-
-
-        StringBuffer postParameters = new StringBuffer("privatekey=");
+    /**
+     * Check reCaptcha Answer.
+     */
+    public ReCaptchaResponse checkAnswer(final String remoteAddr, final String challenge, final String response) {
+//        StringBuffer postParameters = new StringBuffer("privatekey=");
+//        try {
+//            postParameters.append("privatekey=");
+//            postParameters.append(URLEncoder.encode(privateKey, ENCODE));
+//            postParameters.append("&remoteip=");
+//            postParameters.append(URLEncoder.encode(remoteAddr, ENCODE));
+//            postParameters.append("&challenge=");
+//            postParameters.append(URLEncoder.encode(challenge, ENCODE));
+//            postParameters.append("&response=");
+//            postParameters.append(URLEncoder.encode(response, ENCODE));
+//        } catch (UnsupportedEncodingException e) {
+//            postParameters = new StringBuffer("");
+//        }
+          String postParameters;
         try {
-            postParameters.append("privatekey=");
-            postParameters.append(URLEncoder.encode(privateKey, ENCODE));
-            postParameters.append("&remoteip=");
-            postParameters.append(URLEncoder.encode(remoteAddr, ENCODE));
-            postParameters.append("&challenge=");
-            postParameters.append(URLEncoder.encode(challenge, ENCODE));
-            postParameters.append("&response=");
-            postParameters.append(URLEncoder.encode(response, ENCODE));
+          postParameters = "privatekey=" + URLEncoder.encode(privateKey,ENCODE) + "&remoteip=" + URLEncoder.encode(remoteAddr,ENCODE) +
+            "&challenge=" + URLEncoder.encode(challenge,ENCODE) + "&response=" + URLEncoder.encode(response,ENCODE);
         } catch (UnsupportedEncodingException e) {
-            postParameters = new StringBuffer("");
-        }
-
-        //final String postParameters = "privatekey=" + URLEncoder.encode(privateKey,ENCODE) + "&remoteip=" + URLEncoder.encode(remoteAddr,ENCODE) +
-        //    "&challenge=" + URLEncoder.encode(challenge,ENCODE) + "&response=" + URLEncoder.encode(response,ENCODE);
-
+         postParameters = "";
+       }
+       log.debug("reCaptcha checkAnswer :"+postParameters);
         final String message;
         try {
             message = httpLoader.httpPost(verifyUrl, postParameters.toString());
-
+            log.debug("reCaptcha message :"+message);
             if (message == null) {
                 return new ReCaptchaResponse(false, "recaptcha-not-reachable");
             }
         }
         catch (ReCaptchaException networkProblem) {
+            log.error("ReCaptchaException: "+networkProblem);
             return new ReCaptchaResponse(false, "recaptcha-not-reachable");
         }
 
             else
                 errorMessage = "recaptcha4j-missing-error-message";
         }
-
+        log.debug("reCaptcha errorMessage :"+errorMessage);
         return new ReCaptchaResponse(valid, errorMessage);
     }
 

File encuestame-war/src/main/webapp/WEB-INF/messages/messages_en_US.properties

View file
 secure.realName.empty =  A real name is required!
 secure.type.not.valid = What are you doing?
 
+signin.error=Your sign in information was incorrect.
+signin.error.description = Please try again or
+signin.error.signup = sign up
+signin.error.free = for free.
+signin.username = Username
+signin.password = Password
+signin.forgot = Forgot your password?
+signin.signup = You need account?
+signin.social.message = Do you already have an account on one of these sites? Click the logo to log in with it here:
+
+
+forgot.username = Please instroduce your email or username
+forgot.submit = Rescover my password
+
 #######################
 # Notification Messages
 #######################

File encuestame-war/src/main/webapp/WEB-INF/messages/messages_es_ES.properties

View file
 secure.username.valid = Username is perfect!
 secure.realName.valid = Name looks great
 
+
+signin.error=Los datos son incorrectos.
+signin.error.description = Porfavor prueba otra vez o
+signin.error.signup = crea una cuenta
+signin.error.free = gratuitamente.
+signin.username = Nombre de Usuario
+signin.password = Contraseña
+signin.forgot = Olvidate tu contraseña?
+signin.signup = Necesitas una cuenta?
+signin.social.message = Ya tienes cuenta en alguno de estos sitios? Clickea en el logo e inicia sesión con ella.
+
+forgot.username = Escriba su nombre de usuario o correo electrónico
+forgot.submit = Recuperar mi contraseña
+
 #######################
 # Notification Messages
 #######################

File encuestame-war/src/main/webapp/WEB-INF/spring/encuestame-security-context.xml

View file
         <property name="publicKey" value="6LeytMUSAAAAAF84VURfI3TmYFEBLMLvyk5-zTxc" />
         <property name="includeNoscript" value="false" />
         <!-- po ssl -->
-        <property name="recaptchaServer" value="https://api-secure.recaptcha.net" />
+        <property name="recaptchaServer" value="http://api-secure.recaptcha.net" />
     </bean>
 
     <!-- Enable OAuth Security. <import resource="encuestame-security-oauth-context.xml"/> -->

File encuestame-war/src/main/webapp/WEB-INF/views/user/web/forgot.jsp

View file
-    <div id="mainUserWrapper">
-        <div class="form">
-            <form:form modelAttribute="unitForgotPassword">
-                    <div class="data">
-                        <div class="form-pair">
-                            <div class="form-item">
-                                <label for="email">Email</label>
-                            </div>
-                            <div class="form-value">
-                                <form:input path="email" size="30" maxlength="25" /><br /><form:errors path="email" cssClass="errors" />
-                             </div>
-                        </div>
-                    </div>
-                    <div class="recaptcha">
-                        <c:out value="${unitForgotPassword.captcha}" escapeXml="false" />
+<%@ include file="/WEB-INF/jsp/includes/taglibs.jsp"%>
+
+<div id="web-login-container">
+    <form:form modelAttribute="forgotPasswordBean">
+        <div class="section-wrapper">
+            <label class="section-wrapper" for="j_username">
+                 <spring:message code="forgot.username" />:
+             </label>
+            <div class="login-section-wrapper">
+                <fieldset>
+                    <form:input path="email" size="30" maxlength="25" /><br /><form:errors path="email" cssClass="errors" />
+                 </fieldset>
+            </div>
+        </div>
+
+        <div class="section-wrapper">
+            <div class="">
+                 <c:out value="${forgotPasswordBean.captcha}" escapeXml="false" />
                         <br /><form:errors path="captcha" cssClass="error" />
-                    </div>
-                    <div class="form-submit-buttons">
-                        <input type="submit" class="input-submit" name="submit" value="Submit" />
-                    </div>
-            </form:form>
-             <a href="<%=request.getContextPath()%>/user/signin">Sign In</a>
+                 </div>
+        </div>
+        <div class="section-wrapper loginButtonWrapper">
+            <div class="login-buton">
+                <input type="submit" class="btn grey defaultButton" name="submit" value="<spring:message code="forgot.submit" />" />
+            </div>
         </div>
-    </div>
+    </form:form>
+</div>

File encuestame-war/src/main/webapp/WEB-INF/views/user/web/signin.jsp

View file
-<%@ taglib uri="http://www.springframework.org/tags" prefix="s" %>
-<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
-<%@ include file="/WEB-INF/jsp/includes/taglibs.jsp" %>
- <div id="web-login-wrapper" class="enme-auto-center">
-   <div class="web-form-wrapper" >
-       <c:if test="${not empty message}">
-            <div class="${message.infoType.css}">${message.message}</div>
-       </c:if>
-       <c:if test="${signinError}">
-          <div class="error">
-          Your sign in information was incorrect.<br/>
-          Please try again or <a href="<c:url value="/user/signup" />">sign up</a> free.
-          </div>
-      </c:if>
-      <div class="loginTitle defaultSectionTitle">Log in</div>
-       <form class="form" name="loginForm" id="loginForm"
-             action="<%=request.getContextPath()%>/user/signin/authenticate"
-             method="post">
-              <div class="field">
-              <div class="label">Username</div>
-              <div class="output">
-                 <input type="text" name="j_username" id="j_username"/></div>
-              </div>
-              <div class="field">
-              <div class="label">Password</div>
-              <div class="output">
-                <span><input type="password" name="j_password" id="j_password" /></span>
-                <span><a href="<%=request.getContextPath()%>/user/forgot">Forgot?</a></span>
-              </div>
-              </div>
-              <div class="field">
-                 <div class="label"></div>
-                  <div class="output">
-                      <input id="remember"  type="checkbox" name="_rememberMeServices" />
-                      <span>Keep me logged in</span>
-                  </div>
-               </div>
-                <div class="signIn">
-                    <input class="btn grey defaultButton" type="submit" value="Sign In" />
+<%@ include file="/WEB-INF/jsp/includes/taglibs.jsp"%>
+
+<div id="web-login-container">
+    <form class="form" name="loginForm" id="loginForm"
+        action="<%=request.getContextPath()%>/user/signin/authenticate"
+        method="post">
+        <div class="section-wrapper">
+            <c:if test="${not empty message}">
+                <div class="${message.infoType.css}">${message.message}</div>
+            </c:if>
+            <c:if test="${signinError}">
+                <div class="error">
+                    <spring:message code="signin.error" /><br />
+                     <spring:message code="signin.error.description" />
+                     <a href="<c:url value="/user/signup" />">
+                       <spring:message code="signin.error.signup" /> <spring:message code="signin.error.free" />
+                     </a>
+
                 </div>
-        </form>
-        <div class="singup">
-           <span >
-                New User? <a href="<%=request.getContextPath()%>/user/signup"><span>Sign Up</span></a> for free
-           </span>
+            </c:if>
         </div>
-         <c:if test="${social}">
-              <div class="web-social-signin">
-                  <div class="title">Select one of these thrid-party accouns to sign in</div>
-                  <%@ include file="/WEB-INF/jsp/includes/web/social.jsp" %>
+
+
+        <div class="section-wrapper">
+            <label class="section-wrapper" for="j_username">
+                 <spring:message code="signin.username" />:
+             </label>
+            <div class="login-section-wrapper">
+                <fieldset>
+                    <input type="text" name="j_username" id="j_username" />
+                 </fieldset>
+            </div>
+        </div>
+
+        <div class="section-wrapper">
+            <label class="section-wrapper" for="j_password">
+                <spring:message code="signin.password" />:
+             </label>
+            <div class="login-section-wrapper">
+                <fieldset>
+                    <input type="password" name="j_password" id="j_password" />
+                </fieldset>
+            </div>
+            <div class="forgot">
+                 <a href="<%=request.getContextPath()%>/user/forgot">
+                    <spring:message code="signin.forgot" />
+                 </a>
+            </div>
+        </div>
+        <div class="section-wrapper loginButtonWrapper">
+            <div class="login-buton">
+                <input class="btn grey defaultButton" type="submit"
+                       value="Iniciar sesi�n" name="loginButton" id="loginButton">
+            </div>
+            <div class="signup">
+                  <a href="<%=request.getContextPath()%>/user/signup">
+                    <spring:message code="signin.signup" />
+                  </a>
+            </div>
+        </div>
+
+        <div class="section-wrapper">
+           <c:if test="${social}">
+                <div class="web-social-signin">
+                    <div class="title">
+                        <spring:message code="signin.social.message" />
+                    </div>
+                    <%@ include file="/WEB-INF/jsp/includes/web/social.jsp"%>
                 </div>
-          </c:if>
-    </div>
+           </c:if>
+        </div>
+    </form>
 </div>

File encuestame-war/src/main/webapp/resource/css/web/button.css

View file
     background: url(btn.bg.png) repeat-x 0px 0px;
     padding: 5px 10px 6px 10px;
     font-weight: bold;
-    text-shadow: 1px 1px 1px rgba(255, 255, 255, 0.5);
     border: 1px solid rgba(0, 0, 0, 0.4);
     -moz-border-radius: 5px;
-    -moz-box-shadow: 0px 0px 2px rgba(0, 0, 0, 0.5);
     -webkit-border-radius: 5px;
-    -webkit-box-shadow: 0px 0px 2px rgba(0, 0, 0, 0.5);
     font-size: 12px;
 }
 
 }
 
 .grey {
-    background-color: #CCCCCC;
+    background-color: #EEEEEE;
     color: #141414;
 }
 

File encuestame-war/src/main/webapp/resource/css/web/default.css

View file
 /** common classes **/
 
 .error{
-    background-color: #C88080;
+    background-color: #E39393;
     -webkit-border-radius: 4px;
     -moz-border-radius: 4px;
     border-radius: 4px;
 
 .defaultButton{
    margin-left : 8px;
-   border: 1px solid #BCBCBC;
+   border: 1px solid #C1C1C1;
    min-width: 100px;
    padding: 4px;
    cursor: pointer;

File encuestame-war/src/main/webapp/resource/css/web/public.css

View file
     color: #12122D;
 }
 
-.tags a:visited {
-    color: #12122D;
-}
-
 .tag:hover {
     color: #F7FBFF;
     background-color: #3E6D8E;
     white-space: nowrap;
 }
 
-/*** login **/
-#web-login-wrapper {
-    margin: 5em auto;
-    width: 45em;
-    z-index: 1;
-}
 
-#web-login-wrapper div.loginTitle {
-    padding-left: 10px;
-}
-
-#web-login-wrapper div.signIn {
-    margin: 0 auto;
-    padding: 3px;
-    width: 11em;
-}
+/** login **/
 
-#web-login-wrapper div.field {
-    padding: 10px;
+#web-login-container {
+    border-left-width: 1px;
+    border-right-width: 1px;
+    margin: 0 200px;
+    min-width: 400px;
+    padding-top: 80px;
+    width: 50%;
 }
 
-#web-login-wrapper div.forgotPassword {
-    font-size: 10px;
-    float: left;
-    margin-left: 100px;
+#web-login-container .section-wrapper a:link{
+    color: #000 !important;
+    text-decoration: none !important;
 }
 
-#web-login-wrapper div.forgotPassword a {
-    color: #000;
-    text-decoration: none;
+#web-login-container .section-wrapper {
+    margin: 0 auto;
+    padding-top: 15px;
+    text-align: left;
+    width: 60%;
+    position: relative;
 }
 
-#web-login-wrapper div.forgotPassword a:hover {
-    color: #000;
-    text-decoration: underline;
+.login-section-wrapper {
+    background: -moz-linear-gradient(center top, #F0F0F2, #FFFFFF) repeat
+        scroll 0 0 transparent;
+    border: 1px solid #CCCCCC;
+    border-radius: 7px 7px 7px 7px;
+    box-shadow: 0 1px #FFFFFF;
+    display: block;
+    height: 27px;
+    line-height: 27px;
+    margin-top: 6px;
+    position: relative;
+    width: 100%;
 }
 
-#web-login-wrapper div.field div.label {
-    color: #000;
-    float: left;
-    font-size: 133%;
-    padding-top: 6px;
-    width: 90px;
+#web-login-container .section-wrapper label {
+    font-size: 12px;
+    left: 8px;
 }
 
-#web-login-wrapper  input[type="text"] {
-    height: 20px;
-    width: 275px;
-    font-size: 16px;
-    font-weight: normal;
-    border-radius: 3px 3px 3px 3px;
-    -webkit-border-radius: 3px 3px 3px 3px;
-    -moz-border-radius: 3px 3px 3px 3px;
-    padding: 4px 2px;
-    border: 1px solid #AAAAAA;
+.section-shadow-wrapper {
+    text-shadow: 0 1px #FFFFFF;
 }
 
-#web-login-wrapper div.field div.output label {
-    margin-left: 90px;
+.login-section-wrapper fieldset {
+    left: 10px;
+    position: absolute;
+    right: 10px;
 }
 
-#web-login-wrapper  input[type="password"] {
-    height: 20px;
-    width: 275px;
-    font-size: 16px;
-    font-weight: normal;
-    border-radius: 3px 3px 3px 3px;
-    -webkit-border-radius: 3px 3px 3px 3px;
-    -moz-border-radius: 3px 3px 3px 3px;
-    padding: 4px 2px;
-    border: 1px solid #AAAAAA;
+#web-login-container .forgot {
+  left: 342px;
+  position: relative;
+  top: -20px;
 }
 
-#web-login-wrapper div.field div.output span a {
-    font-size: 10px;
-    text-decoration: none;
-    padding-left: 5px;
+#web-login-container .signup {
+  left: 225px;
+  position: relative;
+  text-align: left;
+  top: -19px;
 }
 
-#web-login-wrapper div.buttonGroup {
-    margin-left: 95px;
-    margin-top: 25px;
+.login-section-wrapper fieldset input {
+    background: none repeat scroll 0 0 transparent;
+    border: 0 none;
+    color: #7E7E7E;
+    font-size: 13px;
+    font-weight: inherit;
+    height: 19px;
+    line-height: 19px;
+    position: relative;
+    width: 100%;
 }
 
-#web-login-wrapper div.web-form-wrapper {
-    float: left;
-    min-width: 440px;
-    border-radius: 3px 3px 3px 3px;
-    -webkit-border-radius: 3px 3px 3px 3px;
-    -moz-border-radius: 3px 3px 3px 3px;
-    background-color: #F9F9F9;
-    border: 1px solid #8BA0BC;
+#web-login-container .loginButtonWrapper {
+  padding-top: 25px;
+  text-align: center;
 }
 
-#web-login-wrapper div.singup {
-    text-align: center;
-    padding: 10px;
-    font-size: 120%;
-}
+#web-login-container .web-social-signin {
 
-#web-login-wrapper div.web-social-signin {
-    border-top: 1px dotted gray;
-    max-width: 400px;
-    min-width: 350px;
-    padding: 10px;
-    margin: 10px;
 }
 
-#web-login-wrapper div.web-social-signin .title {
-    color: #000000;
-    font-size: 100%;
-    font-weight: bold;
-    padding-bottom: 10px;
+#web-login-container .web-social-signin .title {
+  color: #919090;
+  font-size: 13px;
+  margin-bottom: 10px;
 }
 
-#web-login-wrapper div.web-social-signin .section {
-    padding: 4px;
-}
+/** form wrapper */
 
 div.web-form-wrapper a.button {
     color: #444;
     text-decoration: none;
 }
 
-div.addAnswers div.answerItem div.title .answerItemShortUrl a:visited {
-    color: #FFF;
-}
-
 div.addAnswers div.answerItem div.title .answerItemShortUrl a:hover {
     text-decoration: none;
 }
     color: #FFF;
 }
 
-div.wrapperHashTagItems div.addNewHashTag .hashTagItem a:visited {
-    color: #FFF;
-    text-decoration: none;
-}
-
 div.wrapperHashTagItems div.addNewHashTag .hashTagItem a:hover {
     color: #FFF;
     text-decoration: none;
     font-weight: normal;
 }
 
-div..menuWrapper .item a:visited {
-    color: #FFFFFF;
-}
-
 div..menuWrapper .item a:hover,.menuWrapper .item .current {
     color: #444444;
     background-color: #E8E8E8;