Forums

Home » Liferay Portal » English » 2. Using Liferay » General

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Ryan T
User login information - When a user last logged in
November 17, 2010 5:59 PM
Answer

Ryan T

Rank: Junior Member

Posts: 94

Join Date: October 30, 2008

Recent Posts

Is there a way to see when a user last logged in or even better, a trail of all their login s?

I have poked around and unless the words I aanm searching for are wrong, I cannot find anything.

Thanks,

Ryan
Amos Fong
RE: User login information - When a user last logged in
November 17, 2010 7:08 PM
Answer

Amos Fong

LIFERAY STAFF

Rank: Liferay Legend

Posts: 1913

Join Date: October 7, 2008

Recent Posts

Hey Ryan,

If you have the user object you can use this method:
1
2    public Date getLastLoginDate() {
3        return _lastLoginDate;
4    }


I don't think a history is kept anywhere though.
Ryan T
RE: User login information - When a user last logged in
December 17, 2010 8:52 AM
Answer

Ryan T

Rank: Junior Member

Posts: 94

Join Date: October 30, 2008

Recent Posts

Thanks... I have no idea where I would use that (Its been forever since I coded). Any help on where this would go?

Thanks!!
Sandeep Nair
RE: User login information - When a user last logged in
December 17, 2010 9:11 AM
Answer

Sandeep Nair

Rank: Liferay Legend

Posts: 1721

Join Date: November 5, 2008

Recent Posts

Hi,

As Amos said you can just retrieve only the lastloginDate of the user

If you want to find the login date of the logged in user simply use the following

PortalUtil.getUser(request).getLastLoginDate();

If you want loginDate of all users, u can call UserLocalServiceUtil.getUsers(-1,-1);
to retrieve all users in system and then use the above method in a loop.
Marcus Souza
RE: User login information - When a user last logged in
January 10, 2011 8:14 AM
Answer

Marcus Souza

Rank: Junior Member

Posts: 58

Join Date: March 31, 2009

Recent Posts

Sandeep Nair:
Hi,

As Amos said you can just retrieve only the lastloginDate of the user

If you want to find the login date of the logged in user simply use the following

PortalUtil.getUser(request).getLastLoginDate();

If you want loginDate of all users, u can call UserLocalServiceUtil.getUsers(-1,-1);
to retrieve all users in system and then use the above method in a loop.


I am trying the same thing in a VM File
with the code

$user.getLastLoginDate() --> Mon Jan 10 16:11:47 GMT 2011

I get it, but i cant format or split it

I tried

$splittedLoginDate = $stringUtil.split($user.getLoginDate(), ' ')
$date.format('medium',$user.getLoginDate())

but i get just the same string. can someone pls point me in the right direction?

Marcus
Sandeep Nair
RE: User login information - When a user last logged in
January 10, 2011 9:02 AM
Answer

Sandeep Nair

Rank: Liferay Legend

Posts: 1721

Join Date: November 5, 2008

Recent Posts

You can use date variable to format. For example if you want to get year from date u could use something as

$date.getDate($user.getLoginDate(),"yyyy", $locale)

The above will give you year in your case 2011
Marcus Souza
RE: User login information - When a user last logged in
January 11, 2011 12:20 AM
Answer

Marcus Souza

Rank: Junior Member

Posts: 58

Join Date: March 31, 2009

Recent Posts

It works. Thanks a lot Sandeep. Where are the library with all methodes? then I dont need to ask next time.
Marcus
Sandeep Nair
RE: User login information - When a user last logged in
January 11, 2011 1:26 AM
Answer

Sandeep Nair

Rank: Liferay Legend

Posts: 1721

Join Date: November 5, 2008

Recent Posts

Actually i am not aware. Basically what i do is i know all the variables that used in vm files are put using VelocityVariable. So i just dig Velocity Variables and then see the init.vm of unstyled theme to see, to which variable is it assigned to.
Ken Patrick
RE: User login information - When a user last logged in
April 20, 2012 8:33 AM
Answer

Ken Patrick

Rank: New Member

Posts: 9

Join Date: November 2, 2011

Recent Posts

Sandeep Nair:
Actually i am not aware. Basically what i do is i know all the variables that used in vm files are put using VelocityVariable. So i just dig Velocity Variables and then see the init.vm of unstyled theme to see, to which variable is it assigned to.



I can't figure out how to get the month at all, I have it set as:

1$date.getDate($user.getLoginDate(),"dd", $locale)/$date.getDate($user.getLoginDate(),"mm", $locale)/$date.getDate($user.getLoginDate(),"yyyy", $locale)


however that gets me an odd date:

20/53/2012
David H Nebinger
RE: User login information - When a user last logged in
April 20, 2012 9:24 AM
Answer

David H Nebinger

Community Moderator

Rank: Liferay Legend

Posts: 11793

Join Date: September 1, 2006

Recent Posts

'mm' is minute, 'MM' is month.
Ken Patrick
RE: User login information - When a user last logged in
April 20, 2012 10:37 AM
Answer

Ken Patrick

Rank: New Member

Posts: 9

Join Date: November 2, 2011

Recent Posts

thank you!
Chethan Barike
RE: User login information - When a user last logged in
November 13, 2012 11:17 PM
Answer

Chethan Barike

Rank: Junior Member

Posts: 28

Join Date: March 27, 2012

Recent Posts

Hi Ken Patrick,

use in this way -- $date.getDate($user.getLastLoginDate(),"dd-MM-yyyy hh:mm:ss",$locale)

Ken Patrick:

I can't figure out how to get the month at all, I have it set as:
1$date.getDate($user.getLoginDate(),"dd", $locale)/$date.getDate($user.getLoginDate(),"mm", $locale)/$date.getDate($user.getLoginDate(),"yyyy", $locale)

however that gets me an odd date:
20/53/2012


BR,
Chethan
Steve Cochran
RE: User login information - When a user last logged in
November 16, 2012 2:22 PM
Answer

Steve Cochran

Rank: New Member

Posts: 13

Join Date: August 21, 2012

Recent Posts

Anyone know if it possible to see this through the control panel GUI?