Author: channa
Date: Fri Dec  7 02:05:17 2007
New Revision: 10690

Log:

Added registry profile creation on user self registration and fixed up 
navigation for the self-registration and verification process.

Modified:
   trunk/mashup/java/modules/core/src/org/wso2/mashup/MashupConstants.java
   
trunk/mashup/java/modules/core/src/org/wso2/mashup/webapp/identity/Registration.java
   trunk/mashup/java/modules/www/org/header.jsp
   trunk/mashup/java/modules/www/org/register_self.jsp
   trunk/mashup/java/modules/www/org/registration_result.jsp
   trunk/mashup/java/modules/www/org/signin.jsp
   trunk/mashup/java/modules/www/org/validate.jsp

Modified: 
trunk/mashup/java/modules/core/src/org/wso2/mashup/MashupConstants.java
==============================================================================
--- trunk/mashup/java/modules/core/src/org/wso2/mashup/MashupConstants.java     
(original)
+++ trunk/mashup/java/modules/core/src/org/wso2/mashup/MashupConstants.java     
Fri Dec  7 02:05:17 2007
@@ -62,6 +62,7 @@
     public static final String FORMAL_NAME = "formalName";
     public static final String FIRST_NAME = "firstname";
     public static final String LAST_NAME = "lastname";
+    public static final String EMAIL_ID = "email";
 
     public static final String INFOCARD_PPID = "ppid";
     public static final String INFOCARD_COUNT = "cardcount";

Modified: 
trunk/mashup/java/modules/core/src/org/wso2/mashup/webapp/identity/Registration.java
==============================================================================
--- 
trunk/mashup/java/modules/core/src/org/wso2/mashup/webapp/identity/Registration.java
        (original)
+++ 
trunk/mashup/java/modules/core/src/org/wso2/mashup/webapp/identity/Registration.java
        Fri Dec  7 02:05:17 2007
@@ -18,13 +18,23 @@
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.wso2.mashup.MashupConstants;
-import org.wso2.usermanager.UserManagerException;
+import org.wso2.mashup.webapp.userprofile.User;
+import org.wso2.registry.ActionConstants;
+import org.wso2.registry.RegistryConstants;
+import org.wso2.registry.RegistryException;
+import org.wso2.registry.Resource;
+import org.wso2.registry.secure.SecureRegistry;
+import org.wso2.registry.secure.RegistryUserManager;
+import org.wso2.registry.jdbc.JDBCRegistry;
 import org.wso2.usermanager.Realm;
+import org.wso2.usermanager.UserManagerConstants;
+import org.wso2.usermanager.UserManagerException;
+import org.wso2.usermanager.UserStoreAdmin;
+import org.wso2.usermanager.AccessControlAdmin;
 import org.wso2.usermanager.verification.email.EmailVerifier;
-import org.wso2.registry.RegistryConstants;
 
-import javax.servlet.http.HttpServletRequest;
 import javax.servlet.ServletContext;
+import javax.servlet.http.HttpServletRequest;
 import java.util.HashMap;
 import java.util.Map;
 
@@ -58,6 +68,7 @@
 
             Map userAttributes = new HashMap();
             userAttributes.put(MashupConstants.FORMAL_NAME, formalName);
+            userAttributes.put(MashupConstants.EMAIL_ID, emailId);
 
             try {
                 verifier.requestUserVerification(userName, emailId, password, 
userAttributes);
@@ -69,7 +80,7 @@
         return success;
     }
 
-        /**
+    /**
      * Verify the self registered user via the confirmation string received 
from the e-mail URL.
      *
      * @param request Servlet request.
@@ -86,7 +97,7 @@
 
                 // Authorize confirmed user if verification succeeds.
                 userName = verifier.getUserName(confValue);
-                if (verifier.confirmUser(confValue)) {                    
+                if (verifier.confirmUser(confValue)) {
                     isVerified = authorizeUser(request, userName);
                 }
             } catch (UserManagerException e) {
@@ -97,7 +108,8 @@
     }
 
     /**
-     * Authorize user to use the secure registry.
+     * Authorizes user to the registry by granting him a role, then adding a 
user directory and
+     * creating a profile granting user edit access.
      *
      * @param userName Identifier of user to be authorized.
      */
