dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #12532
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 3873: Implemented function for saving and viewing last login date for users
------------------------------------------------------------
revno: 3873
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Sat 2011-06-11 21:51:41 +0200
message:
Implemented function for saving and viewing last login date for users
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/UserCredentials.java
dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/UserService.java
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/user/DefaultUserService.java
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/user/hibernate/HibernateUserStore.java
dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/user/hibernate/UserCredentials.hbm.xml
dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/security/listener/AuthenticationListener.java
dhis-2/dhis-web/dhis-web-commons/src/main/resources/META-INF/dhis/security.xml
dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/resources/org/hisp/dhis/user/i18n_module.properties
dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/webapp/dhis-web-maintenance-user/allUser.vm
dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/webapp/dhis-web-maintenance-user/javascript/user.js
dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/webapp/dhis-web-maintenance-user/responseUser.vm
dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/webapp/dhis-web-maintenance-user/user.vm
--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk
Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/UserCredentials.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/UserCredentials.java 2011-06-11 08:15:29 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/UserCredentials.java 2011-06-11 19:51:41 +0000
@@ -28,6 +28,7 @@
*/
import java.io.Serializable;
+import java.util.Date;
import java.util.HashSet;
import java.util.Set;
@@ -61,6 +62,8 @@
private String password;
private Set<UserAuthorityGroup> userAuthorityGroups = new HashSet<UserAuthorityGroup>();
+
+ private Date lastLogin;
// -------------------------------------------------------------------------
// Logic
@@ -147,6 +150,16 @@
// Getters and setters
// -------------------------------------------------------------------------
+ public int getId()
+ {
+ return id;
+ }
+
+ public void setId( int id )
+ {
+ this.id = id;
+ }
+
public String getPassword()
{
return password;
@@ -187,13 +200,13 @@
this.username = username;
}
- public int getId()
+ public Date getLastLogin()
{
- return id;
+ return lastLogin;
}
- public void setId( int id )
+ public void setLastLogin( Date lastLogin )
{
- this.id = id;
+ this.lastLogin = lastLogin;
}
}
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/UserService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/UserService.java 2011-05-28 21:53:18 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/UserService.java 2011-06-11 19:51:41 +0000
@@ -161,6 +161,14 @@
Collection<UserCredentials> getAllUserCredentials();
/**
+ * Updates the last login date of UserCredentials with the given username
+ * with the current date.
+ *
+ * @param username the username of the UserCredentials.
+ */
+ void setLastLogin( String username );
+
+ /**
* Deletes a UserCredentials.
*
* @param userCredentials the UserCredentials.
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/user/DefaultUserService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/user/DefaultUserService.java 2011-05-28 21:53:18 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/user/DefaultUserService.java 2011-06-11 19:51:41 +0000
@@ -1,12 +1,14 @@
package org.hisp.dhis.user;
import java.util.Collection;
+import java.util.Date;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hisp.dhis.dataset.DataSet;
import org.hisp.dhis.organisationunit.OrganisationUnit;
import org.hisp.dhis.system.util.AuditLogUtil;
+import org.springframework.transaction.annotation.Transactional;
/*
* Copyright (c) 2004-2010, University of Oslo
@@ -39,6 +41,7 @@
* @author Chau Thu Tran
* @version $Id$
*/
+@Transactional
public class DefaultUserService
implements UserService
{
@@ -319,9 +322,9 @@
return userStore.getUserCredentials( user );
}
- public UserCredentials getUserCredentialsByUsername( String userName )
+ public UserCredentials getUserCredentialsByUsername( String username )
{
- return userStore.getUserCredentialsByUsername( userName );
+ return userStore.getUserCredentialsByUsername( username );
}
public Collection<UserCredentials> getUsersBetween( int first, int max )
@@ -329,9 +332,9 @@
return userStore.getUsersBetween( first, max );
}
- public Collection<UserCredentials> getUsersBetweenByName( String userName, int first, int max )
+ public Collection<UserCredentials> getUsersBetweenByName( String username, int first, int max )
{
- return userStore.getUsersBetweenByName( userName, first, max );
+ return userStore.getUsersBetweenByName( username, first, max );
}
public Collection<UserCredentials> getUsersWithoutOrganisationUnitBetween( int first, int max )
@@ -339,14 +342,21 @@
return userStore.getUsersWithoutOrganisationUnitBetween( first, max );
}
- public Collection<UserCredentials> getUsersWithoutOrganisationUnitBetweenByName( String userName, int first, int max )
+ public Collection<UserCredentials> getUsersWithoutOrganisationUnitBetweenByName( String username, int first, int max )
{
- return userStore.getUsersWithoutOrganisationUnitBetweenByName( userName, first, max );
+ return userStore.getUsersWithoutOrganisationUnitBetweenByName( username, first, max );
}
- public Collection<UserCredentials> searchUsersByName( String userName )
- {
- return userStore.searchUsersByName( userName );
+ public Collection<UserCredentials> searchUsersByName( String username )
+ {
+ return userStore.searchUsersByName( username );
+ }
+
+ public void setLastLogin( String username )
+ {
+ UserCredentials credentials = getUserCredentialsByUsername( username );
+ credentials.setLastLogin( new Date() );
+ updateUserCredentials( credentials );
}
// -------------------------------------------------------------------------
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/user/hibernate/HibernateUserStore.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/user/hibernate/HibernateUserStore.java 2011-04-24 13:44:20 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/user/hibernate/HibernateUserStore.java 2011-06-11 19:51:41 +0000
@@ -46,13 +46,11 @@
import org.hisp.dhis.user.UserCredentials;
import org.hisp.dhis.user.UserSetting;
import org.hisp.dhis.user.UserStore;
-import org.springframework.transaction.annotation.Transactional;
/**
* @author Nguyen Hong Duc
* @version $Id: HibernateUserStore.java 6530 2008-11-28 15:02:47Z eivindwa $
*/
-@Transactional
public class HibernateUserStore
implements UserStore
{
@@ -434,12 +432,15 @@
private Collection<UserCredentials> findByName( Collection<UserCredentials> users, String key )
{
List<UserCredentials> returnList = new ArrayList<UserCredentials>();
-
+
for ( UserCredentials user : users )
{
- if ( user.getUsername().toLowerCase().contains( key.toLowerCase() ) )
+ if ( user != null )
{
- returnList.add( user );
+ if ( user.getUsername().toLowerCase().contains( key.toLowerCase() ) )
+ {
+ returnList.add( user );
+ }
}
}
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/user/hibernate/UserCredentials.hbm.xml'
--- dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/user/hibernate/UserCredentials.hbm.xml 2011-05-28 21:25:46 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/user/hibernate/UserCredentials.hbm.xml 2011-06-11 19:51:41 +0000
@@ -29,6 +29,8 @@
<key column="userid" foreign-key="fk_userrolemembers_userid" />
<many-to-many column="userroleid" class="org.hisp.dhis.user.UserAuthorityGroup" foreign-key="fk_userrolemembers_userroleid" />
</set>
+
+ <property name="lastLogin"/>
</class>
</hibernate-mapping>
=== modified file 'dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/security/listener/AuthenticationListener.java'
--- dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/security/listener/AuthenticationListener.java 2010-06-25 15:01:58 +0000
+++ dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/security/listener/AuthenticationListener.java 2011-06-11 19:51:41 +0000
@@ -27,8 +27,8 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+import org.hisp.dhis.user.UserService;
import org.hisp.dhis.useraudit.UserAuditService;
-import org.springframework.beans.factory.annotation.Required;
import org.springframework.context.ApplicationEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.security.authentication.event.AbstractAuthenticationFailureEvent;
@@ -42,13 +42,27 @@
public class AuthenticationListener
implements ApplicationListener<ApplicationEvent>
{
+ // -------------------------------------------------------------------------
+ // Dependencies
+ // -------------------------------------------------------------------------
+
private UserAuditService userAuditService;
- @Required
public void setUserAuditService( UserAuditService userAuditService )
{
this.userAuditService = userAuditService;
}
+
+ private UserService userService;
+
+ public void setUserService( UserService userService )
+ {
+ this.userService = userService;
+ }
+
+ // -------------------------------------------------------------------------
+ // ApplicationListener implementation
+ // -------------------------------------------------------------------------
public void onApplicationEvent( ApplicationEvent applicationEvent )
{
@@ -58,7 +72,11 @@
{
AuthenticationSuccessEvent event = (AuthenticationSuccessEvent) applicationEvent;
- userAuditService.registerLoginSuccess( ((UserDetails) event.getAuthentication().getPrincipal()).getUsername() );
+ String username = ((UserDetails) event.getAuthentication().getPrincipal()).getUsername();
+
+ userAuditService.registerLoginSuccess( username );
+
+ userService.setLastLogin( username );
}
else if ( applicationEvent instanceof AbstractAuthenticationFailureEvent )
{
=== modified file 'dhis-2/dhis-web/dhis-web-commons/src/main/resources/META-INF/dhis/security.xml'
--- dhis-2/dhis-web/dhis-web-commons/src/main/resources/META-INF/dhis/security.xml 2011-04-12 10:50:23 +0000
+++ dhis-2/dhis-web/dhis-web-commons/src/main/resources/META-INF/dhis/security.xml 2011-06-11 19:51:41 +0000
@@ -51,6 +51,7 @@
<bean id="authenticationListener" class="org.hisp.dhis.security.listener.AuthenticationListener">
<property name="userAuditService" ref="org.hisp.dhis.useraudit.UserAuditService" />
+ <property name="userService" ref="org.hisp.dhis.user.UserService"/>
</bean>
<!-- Security : AccessProvider -->
=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/resources/org/hisp/dhis/user/i18n_module.properties'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/resources/org/hisp/dhis/user/i18n_module.properties 2011-04-28 19:47:18 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/resources/org/hisp/dhis/user/i18n_module.properties 2011-06-11 19:51:41 +0000
@@ -235,4 +235,5 @@
add_user_group = Add user group
available_users = Available users
group_members = Group members
-no_of_Users = Number of users
\ No newline at end of file
+no_of_Users = Number of users
+last_login = Last login
\ No newline at end of file
=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/webapp/dhis-web-maintenance-user/allUser.vm'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/webapp/dhis-web-maintenance-user/allUser.vm 2011-03-14 21:10:15 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/webapp/dhis-web-maintenance-user/allUser.vm 2011-06-11 19:51:41 +0000
@@ -1,4 +1,4 @@
-<script type="text/javascript" src="javascripts/allUser.js"></script>
+<script type="text/javascript" src="javascript/allUser.js"></script>
<script type="text/javascript">
var i18n_confirm_delete = '$encoder.jsEscape( $i18n.getString( "confirm_delete_user" ) , "'")';
var i18n_none = '$encoder.jsEscape( $i18n.getString( "none" ) , "'")';
@@ -72,7 +72,8 @@
<p><label>$i18n.getString( "firstName" ):</label><br/><span id="firstNameField"></span></p>
<p><label>$i18n.getString( "email" ):</label><br/><span id="emailField"></span></p>
<p><label>$i18n.getString( "phone_number" ):</label><br/><span id="phoneNumberField"></span></p>
- <p><label>$i18n.getString( "number_of_orgunit" ):</label><br/><span id="numberOrgunitField"></span></p>
+ <p><label>$i18n.getString( "number_of_orgunit" ):</label><br/><span id="numberOrgunitField"></span></p>
+ <p><label>$i18n.getString( "last_login"):</label><br/><span id="lastLoginField"></span></p>
</div>
<div id="warningArea" style="position:fixed;right:10px;top:200px;display:none">
=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/webapp/dhis-web-maintenance-user/javascript/user.js'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/webapp/dhis-web-maintenance-user/javascript/user.js 2010-12-30 09:59:11 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/webapp/dhis-web-maintenance-user/javascript/user.js 2011-06-11 19:51:41 +0000
@@ -45,6 +45,9 @@
var numberOrgunit = getElementValue( userElement, 'numberOrgunit' );
setInnerHTML( 'numberOrgunitField', numberOrgunit ? numberOrgunit : '[' + i18n_none + ']' );
+ var lastLogin = getElementValue( userElement, 'lastLogin' );;
+ setInnerHTML( 'lastLoginField', lastLogin ? lastLogin : '[' + i18n_none + ']' );
+
showDetails();
}
=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/webapp/dhis-web-maintenance-user/responseUser.vm'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/webapp/dhis-web-maintenance-user/responseUser.vm 2010-09-23 09:52:41 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/webapp/dhis-web-maintenance-user/responseUser.vm 2011-06-11 19:51:41 +0000
@@ -6,4 +6,5 @@
<email>$!encoder.xmlEncode( $userCredentials.user.email )</email>
<phoneNumber>$!encoder.xmlEncode( $userCredentials.user.phoneNumber )</phoneNumber>
<numberOrgunit>$userCredentials.user.organisationUnits.size()</numberOrgunit>
+ <lastLogin>$!format.formatDate( $!userCredentials.lastLogin )</lastLogin>
</user>
=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/webapp/dhis-web-maintenance-user/user.vm'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/webapp/dhis-web-maintenance-user/user.vm 2011-03-14 21:10:15 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/webapp/dhis-web-maintenance-user/user.vm 2011-06-11 19:51:41 +0000
@@ -66,7 +66,8 @@
<p><label>$i18n.getString( "firstName" ):</label><br/><span id="firstNameField"></span></p>
<p><label>$i18n.getString( "email" ):</label><br/><span id="emailField"></span></p>
<p><label>$i18n.getString( "phone_number" ):</label><br/><span id="phoneNumberField"></span></p>
- <p><label>$i18n.getString( "number_of_orgunit" ):</label><br/><span id="numberOrgunitField"></span></p>
+ <p><label>$i18n.getString( "number_of_orgunit" ):</label><br/><span id="numberOrgunitField"></span></p>
+ <p><label>$i18n.getString( "last_login"):</label><br/><span id="lastLoginField"></span></p>
</div>
<div id="warningArea" style="position:fixed;right:10px;top:200px;display:none">