Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Celebration

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,463,310
Community Members
 
Community Events
176
Community Groups

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

Edited

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

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.

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

Atlassian Community Events