@@ -105,12 +117,61 @@
         boolean isAuthorized = false;
         ServletContext context = request.getSession().getServletContext();
         Realm realm = (Realm) 
context.getAttribute(RegistryConstants.REGISTRY_REALM);
+        JDBCRegistry registry =
+                (JDBCRegistry) 
context.getAttribute(RegistryConstants.REGISTRY);
 
         try {
-            realm.getUserStoreAdmin().addUserToRole(userName, 
RegistryConstants.EVERYONE_ROLE);
+            // Get an instance of the secure registry as admin and then get 
it's user manager.
+            SecureRegistry secureRegistry = new 
SecureRegistry(RegistryConstants.ADMIN_USER,
+                                                               
MashupConstants.ADMIN_PASSWORD,
+                                                               registry, 
realm);
+            RegistryUserManager registryUserManager = 
secureRegistry.getUserManager();
+
+            // Grant the user the everyone role.
+            UserStoreAdmin userStoreAdmin = realm.getUserStoreAdmin();
+            AccessControlAdmin controlAdmin = realm.getAccessControlAdmin();
+            userStoreAdmin.addUserToRole(userName, 
RegistryConstants.EVERYONE_ROLE);
+
+            // Get the properties of the registered user to add them to the 
registry profile.
+            Map userProps = userStoreAdmin.getUserProperties(userName);
+            String formalName = (String) 
userProps.get(MashupConstants.FORMAL_NAME);
+            String eMail = (String) userProps.get(MashupConstants.EMAIL_ID);
+
+            // Add a user directory to the registry and grant edit permission.
+            Resource newUserCollection = new Resource();
+            newUserCollection.setDirectory(true);
+            registry.put("/users/" + userName, newUserCollection);
+            controlAdmin.authorizeUser(userName, "/users/" + userName, 
UserManagerConstants.EDIT);
+
+            // Set the user's profile path.
+            String profilePath = "/users/" + userName + "/profile";
+            registryUserManager
+                    .setUserProperty(userName, MashupConstants.PROFILE_PATH, 
profilePath);
+            registryUserManager
+                    .setUserProperty(userName, MashupConstants.FORMAL_NAME, 
formalName);
+
+            // Instantiate a new user object and assign properties.
+            User user = new User();
+            user.setEmailAddress(eMail);
+            user.setUsername(userName);
+            user.setBio(formalName);
+
+            // Assign a set of default queries.
+            user.addQuery("My Mashups", MashupConstants.MY_MASHUPS_QUERY_PATH,
+                               new String[] { userName });
+            user.addQuery("All Mashups", 
MashupConstants.ALL_MASHUPS_QUERY_PATH,
+                               new String[] { });
+
+            // Create new resource, assign user information, save in profile 
path granting authority.
+            Resource userProfile = new Resource();
+            userProfile.setContent(user.serializeUserProfile().getBytes());
+            registry.put(profilePath, userProfile);
+            controlAdmin.authorizeUser(userName, profilePath, 
ActionConstants.PUT);
             isAuthorized = true;
         } catch (UserManagerException e) {
             log.error("Error adding user to role", e);
+        } catch (RegistryException e) {
+            log.error("Error adding user resources", e);
         }
         return isAuthorized;
     }

Modified: trunk/mashup/java/modules/www/org/header.jsp
==============================================================================
--- trunk/mashup/java/modules/www/org/header.jsp        (original)
+++ trunk/mashup/java/modules/www/org/header.jsp        Fri Dec  7 02:05:17 2007
@@ -27,7 +27,7 @@
                 | <a 
href="signout.jsp?bounceback=<%=URLEncoder.encode(thisPage,"UTF-8")%>">Sign 
out</a>
 <%      } else { %>
                 | <a 
href="signin.jsp?bounceback=<%=URLEncoder.encode(thisPage,"UTF-8")%>">Sign 
in</a>
-                | <a href="register_self.jsp">Sign up</a>
+                | <a 
href="register_self.jsp?bounceback=<%=URLEncoder.encode(thisPage,"UTF-8")%>">Sign
 up</a>
 <%      }
     }  %>
             </td>

