Skip to content
the-ricker edited this page Nov 30, 2011 · 6 revisions

Account creation

Three options

Account creation is the basic beginning of any social site. There are three ways to go about it:

  1. Common web form
  2. OpenID
  3. Use other website using OAuth

The first one is simple, but there are some drawbacks. See, for instance, Luke Wroblewski presentation # Forms Must Die.

OpenID is supported by the Sling OpenID Handler, but it is not supported by Facebook and other popular social sites.

Facebook, Google, AOL, Yahoo and Twitter support OAuth 2.0. One can # with a profile with a single click. See the Facebook documentation for examples.

Web form login

The following is an example JSP. It displays the user name if the user is logged in. It prompts the user to log in if not logged in.

<%@ page import="javax.jcr.Session" %>
<%@ taglib prefix="sling" uri="http://sling.apache.org/taglibs/sling/1.0" %>
<sling:defineObjects />
<div id="malta-header">
<% 
  String url = slingRequest.getRequestURL().toString();
  Session slingSession = resourceResolver.adaptTo(Session.class);
  String userId = slingSession.getUserID();
  if (userId != null && !"anonymous".equals(userId)) {
    // logged in as 
    out.print(userId);
  } else {
// prompt for login
%>
<form method="POST" action="/j_security_check">
  <input type="hidden" name="resource" value="<%=url%>"/>
  <label for="j_username">Username</label>
  <input type="text" name="j_username"/> 
  <label for="j_password">Password</label>
  <input type="password" name="j_password"/>
  <button type="submit">Login</button>
</form>
<%  
  }
%>
</div>

So, what is going on here?

This JSP page only creates a DIV tag, not an entire page, so it can be included by another JSP, as in

<jsp:include page="login.jsp" />

The objects slingRequest and resourceResolver are created by the sling:defineObjects call. See the script variables page for details.

The form named j_security_check is an internal servlet to Sling. See the form authentication page for details. Note that the hidden input named resource redirects right back to the given page.

First page

The first page is the root of presentation, navigation and workflow.

The first page has the following states:

  1. Not logged in, no account. User is prompted to login or create account.
  2. Not logged in, account created. User is informed that account was created successfully and prompted to login.
  3. Logged in, no home page. User is informed that he has no page and is prompted to create one.
  4. Logged in, home page created. User is shown his home page content, among other things.
Clone this wiki locally