Author: channa
Date: Fri Jan  4 03:33:47 2008
New Revision: 11844

Log:

Adding infocard based self registration.

Added:
   
trunk/mashup/java/modules/core/src/org/wso2/mashup/webapp/identity/InfoCardRegistrationBean.java
   trunk/mashup/java/modules/www/register_self_infocard.jsp
Modified:
   trunk/mashup/java/modules/www/infocard.jsp
   trunk/mashup/java/modules/www/register_self.jsp

Added: 
trunk/mashup/java/modules/core/src/org/wso2/mashup/webapp/identity/InfoCardRegistrationBean.java
==============================================================================
--- (empty file)
+++ 
trunk/mashup/java/modules/core/src/org/wso2/mashup/webapp/identity/InfoCardRegistrationBean.java
    Fri Jan  4 03:33:47 2008
@@ -0,0 +1,205 @@
+/*
+ * Copyright (c) 2006, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.wso2.mashup.webapp.identity;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.wso2.mashup.MashupConstants;
+import org.wso2.mashup.webapp.userprofile.ManageUsers;
+import org.wso2.solutions.identity.IdentityConstants;
+import org.wso2.solutions.identity.relyingparty.TokenVerifierConstants;
+import org.wso2.usermanager.UserManagerException;
+import org.wso2.usermanager.verification.email.EmailVerifier;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpSession;
+import java.util.HashMap;
+import java.util.Hashtable;
+import java.util.Map;
+
+/**
+ * Handles the infocard based self registration process.
+ */
+public class InfoCardRegistrationBean {
+    private static final Log log = 
LogFactory.getLog(InfoCardRegistrationBean.class);
+
+    // Constants for storing values in the servlet context.
+    private final String FULL_NAME = "fullname";
+    private final String EMAIL_ID = "emailid";
+    private final String PPID = "ppid";    
+
+    // Get registration values submitted using form.
+    private String userName;
+    private String fullName;
+    private String password;
+    private String confirmedPassword;
+    private String emailId;
+    private String ppid;
+    private Hashtable errors;
+
+    public String getUserName() {
+        return userName;
+    }
+
+    public void setUserName(String userName) {
+        this.userName = userName;
+    }
+
+    public String getPassword() {
+        return password;
+    }
+
+    public void setPassword(String password) {
+        this.password = password;
+    }
+
+    public String getConfirmedPassword() {
+        return confirmedPassword;
+    }
+
+    public void setConfirmedPassword(String confirmedPassword) {
+        this.confirmedPassword = confirmedPassword;
+    }
+
+    public String getFullName() {
+        return fullName;
+    }
+
+    public String getEmailId() {
+        return emailId;
+    }
+
+    /**
+     * Initialize bean values.
+     */
+    public InfoCardRegistrationBean() {
+        this.userName = "";
+        this.password = "";
+        this.confirmedPassword = "";
+        this.errors = new Hashtable();
+    }
+
+    /**
+     * Accepts users information submitted and initiates verification.
+     *
+     * @return true if self registration was successfully initiated.
+     */
+    public boolean register() {
+        boolean success = false;
+
+        // Information already validated - proceed with verification.
+        EmailVerifier verifier = new EmailVerifier();
+
+        Map userAttributes = new HashMap();
+        userAttributes.put(MashupConstants.FULL_NAME, fullName);
+        userAttributes.put(MashupConstants.EMAIL_ID, emailId);
+        userAttributes.put(MashupConstants.INFOCARD_PPID + 0, ppid);
+        userAttributes.put(MashupConstants.INFOCARD_COUNT, "1");
+
+        try {
+            verifier.requestUserVerification(userName, emailId, password, 
userAttributes);
+            success = true;
+        } catch (UserManagerException e) {
+            log.error("Error perrforming self registration", e);
+        }
+
+        return success;
+    }
+
+    /**
+     * Return any added error messages.
+     *
+     * @param key Key to identify error.
+     * @return Message associated with key, if it exists.
+     */
+    public String getErrorMessage(String key) {
+        String errorMsg = (String) errors.get(key.trim());
+        return (errorMsg == null) ? "" : errorMsg;
+    }
+
+    /**
+     * Validates the information in mandatory fields.
+     * @param request Servlet request object.
+     * @return true if validation is successful.
+     */
+    public boolean isInputValid(HttpServletRequest request) {
+        boolean valid = true;
+
+        // Get values from context
+        HttpSession session = request.getSession();
+        ppid = (String) session.getAttribute(PPID);
+        fullName = (String) session.getAttribute(FULL_NAME);
+        emailId = (String) session.getAttribute(EMAIL_ID);
+
+        if (userName.equals("")) {
+            errors.put("userName", "User name cannot be empty.");
+            userName = "";
+            valid = false;
+        }
+
+        if (password.equals("")) {
+            errors.put("password", "Password cannot be empty.");
+            password = "";
+            valid = false;
+        }
+
+        if (confirmedPassword.equals("")) {
+            errors.put("confirmedPassword", "Password confirmation cannot be 
empty.");
+            confirmedPassword = "";
+            valid = false;
+        }
+
+        if (!confirmedPassword.equals(password)) {
+            errors.put("confirmedPassword", "Confirmation password must match 
password.");
+            confirmedPassword = "";
+            valid = false;
+        }
+
+        // Expensive operation, so do only once all other data has been 
validated.
+        if (valid) {
+            if (ManageUsers.isExistingUser(request, userName)) {
+                errors.put("userName", "User name exists, please select 
another.");
+                userName = "";
+                valid = false;
+            }
+        }
+
+        return valid;
+    }
+
+    /**
+     * Retrieve the user's claims from the infocard, to be used in 
registration.
+     * @param request Servlet request object.
+     */
+    public void setInfoCardDetails(HttpServletRequest request) {
+        HttpSession session = request.getSession();
+
+        // If infocard has been successfully used, proceed.
+        String auth = (String) 
request.getAttribute(TokenVerifierConstants.SERVLET_ATTR_STATE);
+
+        // Get the details from the infocard and add to session for 
persistance.
+        if (TokenVerifierConstants.STATE_SUCCESS.equals(auth)) {
+            ppid = (String) request.getAttribute(IdentityConstants.CLAIM_PPID);
+            session.setAttribute(PPID, ppid);
+            String givenName = (String) 
request.getAttribute(IdentityConstants.CLAIM_GIVEN_NAME);
+            String surname = (String) 
request.getAttribute(IdentityConstants.CLAIM_SURNAME);
+            fullName = givenName + " " + surname;
+            session.setAttribute(FULL_NAME, fullName);
+            emailId = (String) 
request.getAttribute(IdentityConstants.CLAIM_EMAIL_ADDRESS);
+            session.setAttribute(EMAIL_ID, emailId);
+        }
+    }
+}

Modified: trunk/mashup/java/modules/www/infocard.jsp
==============================================================================
--- trunk/mashup/java/modules/www/infocard.jsp  (original)
+++ trunk/mashup/java/modules/www/infocard.jsp  Fri Jan  4 03:33:47 2008
@@ -17,6 +17,7 @@
 <%@ page import="java.net.URLDecoder" %>
 <%
     String bounceback = request.getParameter("bounceback");
+    String fromSelfReg = request.getParameter("fromselfreg");
     if (bounceback == null) {
         bounceback = "index.jsp";
     } else {
@@ -27,7 +28,7 @@
         <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
 </head>
 <body>
-   <form name="frm" id="frm" method="post" action="infocardaccept.jsp">  
+   <form name="frm" id="frm" method="post" action="<%= 
"true".equals(fromSelfReg) ? "register_self_infocard.jsp" : 
"infocardaccept.jsp"%>">  
                        <input type="hidden" name="InfoCardSignin" value="Log 
in" /><br/>
             <input type="hidden" name="bounceback" value="<%=bounceback%>"/>
             <OBJECT type="application/x-informationCard" name="xmlToken">

Modified: trunk/mashup/java/modules/www/register_self.jsp
==============================================================================
--- trunk/mashup/java/modules/www/register_self.jsp     (original)
+++ trunk/mashup/java/modules/www/register_self.jsp     Fri Jan  4 03:33:47 2008
@@ -99,6 +99,9 @@
       <br />
                     <form name="formRegisterSelf" method='post' 
action="register_self.jsp">
                         <input type="hidden" name="bounceback" 
value="<%=bounceback%>"/>
+                        <table>
+                            <tr>
+                                <td>
                         <table width="100%" border="0" cellpadding="3" 
cellspacing="0" >
                             <tr>
                                 <td width="130"><label><strong>User Name:<font 
color="#FF0000">*</font></strong></label></td>
@@ -146,7 +149,15 @@
                               <td align="center"></td>
                             </tr>
                         </table>
-                                               <strong><font 
color="#FF0000">*</font></strong> Required fields
+                            </td>
+                                <td align="center" valign="top" height="175">
+                                    <a 
href="infocard.jsp?fromselfreg=true&bounceback=<%=URLEncoder.encode(bounceback,"UTF-8")%>"><img
 src="images/infocard_92x64.png" border="0"></a>
+                                    <br/>
+                                    Fill up your details using your personal 
or managed infocard.
+                                </td>
+                            </tr>
+                        </table>
+                        <strong><font color="#FF0000">*</font></strong> 
Required fields
                     </form>
 
         <br>

Added: trunk/mashup/java/modules/www/register_self_infocard.jsp
==============================================================================
--- (empty file)
+++ trunk/mashup/java/modules/www/register_self_infocard.jsp    Fri Jan  4 
03:33:47 2008
@@ -0,0 +1,156 @@
+<%--
+ * Copyright 2006,2007 WSO2, Inc. http://www.wso2.org
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+--%>
+<%@ page errorPage="error.jsp" %>
+<%@ page contentType="text/html;charset=UTF-8" language="java" %>
+<%@ page import="com.sun.syndication.feed.synd.SyndContent" %>
+<%@ page import="com.sun.syndication.feed.synd.SyndContentImpl" %>
+<%@ page import="com.sun.syndication.feed.synd.SyndEntry" %>
+<%@ page import="com.sun.syndication.feed.synd.SyndEntryImpl" %>
+<%@ page import="com.sun.syndication.feed.synd.SyndFeed" %>
+<%@ page import="com.sun.syndication.feed.synd.SyndFeedImpl" %>
+<%@ page import="com.sun.syndication.io.SyndFeedOutput" %>
+<%@ page import="org.wso2.mashup.MashupConstants" %>
+<%@ page import="org.wso2.mashup.utils.QueryResult" %>
+<%@ page import="org.wso2.mashup.utils.QueryResults" %>
+<%@ page import="org.wso2.mashup.webapp.identity.InfoCardHandler" %>
+<%@ page import="org.wso2.mashup.webapp.identity.RegistrationBean" %>
+<%@ page import="org.wso2.mashup.webapp.userprofile.User" %>
+<%@ page import="org.wso2.mashup.webapp.userprofile.UserQuery" %>
+<%@ page import="org.wso2.mashup.webapp.utils.QueryParamUtils" %>
+<%@ page import="org.wso2.mashup.webapp.utils.RegistryUtils" %>
+<%@ page import="org.wso2.registry.Comment" %>
+<%@ page import="org.wso2.registry.LogEntry" %>
+<%@ page import="org.wso2.registry.Registry" %>
+<%@ page import="org.wso2.registry.RegistryConstants" %>
+<%@ page import="org.wso2.registry.RegistryException" %>
+<%@ page import="org.wso2.registry.Resource" %>
+<%@ page import="org.wso2.registry.Tag" %>
+<%@ page import="org.wso2.registry.jdbc.JDBCRegistry" %>
+<%@ page import="org.wso2.registry.secure.SecureRegistry" %>
+<%@ page import="org.wso2.usermanager.Realm" %>
+<%@ page import="org.wso2.usermanager.UserManagerException" %>
+<%@ page import="org.wso2.usermanager.verification.email.EmailVerifier" %>
+<%@ page import="javax.servlet.ServletContext" %>
+<%@ page import="java.net.URL" %>
+<%@ page import="java.net.URLDecoder" %>
+<%@ page import="java.util.ArrayList" %>
+<%@ page import="java.util.Date" %>
+<%@ page import="java.util.Iterator" %>
+<%@ page import="java.util.List" %>
+<%@ page import="java.util.Map" %>
+<%
+    Registry registry = RegistryUtils.getRegistry(request);
+    String bounceback = request.getParameter("bounceback");
+    String infoCardPresented = request.getParameter("InfoCardSignin");
+    if (bounceback == null) {
+        bounceback = "index.jsp";
+    } else {
+        bounceback = URLDecoder.decode(bounceback, "UTF-8");
+    }
+%>
+<jsp:useBean id="infoCardRegHandler" 
class="org.wso2.mashup.webapp.identity.InfoCardRegistrationBean"
+             scope="request">
+    <jsp:setProperty name="infoCardRegHandler" property="*"/>
+</jsp:useBean>
+<%
+        if ("Log in".equals(infoCardPresented)) {
+            infoCardRegHandler.setInfoCardDetails(request);
+        } else {
+        if (infoCardRegHandler.isInputValid(request)) {
+            if (infoCardRegHandler.register()) {
+                response.sendRedirect(
+                        "registration_result.jsp?success=true&bounceback=" + 
bounceback);
+            } else {
+                response.sendRedirect(
+                        "registration_result.jsp?success=false&bounceback=" + 
bounceback);
+            }
+        }
+        }
+%>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd";>
+<html>
+<head>
+    <title>Mashups.wso2.org</title>
+    <!-- Required CSS -->
+    <link href="css/styles.css" rel="stylesheet" type="text/css"/>
+    <script language="javascript" src="js/common.js" 
type="text/javascript"></script>
+    <script language="javascript"
+            type="text/javascript">userLoggedOn = 
<%=RegistryUtils.isLoggedIn(registry) %>;</script>
+</head>
+<body>
+<div id="page">
+    <% String thisPage = "register_self.jsp"; %>
+    <%@ include file="header.jsp" %>
+       <div id="search"></div>
+    <div id="content" style="height:400px; ">
+        <% if (RegistrationBean.isSelfRegistrationEnabled()) { %>
+    <div class="mashup_title">Your infocard details have been added and will 
be verified via e-mail</div>
+      <br />
+                    <form name="formRegisterSelf" method='post' 
action="register_self_infocard.jsp">
+                        <input type="hidden" name="bounceback" 
value="<%=bounceback%>"/>
+                        <table width="100%" border="0" cellpadding="3" 
cellspacing="0" >
+                            <tr>
+                                <td width="130"><label><strong>Full 
Name:</strong></label></td>
+                                <td><%=infoCardRegHandler.getFullName()%></td>
+                            </tr>
+                            <tr>
+                                <td 
width="130"><label><strong>E-mail:</strong></label></td>
+                                <td><%=infoCardRegHandler.getEmailId()%></td>
+                            </tr>
+                            <tr>
+                                <td width="130"><label><strong>User Name:<font 
color="#FF0000">*</font></strong></label></td>
+                                <td><input type="text" name="userName"
+                                           
value="<%=infoCardRegHandler.getUserName()%>"/>
+                                    <br><font 
color="#FF0000"><%=infoCardRegHandler.getErrorMessage("userName")%></font>
+                                </td>
+                            </tr>
+                            <tr>
+                                <td><label><strong>Password:<font 
color="#FF0000">*</font></strong></label></td>
+                                <td><input type="password" name="password"
+                                           
value="<%=infoCardRegHandler.getPassword()%>"/>
+                                    <br><font 
color="#FF0000"><%=infoCardRegHandler.getErrorMessage("password")%></font>
+                                </td>
+                            </tr>
+                            <tr>
+                                <td><label><strong>Confirmation Password:<font 
color="#FF0000">*</font></strong></label></td>
+                                <td><input type="password"
+                                           
name="confirmedPassword"<%=infoCardRegHandler
+                                        .getConfirmedPassword()%>"/>
+                                    <br><font 
color="#FF0000"><%=infoCardRegHandler
+                                        
.getErrorMessage("confirmedPassword")%></font>
+                                </td>
+                            </tr>
+                            <tr>
+                                <td>&nbsp;</td>
+                                <td><input type="submit" value="Register"/> 
<input type="button" value="Cancel" onclick="document.location = '<%= 
bounceback %>';"></td>
+                            </tr>
+                            <tr>
+                              <td>&nbsp;</td>
+                              <td align="center"></td>
+                            </tr>
+                        </table>
+                     </form>
+        <br>
+        <% } else { %>
+            <div class="mashup_title">Self Registration Disabled</div>
+            <div>&nbsp; Self-registration disabled. Please contact 
administrator to register yourself.</div>
+        <% } %>
+        <br>
+    </div>
+    <%@ include file="footer.jsp" %>
+</div>
+</body>
+</html>

_______________________________________________
Mashup-dev mailing list
[email protected]
http://www.wso2.org/cgi-bin/mailman/listinfo/mashup-dev

Reply via email to