cancel
Showing results for 
Search instead for 
Did you mean: 

Redirect users to their default site - temporary solution

juan
Champ in-the-making
Champ in-the-making
Hi,

I have been working in a simple solution to redirect users to their "default sites". It is not a perfect solution, but it works. However I would thank your collaboration to improve it.

This is my tomcat/webapps/share/site-index.jsp modified file:


<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<%@ page import="org.alfresco.web.site.*" %>
<%@ page import="org.springframework.extensions.surf.*" %>
<%@ page import="org.springframework.extensions.surf.site.*" %>
<%@ page import="org.springframework.extensions.surf.util.*" %>
<%@ page import="java.util.*" %>

<%@ page import="org.springframework.extensions.webscripts.connector.*" %>

<%
   String redirection = "";

   // retrieve user name from the session
   String userid = (String)session.getAttribute(SlingshotUserFactory.SESSION_ATTRIBUTE_KEY_USER_ID);


   // test user dashboard page exists?
   RequestContext context = (RequestContext)request.getAttribute(RequestContext.ATTR_REQUEST_CONTEXT);
   if (context.getObjectService().getPage("user/" + userid + "/dashboard") == null)
   {
      // no site found! create initial dashboard for this user…
      Map<String, String> tokens = new HashMap<String, String>();
      tokens.put("userid", userid);
      FrameworkUtil.getServiceRegistry().getPresetsManager().constructPreset("user-dashboard", tokens);
   }
  
   User user = context.getUser();

   //user.setProperty( "defaultSite", "central" ); // this property was not perisistent so it was disscarded
   //user.setSkype("central");// use skype property instead
   //user.save();

   String defaultSite = user.getSkype();//here "defaultSite" is stored

   if( defaultSite == null )
   {
      // forward to user specific dashboard page
        redirection = request.getContextPath() + "/page/user/" + URLEncoder.encode(userid) + "/dashboard";
   }
   else
   {
   redirection = request.getContextPath() + "/page/site/" + defaultSite  + "/documentlibrary" ;
   }

  response.sendRedirect( redirection );
%>

(Temporary it uses "Skype" property to store default site. )

Suggestions and comments are welcome.
2 REPLIES 2

juan
Champ in-the-making
Champ in-the-making
Some usefull scripts:

GetUsersDefaultSites.js

var gens = search.luceneSearch("TYPE:\"{http://www.alfresco.org/model/content/1.0}person\"");
    var logFile = space.childByNamePath("out_defaulSite.csv");
    if (logFile == null) {
       logFile = space.createFile("out_defaulSite.csv");
    }
    logFile.content = "";

   var lines = Array();
   var i =0;
    for ( i=0; i<gens.length;i++) {
     if( gens[i].properties["cm:skype"] != null )
        lines[i] = gens[i].properties["cm:userName"]+ "," + gens[i].properties["cm:skype"]+"\n";
     else
       lines[i] = gens[i].properties["cm:userName"]+ "," + "\n";
      }
    
     lines.sort();
    
     for ( i=0; i<lines.length;i++) {
      logFile.content += lines[i];
     }

and

SetUsersDefaultSites.js

    var csvFile = space.childByNamePath("in_defaulSite.csv");

    if ( csvFile == null ){
      logger.log("File not found in_defaulSite.csv");
   }
   else{   
      logger.log("File found");
      var user_list = new Array();
      var defaultsite_list = new Array();
       var lines = csvFile.content.split("\n",1000);
      var tmpline = new Array();
      for (var i=0; i<lines.length;i++) {
      tmpline = lines[i].split(",",2);
      if( tmpline.length > 1 )
      {
         var user = people.getPerson(tmpline[0]);
         if(user == null){
            logger.log("User is null while setting skype " + tmpline[0]);
         }else{
            if(tmpline[1] == null || tmpline[0] == ''){
                  user.properties["cm:skype"] = null;
                  user.save();
            }
            else{
               user.properties["cm:skype"] = tmpline[1].replace("\r","");
               user.save();
            }
         }
      }
      }
    }

bigrob
Champ in-the-making
Champ in-the-making
Thanks for this Juan. I've been trying to set up a company document portal using alfresco share, but at the request of my (absolutely computer illiterate) boss i'm removing as many of the extra features/steps between logging in and browsing your site's document portal as possible.

In Alfresco i'm creating one user and one site so that each customer can access their documents through a single login. By keeping the site name and user name identical I thought I would easily be able to change /user/ to /site/ in the url's. Whilst I have this working for the customers, my admin account does not have a site called admin so I'd like to use an if function to test if a site with the same name as that user exists, and if not send them to their user dashboard. I've tried altering the site-index.jsp but the "test user's site page exists?" part doesn't send me to the user dashboard when the site doesn't exist, it just gives me an error.

My site-index.jsp:
     // retrieve user name from the session
   String userid = (String)session.getAttribute(SlingshotUserFactory.SESSION_ATTRIBUTE_KEY_USER_ID);
  
   // test user's site page exists?
   RequestContext context = (RequestContext)request.getAttribute(RequestContext.ATTR_REQUEST_CONTEXT);
   if (context.getObjectService().getPage("site/" + userid + "/dashboard") == null)
   {
      // no site found! create initial dashboard for this user…
      response.sendRedirect(request.getContextPath() + "/page/user/" + URLEncoder.encode(userid) + "/dashboard");
   }
  
   // forward to site with same name as user
   response.sendRedirect(request.getContextPath() + "/page/site/" + URLEncoder.encode(userid) + "/dashboard");

Any pointers you could give me would be great, i'm pretty experienced with programming in php but i've yet to learn java's syntax!

Thanks in advance, Rob