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

Next challenges

Recent achievements

  • Global
  • Personal

Recognition

  • Give kudos
  • Received
  • Given

Leaderboard

  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Last Login User Macro customized

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 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))

 


<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

1 answer

1 accepted

0 votes
Answer accepted
Bill Bailey Community Leader Sep 04, 2020

What do you get? Blank in that cell? Error rendering macro? Have you looked at the Confluence log for errors?

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.

There are no errors in the log

Bill Bailey Community Leader Sep 04, 2020

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() rather than .lastSuccessfulLoginDate

Which version of Confluence are you using?

Hi @Kaya_ Rahmi ,

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

Thank you!

KR, Marco

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

@Kaya_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?

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Confluence

Announcing Team Calendars in Confluence Data Center

Hi Community! We're thrilled to share that Team Calendars for Confluence is now a built-in feature for Confluence Data Center releases 7.11 and beyond.  A long time favorite,  Team Cale...

26 views 0 2
Read article

Community Events

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

Find an event

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

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you