r7028 - in dumbhippo/trunk/server: src/com/dumbhippo/server/impl src/com/dumbhippo/web/pages src/com/dumbhippo/web/servlets web
- From: commits mugshot org
- To: online-desktop-list gnome org
- Subject: r7028 - in dumbhippo/trunk/server: src/com/dumbhippo/server/impl src/com/dumbhippo/web/pages src/com/dumbhippo/web/servlets web
- Date: Tue, 11 Dec 2007 16:33:37 -0600 (CST)
Author: marinaz
Date: 2007-12-11 16:33:36 -0600 (Tue, 11 Dec 2007)
New Revision: 7028
Added:
dumbhippo/trunk/server/src/com/dumbhippo/web/servlets/FacebookSigninServlet.java
Modified:
dumbhippo/trunk/server/src/com/dumbhippo/server/impl/IdentitySpiderBean.java
dumbhippo/trunk/server/src/com/dumbhippo/server/impl/PersonViewerBean.java
dumbhippo/trunk/server/src/com/dumbhippo/web/pages/AbstractPersonPage.java
dumbhippo/trunk/server/src/com/dumbhippo/web/servlets/FacebookServlet.java
dumbhippo/trunk/server/web/servlet-info.xml
Log:
Allow the user whom we don't recognize based on their Facebook id to either
connect to their Mugshot account or create a new Mugshot account.
Don't display Mugshot person page for people who have not accepted terms of
use to others.
Modified: dumbhippo/trunk/server/src/com/dumbhippo/server/impl/IdentitySpiderBean.java
===================================================================
--- dumbhippo/trunk/server/src/com/dumbhippo/server/impl/IdentitySpiderBean.java 2007-12-11 22:11:48 UTC (rev 7027)
+++ dumbhippo/trunk/server/src/com/dumbhippo/server/impl/IdentitySpiderBean.java 2007-12-11 22:33:36 UTC (rev 7028)
@@ -468,6 +468,8 @@
DataService.currentSessionRW().changed(UserDMO.class, owner.getGuid(), "aim");
else if (res instanceof XmppResource)
DataService.currentSessionRW().changed(UserDMO.class, owner.getGuid(), "xmpp");
+ else if (res instanceof FacebookResource)
+ DataService.currentSessionRW().changed(UserDMO.class, owner.getGuid(), "facebook");
// People may have listed resource as a contact
if (!oldContacters.isEmpty()) {
Modified: dumbhippo/trunk/server/src/com/dumbhippo/server/impl/PersonViewerBean.java
===================================================================
--- dumbhippo/trunk/server/src/com/dumbhippo/server/impl/PersonViewerBean.java 2007-12-11 22:11:48 UTC (rev 7027)
+++ dumbhippo/trunk/server/src/com/dumbhippo/server/impl/PersonViewerBean.java 2007-12-11 22:33:36 UTC (rev 7028)
@@ -26,6 +26,7 @@
import com.dumbhippo.persistence.Contact;
import com.dumbhippo.persistence.ContactClaim;
import com.dumbhippo.persistence.EmailResource;
+import com.dumbhippo.persistence.FacebookResource;
import com.dumbhippo.persistence.Person;
import com.dumbhippo.persistence.Resource;
import com.dumbhippo.persistence.User;
@@ -87,6 +88,8 @@
resources.add(r);
else if (r instanceof XmppResource)
resources.add(r);
+ else if (r instanceof FacebookResource)
+ resources.add(r);
// we filter out any non-"primary" resources for now
}
} else if (person instanceof Contact) {
@@ -98,6 +101,8 @@
resources.add(r);
else if (r instanceof XmppResource)
resources.add(r);
+ else if (r instanceof FacebookResource)
+ resources.add(r);
// we filter out any non-"primary" resources for now
}
} else {
Modified: dumbhippo/trunk/server/src/com/dumbhippo/web/pages/AbstractPersonPage.java
===================================================================
--- dumbhippo/trunk/server/src/com/dumbhippo/web/pages/AbstractPersonPage.java 2007-12-11 22:11:48 UTC (rev 7027)
+++ dumbhippo/trunk/server/src/com/dumbhippo/web/pages/AbstractPersonPage.java 2007-12-11 22:33:36 UTC (rev 7028)
@@ -135,14 +135,15 @@
this.viewedUser = user;
this.viewedUserId = user.getId();
- if (identitySpider.getAccountDisabled(user)) {
- this.disabled = true;
- if (!getSignin().getViewpoint().isOfUser(user)) {
- this.viewedUser = null;
- this.viewedUserId = null;
- }
- }
+ if (identitySpider.getAccountDisabled(user))
+ this.disabled = true;
+ if ((identitySpider.getAccountDisabled(user) || !user.getAccount().getHasAcceptedTerms()) &&
+ !getSignin().getViewpoint().isOfUser(user)) {
+ this.viewedUser = null;
+ this.viewedUserId = null;
+ }
+
logger.debug("viewing person: {} disabled = {}", this.viewedUser, disabled);
}
Modified: dumbhippo/trunk/server/src/com/dumbhippo/web/servlets/FacebookServlet.java
===================================================================
--- dumbhippo/trunk/server/src/com/dumbhippo/web/servlets/FacebookServlet.java 2007-12-11 22:11:48 UTC (rev 7027)
+++ dumbhippo/trunk/server/src/com/dumbhippo/web/servlets/FacebookServlet.java 2007-12-11 22:33:36 UTC (rev 7028)
@@ -294,14 +294,20 @@
xml.closeElement();
xml.closeElement();
}
-
- xml.appendTextNode("span", "Updates to the information below will be reflected in ",
- "style", "margin-left:15px;");
- xml.appendTextNode("a", "your Mugshot account", "href",
- "http://dogfood.mugshot.org/person?who=" + user.getId(), "target", "_blank");
- xml.append(".");
+
+ if (user.getAccount().getHasAcceptedTerms()) {
+ xml.appendTextNode("span", "Updates to the information below will be reflected in ",
+ "style", "margin-left:15px;");
+ xml.appendTextNode("a", "your Mugshot account", "href",
+ "http://dogfood.mugshot.org/person?who=" + user.getId(), "target", "_blank");
+ xml.append(".");
+ } else {
+ xml.appendTextNode("span", "Fill in information for the accounts you have and want to display updates from, then press 'Submit Info!'",
+ "style", "margin-left:15px;");
+ }
ExternalAccountCategory currentCategory = null;
- xml.openElement("fb:editor", "action", "", "width", "300", "labelwidth", "120");
+ xml.openElement("div", "style", "position:relative;width:250px;float:left;");
+ xml.openElement("fb:editor", "action", "", "width", "250", "labelwidth", "90");
for (ExternalAccountView externalAccount : getSupportedAccounts(user)) {
if (currentCategory == null || !currentCategory.equals(externalAccount.getExternalAccountType().getCategory())) {
currentCategory = externalAccount.getExternalAccountType().getCategory();
@@ -353,16 +359,30 @@
xml.appendEmptyNode("fb:editor-cancel");
xml.closeElement(); // fb:editor-buttonset
xml.closeElement(); // fb:editor
+ xml.closeElement(); // div with the form
+
+ if (!user.getAccount().getHasAcceptedTerms()) {
+ xml.openElement("div", "style", "position:relative;width:100px;float:right;color:#666666;font-weight:bold;");
+ xml.append("Do you already have a Mugshot account? Don't fill in this stuff, just verify" +
+ " your Mugshot account by following this link.");
+ xml.openElement("form", "action", "http://dogfood.mugshot.org/facebook-add", "target", "_blank", "method", "GET");
+ xml.appendEmptyNode("input", "type", "submit", "value", "Verify My Mugshot Account", "style", "margin-bottom:30px;");
+ xml.closeElement();
+ xml.append("Want to create a Mugshot account? It's free and easy and helps you see all your friends' activities in one place, share links, and read feeds in a social setting.");
+ xml.openElement("form", "action", "http://dogfood.mugshot.org/facebook-signin", "target", "_blank", "method", "GET");
+ xml.appendEmptyNode("input", "type", "submit", "value", "Create My Mugshot Account", "style", "margin-bottom:30px;");
+ xml.closeElement();
+ xml.closeElement();
+ }
} else {
- xml.append("You need to be ");
- xml.appendTextNode("a", "logged in to Mugshot", "href",
- "http://dogfood.mugshot.org/account", "target", "_blank");
- xml.append(" to be able to verify your Mugshot account.");
- xml.openElement("form", "action", "http://dogfood.mugshot.org/facebook-add", "target", "_blank", "method", "GET");
- xml.appendEmptyNode("input", "type", "submit", "value", "Verify My Mugshot Account");
- xml.closeElement();
- }
-
+ if (errorMessage == null)
+ errorMessage = "We could not get an existing or create a new user.";
+ logger.error("Displaying a really bad error message on Facebook: {}", errorMessage);
+ xml.openElement("fb:error");
+ xml.appendTextNode("fb:message", "Getting Mugshot Information Failed");
+ xml.append(errorMessage);
+ xml.closeElement();
+ }
response.setContentType("text/html");
response.getOutputStream().write(xml.getBytes());
Added: dumbhippo/trunk/server/src/com/dumbhippo/web/servlets/FacebookSigninServlet.java
===================================================================
--- dumbhippo/trunk/server/src/com/dumbhippo/web/servlets/FacebookSigninServlet.java 2007-12-11 22:11:48 UTC (rev 7027)
+++ dumbhippo/trunk/server/src/com/dumbhippo/web/servlets/FacebookSigninServlet.java 2007-12-11 22:33:36 UTC (rev 7028)
@@ -0,0 +1,118 @@
+package com.dumbhippo.web.servlets;
+
+import java.io.IOException;
+import java.util.Map;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.servlet.http.HttpSession;
+
+import org.slf4j.Logger;
+
+import com.dumbhippo.GlobalSetup;
+import com.dumbhippo.persistence.AccountClaim;
+import com.dumbhippo.persistence.FacebookResource;
+import com.dumbhippo.server.AccountSystem;
+import com.dumbhippo.server.Configuration;
+import com.dumbhippo.server.HippoProperty;
+import com.dumbhippo.server.HumanVisibleException;
+import com.dumbhippo.server.IdentitySpider;
+import com.dumbhippo.server.NotFoundException;
+import com.dumbhippo.server.Configuration.PropertyNotFoundException;
+import com.dumbhippo.tx.RetryException;
+import com.dumbhippo.web.SigninBean;
+import com.dumbhippo.web.WebEJBUtil;
+import com.facebook.api.FacebookParam;
+import com.facebook.api.FacebookSignatureUtil;
+
+public class FacebookSigninServlet extends AbstractServlet {
+
+ @SuppressWarnings("unused")
+ private static final Logger logger = GlobalSetup.getLogger(FacebookAddServlet.class);
+
+ static final long serialVersionUID = 1;
+
+ private Configuration config;
+
+ @Override
+ public void init() {
+ config = WebEJBUtil.defaultLookup(Configuration.class);
+ }
+
+ @Override
+ protected String wrappedDoGet(HttpServletRequest request, HttpServletResponse response) throws IOException, HumanVisibleException, HttpException, ServletException, RetryException {
+ String redirectUrl = "/facebook-welcome";
+ logger.debug("context params are:");
+ for (Object o : request.getParameterMap().entrySet()) {
+ @SuppressWarnings("unchecked")
+ Map.Entry<String, String[]> mapEntry = (Map.Entry<String, String[]>)o;
+ logger.debug("{} = {}", mapEntry.getKey(), mapEntry.getValue()[0]);
+ }
+
+ @SuppressWarnings("unchecked")
+ Map<String, CharSequence> facebookParams = FacebookSignatureUtil.extractFacebookParamsFromArray(request.getParameterMap());
+ String secret = null;
+ try {
+ secret = config.getPropertyNoDefault(HippoProperty.FACEBOOK_SECRET).trim();
+ if (secret.length() == 0)
+ secret = null;
+ } catch (PropertyNotFoundException e) {
+ secret = null;
+ }
+
+ String errorMessage = null;
+ if (secret == null) {
+ errorMessage = "We could not verify Facebook information due to a missing secret key we should share with Facebook.";
+ } else {
+ boolean signatureValid = FacebookSignatureUtil.verifySignature(facebookParams, secret);
+ if (!signatureValid) {
+ errorMessage = "We could not verify Facebook information because the signature supplied for Facebook parameters was not valid.";
+ } else {
+ AccountSystem accounts = WebEJBUtil.defaultLookup(AccountSystem.class);
+ IdentitySpider identitySpider = WebEJBUtil.defaultLookup(IdentitySpider.class);
+ String facebookUserId = facebookParams.get(FacebookParam.USER.toString()).toString();
+ try {
+ FacebookResource res = identitySpider.lookupFacebook(facebookUserId);
+ AccountClaim ac = res.getAccountClaim();
+ if (ac != null) {
+ accounts.authorizeNewClient(ac.getOwner().getAccount(), SigninBean.computeClientIdentifier(request));
+ HttpSession sess = request.getSession(false);
+ if (sess != null)
+ sess.invalidate();
+ return redirectToNextPage(request, response, "/account", null);
+ } else {
+ errorMessage = "FacebookResource for " + facebookUserId + " was not claimed by any user.";
+ }
+ } catch (NotFoundException e) {
+ errorMessage = "We could not find a FacebookResource for Facebook user " + facebookUserId + ".";
+ }
+ }
+ }
+
+ if (errorMessage != null) {
+ logger.error("Will show the following error to the user: {}", errorMessage);
+ redirectUrl = redirectUrl + "?error_message=" + errorMessage;
+ } else {
+ logger.error("Redirecting to a facebook-welcome page for unknown reason!");
+ }
+
+ response.sendRedirect(redirectUrl);
+ return null;
+ }
+
+ @Override
+ protected boolean isReadWrite(HttpServletRequest request) {
+ // The method is GET, since we need links that the user can just click upon,
+ // but they have side effects. This is OK since the links are unique, so
+ // caching won't happen.
+
+ return true;
+ }
+
+
+ @Override
+ protected boolean requiresTransaction(HttpServletRequest request) {
+ return true;
+ }
+}
Modified: dumbhippo/trunk/server/web/servlet-info.xml
===================================================================
--- dumbhippo/trunk/server/web/servlet-info.xml 2007-12-11 22:11:48 UTC (rev 7027)
+++ dumbhippo/trunk/server/web/servlet-info.xml 2007-12-11 22:33:36 UTC (rev 7028)
@@ -269,20 +269,30 @@
<url-pattern>/facebook-verify-from-home</url-pattern>
</servlet-mapping>
- <servlet>
+ <servlet>
<servlet-name>FacebookAddServlet</servlet-name>
<servlet-class>com.dumbhippo.web.servlets.FacebookAddServlet</servlet-class>
- </servlet>
+ </servlet>
<servlet-mapping>
<servlet-name>FacebookAddServlet</servlet-name>
<url-pattern>/facebook-add</url-pattern>
</servlet-mapping>
- <servlet>
+ <servlet>
+ <servlet-name>FacebookSigninServlet</servlet-name>
+ <servlet-class>com.dumbhippo.web.servlets.FacebookSigninServlet</servlet-class>
+ </servlet>
+
+ <servlet-mapping>
+ <servlet-name>FacebookSigninServlet</servlet-name>
+ <url-pattern>/facebook-signin</url-pattern>
+ </servlet-mapping>
+
+ <servlet>
<servlet-name>FacebookServlet</servlet-name>
<servlet-class>com.dumbhippo.web.servlets.FacebookServlet</servlet-class>
- </servlet>
+ </servlet>
<servlet-mapping>
<servlet-name>FacebookServlet</servlet-name>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]