-
Notifications
You must be signed in to change notification settings - Fork 0
Account creation
Account creation is the basic beginning of any social site. There are three ways to go about it:
- Common web form
- OpenID
- 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.
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.
The first page is the root of presentation, navigation and workflow.
The first page has the following states:
- Not logged in, no account. User is prompted to login or create account.
- Not logged in, account created. User is informed that account was created successfully and prompted to login.
- Logged in, no home page. User is informed that he has no page and is prompted to create one.
- Logged in, home page created. User is shown his home page content, among other things.