How to get list of users and their last login using user macro

Poornika Reddy Ekkati December 22, 2022

When I try to get the list of users with the user macro where I need the users last login and login count. But I'm unable to get that through the macro.

Is there any logic where I can get the users last login and the login count.

Macro which I've created:

## Macro title: Last Login
## Macro has a body: N
## Body processing: Selected body processing option
## Output: Selected output option
##
## Developed by: Poornika Reddy Ekkati
## Macro to display the last login date of users who have access to the current space
## @noparams

#set($containerManagerClass = $content.class.forName('com.atlassian.spring.container.ContainerManager'))
#set($getInstanceMethod = $containerManagerClass.getDeclaredMethod('getInstance',null))
#set($containerManager = $getInstanceMethod.invoke(null,null))
#set($containerContext = $containerManager.containerContext)
#set($loginManager = $containerContext.getComponent('loginManager'))
#set($users = $userAccessor.getUsers())


<table class="confluenceTable">
<tr>
<th class="confluenceTh">Count</th>
<th class="confluenceTh">User</th>
<th class="confluenceTh">Login Name</th>
<th class="confluenceTh">Last Successful Login</th>
<th class="confluenceTh">Directory</th>
</tr>

#set($count = 0)

#foreach($user in $users)
## list the last login date of users who can view the current space
#if($user.directoryId == 1)
#if($user.active == true)
#set($count = $count + 1)
<tr>
<td class="confluenceTd">$count</td>
<td class="confluenceTd">#usernameLink($user.name)</td>
<td class="confluenceTd">$user.name</td>
<td class="confluenceTd">$user.lastSuccessfulLoginDate</td>
##action.dateFormatter.formatDateTime($loginManager.getLoginInfo($user.name)
<td class="confluenceTd">$user.directoryId</td>
#end
#end
#end
</table>

 

Output which I get:

Screenshot (170).png

 

1 answer

0 votes
Patrick Vanhoof
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.
December 23, 2022

I don't think you can achieve this through the standard macro. Creating a user macro might be a solution but I can not help you with that.

Poornika Reddy Ekkati January 9, 2023

Thank you patrick. I've created a user macro, but it doesn't print the Last Successful Login. 

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events