Modified: trunk/mashup/java/modules/www/org/register_self.jsp
==============================================================================
--- trunk/mashup/java/modules/www/org/register_self.jsp (original)
+++ trunk/mashup/java/modules/www/org/register_self.jsp Fri Dec  7 02:05:17 2007
@@ -51,9 +51,13 @@
 <%@ page import="java.util.List" %>
 <%@ page import="java.util.Map" %>
 <%
-
     Registry registry = RegistryUtils.getRegistry(request);
-
+    String bounceback = request.getParameter("bounceback");
+    if (bounceback == null) {
+        bounceback = "index.jsp";
+    } else {
+        bounceback = URLDecoder.decode(bounceback, "UTF-8");
+    }
 %>
 <html>
 <head>
@@ -75,6 +79,7 @@
             <tr>
                 <td>
                     <form name="formRegisterSelf" method='post' 
action="registration_result.jsp">
+                        <input type="hidden" name="bounceback" 
value="<%=bounceback%>"/>
                         <table width="100%" border="0" cellspacing="0" 
cellpadding="3">
                             <tr>
                                 <td width="130"><label><strong>User 
Name:</strong></label></td>

Modified: trunk/mashup/java/modules/www/org/registration_result.jsp
==============================================================================
--- trunk/mashup/java/modules/www/org/registration_result.jsp   (original)
+++ trunk/mashup/java/modules/www/org/registration_result.jsp   Fri Dec  7 
02:05:17 2007
@@ -53,7 +53,12 @@
 <%
 
     Registry registry = RegistryUtils.getRegistry(request);
-
+    String bounceback = request.getParameter("bounceback");
+    if (bounceback == null) {
+        bounceback = "index.jsp";
+    } else {
+        bounceback = URLDecoder.decode(bounceback, "UTF-8");
+    }
 %>
 <html>
 <head>
@@ -75,10 +80,12 @@
             <tr>
                 <td align="center" height="175">
                     <% if (Registration.register(request)) { %>
-                    <div class="login-error">Self-registration successful. 
Please check mail and click on the link sent.</div>
+                    <div class="login-error">Self-registration successful. 
Please check the specified
+                        mail account and click on the link sent to verify your 
registration.</div>
                     <% } else { %>
                     <div class="login-error">Self-registration failed. Please 
try again.</div>
                     <% } %>
+                    You may return to the page you were on using this <a 
href="<%=URLEncoder.encode(bounceback,"UTF-8")%>">link</a>.
                 </td>
             </tr>
         </table>

Modified: trunk/mashup/java/modules/www/org/signin.jsp
==============================================================================
--- trunk/mashup/java/modules/www/org/signin.jsp        (original)
+++ trunk/mashup/java/modules/www/org/signin.jsp        Fri Dec  7 02:05:17 2007
@@ -133,7 +133,7 @@
                                                                                
        value="Sign In"/></div>
                                 </td>
                                 <td align="center" height="175">
-                                    <a href="infocard.jsp?bounceback=<%= 
bounceback %>"><img src="images/infocard_92x64.png" border="0"></a>
+                                    <a 
href="infocard.jsp?bounceback=<%=URLEncoder.encode(bounceback,"UTF-8")%>"><img 
src="images/infocard_92x64.png" border="0"></a>
                                     <br/>
                                     Signup using your personal or managed 
infocard.
                                 </td>

Modified: trunk/mashup/java/modules/www/org/validate.jsp
==============================================================================
--- trunk/mashup/java/modules/www/org/validate.jsp      (original)
+++ trunk/mashup/java/modules/www/org/validate.jsp      Fri Dec  7 02:05:17 2007
@@ -31,7 +31,7 @@
 </head>
 <body>
 <div id="page">
-    <% String thisPage = "validate.jsp"; %>
+    <% String thisPage = "index.jsp"; %>
     <%@ include file="header.jsp" %>
     <div id="content">
         <table width="100%" height="400" border="0" cellspacing="0" 
cellpadding="5">

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

Reply via email to