Last Login User Macro customized
Asked by Kaya, Rahmi:

Hey Community,

i?ve got a Macro to get a list about the last Logins for Confluence.

But it doesn?t give me the important information about the last login of my users.

## [@Param](/t5/user/viewprofilepage/user-id/1345631) group:title=Gruppe\|type=string\|required=true\|desc=Group to show

#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($crowdService = $containerContext.getComponent('crowdService'))  
#set($t1=$content.currentDate.time)

#set($group = $userAccessor.getGroup($paramgroup))

#if($group)  
#set($usernames = $userAccessor.getMemberNames($group))

<br />

\<table class="confluenceTable" width="660px"\>  
\<tr\>  
\<th class="confluenceTh " width="220px"\>Name\</th\>  
\<th class="confluenceTh" width="110px"\>Create date\</th\>  
\<th class="confluenceTh" width="110px"\>Last Login\</th\>  
\<th class="confluenceTh" width="110px" style="text-align:center;"\>Activated\</th\>  
\<th class="confluenceTh" width="110px" style="text-align:center;"\>Days\</th\>  
\</tr\>  
#foreach($username in $usernames)  
#set($t3=9999)  
#set($user = $userAccessor.getUser($username))  
#set($crowdUser = $crowdService.getUser($user.name))

\<tr\>  
\<td class="confluenceTd"\>#usernameLink($user.name)\</td\>  
\<td class="confluenceTd" style="text-align:center;"\>$action.dateFormatter.formatGivenString('dd.MM.yyyy', $crowdUser.createdDate)\</td\>  
\<td class="confluenceTd" style="text-align:center;"\>$loginManager.getLoginInfo($user).lastSuccessfulLoginDate.toString\</td\>  
\<td class="confluenceTd" style="text-align:center;"\>  
#if($userAccessor.isDeactivated($user))  
\<ac:macro ac:name="status"\>  
\<ac:parameter ac:name="colour"\>Red\</ac:parameter\>  
\<ac:parameter ac:name="title"\>Nein\</ac:parameter\>  
\</ac:macro\>  
#else  
\<ac:macro ac:name="status"\>  
\<ac:parameter ac:name="colour"\>Green\</ac:parameter\>  
\<ac:parameter ac:name="title"\>Ja\</ac:parameter\>  
\</ac:macro\>  
#set($totalactiveusers = $totalactiveusers + 1)  
#end

\</td\>

#if($loginManager.getLoginInfo($user).lastSuccessfulLoginDate)  
#set($t3= $content.currentDate.time - $loginManager.getLoginInfo($user).lastSuccessfulLoginDate.time)  
#set($t3=$t3/1000/24/60/60)  
#end  
\<td class="confluenceTd" style="text-align:center;"\>  
#if($t3 \< 7)  
\<ac:macro ac:name="status"\>  
\<ac:parameter ac:name="colour"\>Green\</ac:parameter\>  
\<ac:parameter ac:name="title"\>$t3\</ac:parameter\>  
\</ac:macro\>  
#elseif($t3 \< 14)  
\<ac:macro ac:name="status"\>  
\<ac:parameter ac:name="colour"\>Yellow\</ac:parameter\>  
\<ac:parameter ac:name="title"\>$t3\</ac:parameter\>  
\</ac:macro\>  
#elseif($t3 \< 9999)  
\<ac:macro ac:name="status"\>  
\<ac:parameter ac:name="colour"\>Red\</ac:parameter\>  
\<ac:parameter ac:name="title"\>$t3\</ac:parameter\>  
\</ac:macro\>  
#else  
\<ac:macro ac:name="status"\>  
\<ac:parameter ac:name="colour"\>Magenta\</ac:parameter\>  
\<ac:parameter ac:name="title"\>$t3\</ac:parameter\>  
\</ac:macro\>

#end

\</td\>  
\</tr\>  
#end  
\</table\>  
#end


Answers:
author: Bill Bailey
body: What do you get? Blank in that cell? Error rendering macro? Have you looked at the Confluence log for errors?

comments: author: Kaya, Rahmi
body: Hey Bill thank you for your Response,

I get a blank cell.

The Check of redenering is Marked. The Macro works but i dont get the Information about rhe last Lagin. It stays blank.


author: Kaya, Rahmi
body: There are no errors in the log


author: Bill Bailey
body: Can you access the logs? It may give some insight into what is wrong. Blank often means that the method/property you are using does not exist in the Velocity context. I am guessing that this is where your macro fails:

```
#if($loginManager.getLoginInfo($user).lastSuccessfulLoginDate)
```

In other words, that construct is null so the condition is evaluated is false.

In a case like this, I start with a very simple test macro to try to determine what properties and methods are visible to me. I would create a simple user macro that lets you select a user, and try to see how to get what you want. It might be as simple as having to be more explicit in your structures, using [getLastSuccessfulLoginDate](https://docs.atlassian.com/atlassian-confluence/5.9.2/com/atlassian/confluence/security/persistence/dao/hibernate/UserLoginInfo.html#getLastSuccessfulLoginDate--)`()` rather than .lastSuccessfulLoginDate

Which version of Confluence are you using?


author: Marco H?lzemer
body: Hi [@Kaya, Rahmi](/t5/user/viewprofilepage/user-id/3713734) ,

can you post your new working macro code please? I've got the same problem.

Thank you!

KR, Marco


author: Kaya, Rahmi
body: Dear Marco,

i?ve builded a SQL.file and a Batch.file to get these informations as a csv. I?ve worked more then 3 Hours for this.

But currently it only works with PostgreSQL.

Best Regards,

Rahmi Kaya


author: Philipp Arnold
body: [@Kaya](/t5/user/viewprofilepage/user-id/1506984)_Rahmi,

I would be interested as well. I read in another Thread that Atlassian tighened the security so that you cannot access the loginmanager without modifying the velocity.properties. Is that correct?


author: Marco H?lzemer
body: [@Philipp Arnold](/t5/user/viewprofilepage/user-id/131010)

Thanks for the hint! I have found the solution here:

<https://community.atlassian.com/t5/Confluence-questions/User-macro-using-LoginManager-not-working-anymore-in-Confluence/qaq-p/1347650>

KR, Marco


Tags: confluence-server

login

macro

server

user

user-macro

user-management