cancel
Showing results for 
Search instead for 
Did you mean: 

javascript - name of current user?

fx3000se
Champ in-the-making
Champ in-the-making
Sounds like a simple question:
In Javascript: how do I find out the name of the currently logged in user?

I tried with the root objects "person" and "session" but couldn't get name out of them…

Thx
fx3000se
8 REPLIES 8

mikeh
Star Contributor
Star Contributor
If you're after username, then it's
person.properties.userName
Thanks,
Mike

rafaelscg
Champ on-the-rise
Champ on-the-rise
When i use this with my UI Action, the person what is return is only Admin.
Anybody know's why?

Thanks

rafaelscg
Champ on-the-rise
Champ on-the-rise
Sorry. I found the problem.  Smiley Surprisedops:

susana
Champ in-the-making
Champ in-the-making
I have the same problem! Can you help me to understand it?

sanket
Champ on-the-rise
Champ on-the-rise
I am always getting "admin" when I execute
person.properties.userName;

Can you plz help.

nirvanvjain
Champ on-the-rise
Champ on-the-rise
Dear Folks,

I am also getting the same issue.

I always get the admin as current logged in User even though I am logging as normal user.

Please help me with the issue.

Thanks!
-Nirvan

romschn
Star Collaborator
Star Collaborator
Hi,

I am using alfresco v 3.4.3 and I have tried to replicate your scenario where in I have created a webscript which will just fetch me the current user name.

Below is the reference code :
1. xyz.get.js file
function main()
{
   model.currentUserDetails = person.properties.userName;
}

main();

2. xyz.get.json.ftl file

{      
        "userName":"${currentUserDetails}"                   
}

3. xyz.get.desc.xml file - description file

<webscript>
  <shortname>CurrentUser</shortname>
  <url>/api/user/currentuser</url>
  <format default="json"/>
  <authentication>user</authentication>
<transaction allow="readonly">required</transaction>
</webscript>

This is giving me the correct logged in user.

One probable reason I could think of is - admin user must be in browser history/Cache. You may try clearing the browser history and see if it works or not.

Please share if you found the root cause of why person.properties.userName always gives you the admin user.

Thanks,

malliswar
Champ in-the-making
Champ in-the-making
i tried person.properties.username


but it always gives "admin"

if anyone solved this

please help me

Thanks in advance