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

Lakshmi August 7, 2013

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

2 votes
Lakshmi August 7, 2013

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>

1 vote
Lakshmi August 27, 2013
&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.
 
0 votes
RambanamP
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 7, 2013

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;

Lakshmi August 7, 2013

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

Thanks,

Lakshmi

0 votes
RambanamP
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 7, 2013

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

Lakshmi August 7, 2013

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

RambanamP
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 7, 2013

check now i have updated my answer!

Lakshmi August 7, 2013

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

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events