5

1

BugMonkey allows you to set a customization to run for normal users, admin, etc, but I am looking for more granularity.

How to I get the current user's name and type (Normal, Administrator or Community)?

flag

1 Answer

5

Add the following code to your script to get the user type (sUserType) and name (sFullName):

var sUserType = "Not logged in";
var sFullName = "Anonymous";

if (IsLoggedIn())
{
  if (IsAdmin())
  {
    sUserType = "Administrator";
    sFullName = GetFullName();
  }
  else
  {
    var sCommunityType = "(" + FB_COMMUNITY + ")";
    if ($("#usertype").text().trim() == sCommunityType)
    {
      sUserType = "Community";
      var sNameAndType = $("#username").text();
      sFullName = sNameAndType.substring(0, sNameAndType.indexOf(sCommunityType));
    }
    else
    {
      sUserType = "Normal";
      sFullName = GetFullName();
    }
  }
}

This will help you figure out a) what type of user you're dealing with (sUserType will be one of "Not logged in", "Administrator", "Normal", or "Community") and b) what their full name is (sFullName will be either their name or "Anonymous" if they're not logged in).

There's a bit of hackery in there to deal with Community users, but I'm going to look into it and see if it can't be cleaned up.

link|flag
cool! Had no idea #username was in the DOM! – Rich Armstrong Jan 6 2010 at 18:43

Your Answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.