way to get login id and pass as query string in confluence?

Hi, I am looking for the option to get user login id and pass the value to query stirng to url .

help please?

Thanks,

Laskhmi

4 answers

the below code is working to get user login id with confluence 5.1.3:


<script type="text/javascript">

alert(AJS.Data.get("remote-user"));

</script>

&lt;script type="text/javascript"&gt;
var init = 0;   
function download() 
{  
var url = document.getElementById("dload_frame").src;  
var userEmail;
var userlogin = AJS.Data.get("remote-user"); 

var userName= AJS.Data.get("user-display-name");  
var arr=userName.split(",");  
var Firstname=arr[1];
var Lastname=arr[0];
userEmail = userlogin+"@xyz.com"    ;
var url1="http://www.abc.com?firstname=" + Firstname + "&amp;lastname=" + Lastname + "&amp;email="+ userEmail; 
 
document.getElementById("dload_frame").src = url1; 
}   

&lt;/script&gt; 
    
&lt;iframe id="dload_frame" src="" width="800" height="400" frameborder="0" scrolling="no" &gt; &lt;/iframe&gt;   
&lt;script&gt;   download();   &lt;/script&gt;

The provided code should be HTML macro. this code is to pass frist name, last name and email id from confluence logged in user and passing values to iframe url.
 

if you are tyring to get through jira api then use this

ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()

or if you are trying to get in JAvaScript then try with this

AJS.params.loggedInUser 
or
function getCurrentUserName()
{
var user;
     AJS.$.ajax({
        url: "/confluence/rest/prototype/1/user/current",
        type: 'get',
        dataType: 'json',
        async: false,
        success: function(data) {
            user = data.username;
        }
     });
     return user;
}

and check this post

https://answers.atlassian.com/questions/167046/expose-the-value-of-action-remoteuser-name-to-javascript?page=1

Hi Prasad, Thans for the prompt reply.

can you also let me know the variable to get user's firstname and lastname?

My idea is to get everyting done through HTML code in confluence. Basically this HTML code will get the user login id and pass that value to querystring of the url in iframe tab.

will the above suits for my requirement? please suggest.

Thanks,

Lakshmi

check now i have updated my answer!

Hi Prasad, thanks again!

I have just tried above provided code by placing between <script language="Javascript"> </script>. i tried to display the user value using alert(user) instead. but code did not work . getting alert message 'undefined' after save the page.


below is the code i tried to put in HTML macro

 <script language="Javascript"> 

var user;
AJS.$.ajax({         url: "/confluence/rest/prototype/1/user/current",         type: 'get',         dataType: 'json',         async: false,         success: function(data) {             
user = data.username;
}
});
 alert(user);     
   
</script> 

did i place something wrong? please help me this non-programmer.

or guide me how to use AJS.params.loggedInUser in script?

Thanks,

Lakshmi

try with this

&lt;script type="text/javascript"&gt;
    alert(AJS.Meta.get("ajs-user-display-name"));
    alert(AJS.Meta.get("ajs-remote-user"));
&lt;/script&gt;
or 
&lt;script type="text/javascript"&gt;
    alert(AJS.params.loggedInUser);    
    alert(AJS.params.remoteUser);
&lt;/script&gt;

Both the cases i end up with alert which says 'undefined' . No luck :-(

Thanks,

Lakshmi

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted 8 hours ago in Canada

TOPIC TUESDAY - Fav Scary Monster!

Hey folks and happy Topic Tuesday! In the spirit of Halloween and all things scary, today's topic is what is your favourite horror movie monster. My personal choice here would be Jason from the Frida...

11 views 0 0
View post

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you