Question

I am trying to make a site using Google Sites, and i need a way to know the user name or group and then redirect them to different pages.

Also if you have any Google script that can help, that will be great too, thanks.

Was it helpful?

Solution

This is a very simple answer but it can help. We just need to get the user ID and compare it to the list of authorized users, if user is in the list then a link is created, if not, a label is created telling the user they need permission.

I don't need more than that for now, but in the future 2 more features can be cool to add:
1- using group names instead of an array with users to be more dynamic. (i don't know how yet)
2- auto redirect user instead of displaying a link. (i think that can be easy)

function doGet() {
  var app = UiApp.createApplication();

  var arr = new Array(4);
  arr[0] = "user_001@company.com";
  arr[1] = "user_002@company.com";
  arr[2] = "user_003@company.com";
  arr[3] = "user_004@company.com";

  for (var i = 0; i < arr.length; i++) {
    if (Session.getActiveUser().getUserLoginId() == arr[i]){
      var label = app.createLabel('User: ' + Session.getActiveUser().getUserLoginId() + ', You have permission :)');//false
      var link = app.createAnchor('Here is your link', 'http://www.umich.edu').setId("link").setVisible(true);//false
      var flag = 1;
      break;
      //#####################
    } else {
      var label = app.createLabel('You need permission :(');//false
      var flag = 0;
    }
  }
      app.add(label);
  if (flag == 1){app.add(link);}

  return app;
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top