Commits

Juan Carlos Picado Herrera committed 4b1f335 Merge

Merge branch 'juanpicado' into development

Comments (0)

Files changed (11)

encuestame-business/src/main/java/org/encuestame/business/social/AbstractISocialService.java

  */
 package org.encuestame.business.social;
 
+import org.encuestame.core.exception.EnMeNoSuchAccountConnectionException;
 import org.encuestame.persistence.domain.security.UserAccount;
+import org.encuestame.persistence.exception.EnMeDomainNotFoundException;
 import org.encuestame.persistence.exception.EnMeExpcetion;
 import org.encuestame.utils.oauth.AuthorizedRequestToken;
 import org.encuestame.utils.oauth.OAuthToken;
         void connect(Long accountId, AuthorizedRequestToken requestToken) throws EnMeExistPreviousConnectionException;
 
 
-        UserAccount findAccountByConnection(String accessToken) throws EnMeExpcetion;
+        UserAccount findAccountByConnection(String accessToken) throws EnMeDomainNotFoundException;
 
 }

encuestame-business/src/main/java/org/encuestame/business/social/FacebookSocialService.java

  */
 public class FacebookSocialService extends AbstractSocialProvider<FacebookOperations> implements IFacebookSocialService{
 
+
+    /**
+     * Social Account Provider;
+     */
+    private SocialAccountProvider parameters;
+
+    /**
+     * Twitter Template.
+     */
+    private FacebookTemplate facebookTemplate;
+
     /**
      *
      * @param socialProviderName
      */
-    public FacebookSocialService(String socialProviderName) {
-        //super(socialProviderName);
+    public FacebookSocialService() {
+        this.loadParameters();
+    }
+
+    /**
+     * Load Parameters.
+     */
+    private void loadParameters(){
+        if(getSocialProviderDao() != null){
+            final SocialAccountProvider parameters = getSocialProviderDao().getSocialAccountProviderId(4L);
+            if(parameters == null){
+                log.error("NOT SOCIAL PROVIDER FOUND");
+            }
+            setParameters(parameters);
+        } else {
+            log.error("No Provider Dao");
+        }
     }
 
     @Override

encuestame-business/src/main/java/org/encuestame/business/social/SocialProviderOperations.java

  */
 package org.encuestame.business.social;
 
+import org.encuestame.core.exception.EnMeNoSuchAccountConnectionException;
 import org.encuestame.persistence.domain.security.AccountConnection;
 import org.encuestame.persistence.domain.security.UserAccount;
 import org.encuestame.persistence.exception.EnMeDomainNotFoundException;

encuestame-business/src/main/resources/encuestame-service-context.xml

         * LinkedIn Connect
   -->
 
-    <bean id="abstractSocialProvider" class="org.encuestame.business.social.AbstractSocialProvider"
+     <bean id="abstractSocialProvider" class="org.encuestame.business.social.AbstractSocialProvider"
           abstract="true">
     </bean>
 
           class="org.encuestame.business.social.TwitterSocialService" parent="abstractSocialProvider">
     </bean>
 
-    <!-- Facebook OAuth Consumer
-    <bean id="facebookServiceConnect" autowire="byName" class="org.encuestame.business.social.FacebookSocialService" parent="abstractSocialProvider">
-        <constructor-arg value="facebook" />
-    </bean>-->
+    <!-- Facebook OAuth Consumer -->
+    <bean id="facebookServiceConnect" autowire="byName"
+          class="org.encuestame.business.social.FacebookSocialService"
+          parent="abstractSocialProvider">
+    </bean>
 
     <!-- LinkedIn OAuth Consumer
     <bean id="linkedInServiceConnect" autowire="byName" class="org.encuestame.business.social.LinkedInSocialService" parent="abstractSocialProvider">

encuestame-mvc/src/main/java/org/encuestame/mvc/controller/social/facebook/FacebookConnectSignIn.java

  */
 package org.encuestame.mvc.controller.social.facebook;
 
+import org.encuestame.business.service.imp.ISecurityService;
+import org.encuestame.business.social.IFacebookSocialService;
+import org.encuestame.core.exception.EnMeNoSuchAccountConnectionException;
 import org.encuestame.mvc.controller.social.AbstractSocialController;
+import org.encuestame.persistence.domain.security.UserAccount;
+import org.encuestame.persistence.exception.EnMeDomainNotFoundException;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.social.facebook.FacebookAccessToken;
+import org.springframework.social.facebook.FacebookProfile;
+import org.springframework.social.facebook.FacebookTemplate;
 import org.springframework.stereotype.Controller;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
 
 /**
  * Controller to Signin with Facebook Account.
 @Controller
 public class FacebookConnectSignIn extends AbstractSocialController{
 
+    @Autowired
+    private IFacebookSocialService facebookSocialService;
+
+    /**
+     * Sign in the member with their Facebook account.
+     * The submitted access token, obtained via a cookie, identifies the connection between a local member account and a Facebook account.
+     * For sign-in to succeed, the submitted access token must match a Facebook accessToken on file in our system.
+     * Notifies the user if the access token is invalid.
+     */
+    @RequestMapping(value="/signin/facebook", method=RequestMethod.POST)
+    public String signin(@FacebookAccessToken String accessToken) {
+        try {
+            UserAccount account = this.facebookSocialService.findAccountByConnection(accessToken);
+            authenticate(account);
+            return "redirect:/";
+        } catch (EnMeNoSuchAccountConnectionException e) {
+            return handleNoFacebookConnection(new FacebookTemplate(accessToken).getUserProfile());
+        } catch (EnMeDomainNotFoundException e) {
+            // TODO Auto-generated catch block
+            e.printStackTrace();
+        }
+        return null;
+    }
+
+    // internal helpers
+
+    private String handleNoFacebookConnection(FacebookProfile userInfo) {
+        try {
+            //accountRepository.findBySignin(userInfo.getEmail());
+            //FlashMap.setWarningMessage("Your Facebook account is not linked with your Greenhouse account. To connect them, sign in and then go to the Settings page.");
+            return "redirect:/signin";
+        } catch (Exception e) {
+           // FlashMap.setInfoMessage("Your Facebook account is not linked with a Greenhouse account. "
+            ///        + "If you do not have a Greenhouse account, complete the following form to create one. "
+            //        + "If you already have an account, sign in with your username and password, then go to the Settings page to connect with Facebook.");
+            // TODO encode form query parameters into url to pre-populate from userinfo
+            return "redirect:/signup";
+        }
+    }
+
+    /**
+     * @return the facebookSocialService
+     */
+    public IFacebookSocialService getFacebookSocialService() {
+        return facebookSocialService;
+    }
+
+    /**
+     * @param facebookSocialService the facebookSocialService to set
+     */
+    public void setFacebookSocialService(final IFacebookSocialService facebookSocialService) {
+        this.facebookSocialService = facebookSocialService;
+    }
 }

encuestame-war/src/main/resources/encuestame-mvc-context.xml

     <property name="order" value="1"/>
   </bean>
 
+  <!-- Maps request paths to @Controller classes;
+       e.g. a path of /signup looks for a controller named SignUpController -->
+    <bean class="org.springframework.web.servlet.mvc.support.ControllerClassNameHandlerMapping">
+        <property name="order" value="3" />
+        <property name="defaultHandler">
+            <!-- If no @Controller match, map path to a view to render; e.g. the "/intro"
+                 path would map to the view named "intro" -->
+            <ref bean="urlFilenameViewController"></ref>
+        </property>
+    </bean>
+
     <!-- Configures File Upload -->
     <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
         <property name="maxUploadSize" value="500000" />

encuestame-war/src/main/resources/encuestame-web-flow-context.xml

     </webflow:flow-executor>
 
         <!-- Plugs in a custom creator for Web Flow views
+        -->
     <webflow:flow-builder-services id="flowBuilderServices"
            view-factory-creator="mvcViewFactoryCreator" development="true" />
-           -->
 
-    <!-- Configures Web Flow to use Tiles to create views for rendering; Tiles allows for applying consistent layouts to your views
+
+    <!-- Configures Web Flow to use Tiles to create views for rendering; Tiles allows for applying consistent layouts to your views-->
     <bean id="mvcViewFactoryCreator" class="org.springframework.webflow.mvc.builder.MvcViewFactoryCreator">
         <property name="viewResolvers" ref="jspViewResolver"/>
         <property name="useSpringBeanBinding" value="true" />
-    </bean> -->
+    </bean>
 
     <!-- Installs a listener that manages Hibernate persistence contexts for flows that require them -->
     <bean id="hibernateFlowExecutionListener" class="org.springframework.webflow.persistence.HibernateFlowExecutionListener">

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

+<%@ include file="/WEB-INF/jsp/includes/taglibs.jsp" %>
+<%@ include file="/WEB-INF/jsp/includes/initPage.jsp" %>
+<%@ include file="/WEB-INF/jsp/includes/publicBody.jsp" %>
+    <div id="mainUserWrapper">
+        <div class="form">
+            find friends.
+        </div>
+        <form>
+            <a href="next">Next</a>
+        </form>
+    </div>
+<%@ include file="/WEB-INF/jsp/includes/footer.jsp" %>

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

+<%@ include file="/WEB-INF/jsp/includes/taglibs.jsp" %>
+<%@ include file="/WEB-INF/jsp/includes/initPage.jsp" %>
+<%@ include file="/WEB-INF/jsp/includes/publicBody.jsp" %>
+    <div id="mainUserWrapper">
+        <div class="form">
+            profile
+        </div>
+        <form>
+            <a href="next">Next</a>
+        </form>
+    </div>
+<%@ include file="/WEB-INF/jsp/includes/footer.jsp" %>

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

 <?xml version="1.0" encoding="UTF-8"?>
 <flow xmlns="http://www.springframework.org/schema/webflow"
-      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-      xsi:schemaLocation="http://www.springframework.org/schema/webflow http://www.springframework.org/schema/webflow/spring-webflow-2.0.xsd">
+    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+    xsi:schemaLocation="http://www.springframework.org/schema/webflow http://www.springframework.org/schema/webflow/spring-webflow-2.0.xsd">
 
     <var name="signUpBean" class="org.encuestame.utils.security.SignUpBean" />
 
-    <view-state id="signup">
-        <transition on="singup" to="succesfull" >
-             <evaluate expression="securityService.singupUser(singUpBean)" result="flowScope.userInfo"
-                result-type="org.encuestame.utils.web.UnitUserBean" />
-        </transition>
+    <persistence-context />
+
+    <view-state id="signup" model="signUpBean">
+        <binder>
+            <binding property="username" />
+            <binding property="email" />
+            <binding property="captcha" />
+        </binder>
+        <transition on="saveUser" to="findFriends" />
+
+
     </view-state>
 
-    <view-state id="succesfull">
-        <transition on="confirm" to="succesfullEnd" >
-        </transition>
+    <view-state id="findFriends" model="signUpBean">
+        <transition on="next" to="profile" />
     </view-state>
 
-    <end-state id="succesfullEnd" view="externalRedirect:contextRelative:/login.do"></end-state>
+    <view-state id="profile" model="signUpBean">
+        <transition on="next" to="profile" />
+    </view-state>
+
+    <end-state id="profile"
+        view="externalRedirect:contextRelative:/account/dashboard" commit="false" />
+
 
 </flow>

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

 <%@ include file="/WEB-INF/jsp/includes/initPage.jsp" %>
 <%@ include file="/WEB-INF/jsp/includes/publicBody.jsp" %>
     <div id="mainUserWrapper">
-        FLOW
+        <div class="form">
+            <form:form modelAttribute="signUpBean">
+                    <div class="data">
+                        <div class="form-pair">
+                            <div class="form-item">
+                                <label for="username">Username</label>
+                            </div>
+                            <div class="form-value">
+                                <form:input path="username" size="30" maxlength="16" />
+                                <br />
+                                <form:errors path="username" cssClass="errors" />
+                             </div>
+                        </div>
+                        <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="${signUpBean.captcha}" escapeXml="false" />
+                        <br />
+                        <form:errors path="capcetcha" cssClass="error" />
+                    </div>
+                    <div class="form-submit-buttons">
+                        <input type="submit" id="saveUser" name="_eventId_saveUser" value="Sign Up"/>
+                    </div>
+            </form:form>
+            <a href="<%=request.getContextPath()%>/user/forgot">Forgot Password?</a>
+        </div>
     </div>
 <%@ include file="/WEB-INF/jsp/includes/footer.jsp" %>