NIHVIVO-2819 Store the time of last login as part of the UserAccount. Display it on the List page.
This commit is contained in:
parent
c5c4ecd394
commit
0fdf28d3f5
14 changed files with 87 additions and 8 deletions
|
@ -54,6 +54,7 @@ public class UserAccount {
|
|||
private boolean passwordChangeRequired = false;
|
||||
|
||||
private int loginCount = 0; // Never negative.
|
||||
private long lastLoginTime = 0L; // Never negative.
|
||||
private Status status = Status.INACTIVE; // Might be null.
|
||||
private String externalAuthId = ""; // Never null.
|
||||
|
||||
|
@ -143,6 +144,14 @@ public class UserAccount {
|
|||
this.loginCount = Math.max(0, loginCount);
|
||||
}
|
||||
|
||||
public long getLastLoginTime() {
|
||||
return lastLoginTime;
|
||||
}
|
||||
|
||||
public void setLastLoginTime(long lastLoginTime) {
|
||||
this.lastLoginTime = Math.max(0, lastLoginTime);
|
||||
}
|
||||
|
||||
public Status getStatus() {
|
||||
return status;
|
||||
}
|
||||
|
|
|
@ -34,7 +34,8 @@ public class UserAccountsOrdering {
|
|||
|
||||
public enum Field {
|
||||
EMAIL("email"), FIRST_NAME("firstName"), LAST_NAME("lastName"), STATUS(
|
||||
"status"), ROLE("ps"), LOGIN_COUNT("count");
|
||||
"status"), ROLE("ps"), LOGIN_COUNT("count"), LAST_LOGIN_TIME(
|
||||
"lastLogin");
|
||||
|
||||
public static Field DEFAULT_FIELD = EMAIL;
|
||||
|
||||
|
|
|
@ -39,7 +39,8 @@ public class UserAccountsSelector {
|
|||
+ "PREFIX fn: <http://www.w3.org/2005/xpath-functions#> \n"
|
||||
+ "PREFIX auth: <http://vitro.mannlib.cornell.edu/ns/vitro/authorization#> \n";
|
||||
|
||||
private static final String ALL_VARIABLES = "?uri ?email ?firstName ?lastName ?pwd ?expire ?count ?status ?isRoot";
|
||||
private static final String ALL_VARIABLES = "?uri ?email ?firstName "
|
||||
+ "?lastName ?pwd ?expire ?count ?lastLogin ?status ?isRoot";
|
||||
|
||||
private static final String COUNT_VARIABLE = "?uri";
|
||||
|
||||
|
@ -169,6 +170,7 @@ public class UserAccountsSelector {
|
|||
+ " OPTIONAL { ?uri auth:md5password ?pwd } \n"
|
||||
+ " OPTIONAL { ?uri auth:passwordChangeExpires ?expire } \n"
|
||||
+ " OPTIONAL { ?uri auth:loginCount ?count } \n"
|
||||
+ " OPTIONAL { ?uri auth:lastLoginTime ?lastLogin } \n"
|
||||
+ " OPTIONAL { ?uri auth:status ?status } \n"
|
||||
+ " OPTIONAL { ?uri ?isRoot auth:RootUserAccount }";
|
||||
}
|
||||
|
@ -326,6 +328,7 @@ public class UserAccountsSelector {
|
|||
user.setMd5Password(ifLiteralPresent(solution, "pwd", ""));
|
||||
user.setPasswordLinkExpires(ifLongPresent(solution, "expire", 0L));
|
||||
user.setLoginCount(ifIntPresent(solution, "count", 0));
|
||||
user.setLastLoginTime(ifLongPresent(solution, "lastLogin", 0));
|
||||
user.setStatus(parseStatus(solution, "status", null));
|
||||
user.setRootUser(solution.contains("isRoot"));
|
||||
return user;
|
||||
|
|
|
@ -141,6 +141,7 @@ public class UserAccountsAddPage extends UserAccountsPage {
|
|||
u.setPasswordChangeRequired(false);
|
||||
u.setPasswordLinkExpires(0);
|
||||
u.setLoginCount(0);
|
||||
u.setLastLoginTime(0L);
|
||||
u.setStatus(Status.INACTIVE);
|
||||
u.setPermissionSetUris(Collections.singleton(selectedRoleUri));
|
||||
|
||||
|
|
|
@ -7,6 +7,7 @@ import static edu.cornell.mannlib.vitro.webapp.controller.accounts.UserAccountsS
|
|||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
@ -34,9 +35,6 @@ import edu.cornell.mannlib.vitro.webapp.controller.freemarker.responsevalues.Tem
|
|||
/**
|
||||
* Handle the List page.
|
||||
*
|
||||
* TODO: agree with Manolo how to do the column heads as links that change the
|
||||
* sort order
|
||||
*
|
||||
* TODO: auto-complete
|
||||
*/
|
||||
public class UserAccountsListPage extends UserAccountsPage {
|
||||
|
@ -242,6 +240,15 @@ public class UserAccountsListPage extends UserAccountsPage {
|
|||
return account.getLoginCount();
|
||||
}
|
||||
|
||||
public Date getLastLoginTime() {
|
||||
long time = account.getLastLoginTime();
|
||||
if (time > 0L) {
|
||||
return new Date(time);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public String getStatus() {
|
||||
Status status = account.getStatus();
|
||||
if (status == null) {
|
||||
|
@ -299,7 +306,7 @@ public class UserAccountsListPage extends UserAccountsPage {
|
|||
HttpSession session = req.getSession();
|
||||
Object o = session.getAttribute(ATTRIBUTE);
|
||||
session.removeAttribute(ATTRIBUTE);
|
||||
|
||||
|
||||
if (o instanceof Message) {
|
||||
((Message) o).applyToBodyMap(body);
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
package edu.cornell.mannlib.vitro.webapp.controller.authenticate;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
@ -137,6 +138,7 @@ public class BasicAuthenticator extends Authenticator {
|
|||
*/
|
||||
private void recordLoginOnUserRecord(UserAccount userAccount) {
|
||||
userAccount.setLoginCount(userAccount.getLoginCount() + 1);
|
||||
userAccount.setLastLoginTime(new Date().getTime());
|
||||
getUserAccountsDao().updateUserAccount(userAccount);
|
||||
}
|
||||
|
||||
|
|
|
@ -157,6 +157,7 @@ public class VitroVocabulary {
|
|||
public static final String USERACCOUNT_MD5_PASSWORD = VITRO_AUTH + "md5password";
|
||||
public static final String USERACCOUNT_OLD_PASSWORD = VITRO_AUTH + "oldpassword";
|
||||
public static final String USERACCOUNT_LOGIN_COUNT = VITRO_AUTH + "loginCount";
|
||||
public static final String USERACCOUNT_LAST_LOGIN_TIME = VITRO_AUTH + "lastLoginTime";
|
||||
public static final String USERACCOUNT_STATUS = VITRO_AUTH + "status";
|
||||
public static final String USERACCOUNT_PASSWORD_LINK_EXPIRES = VITRO_AUTH + "passwordLinkExpires";
|
||||
public static final String USERACCOUNT_PASSWORD_CHANGE_REQUIRED = VITRO_AUTH + "passwordChangeRequired";
|
||||
|
|
|
@ -127,6 +127,7 @@ public class JenaBaseDaoCon {
|
|||
protected DatatypeProperty USERACCOUNT_MD5_PASSWORD = _constModel.createDatatypeProperty(VitroVocabulary.USERACCOUNT_MD5_PASSWORD);
|
||||
protected DatatypeProperty USERACCOUNT_OLD_PASSWORD = _constModel.createDatatypeProperty(VitroVocabulary.USERACCOUNT_OLD_PASSWORD);
|
||||
protected DatatypeProperty USERACCOUNT_LOGIN_COUNT = _constModel.createDatatypeProperty(VitroVocabulary.USERACCOUNT_LOGIN_COUNT);
|
||||
protected DatatypeProperty USERACCOUNT_LAST_LOGIN_TIME = _constModel.createDatatypeProperty(VitroVocabulary.USERACCOUNT_LAST_LOGIN_TIME);
|
||||
protected DatatypeProperty USERACCOUNT_STATUS = _constModel.createDatatypeProperty(VitroVocabulary.USERACCOUNT_STATUS);
|
||||
protected DatatypeProperty USERACCOUNT_PASSWORD_LINK_EXPIRES = _constModel.createDatatypeProperty(VitroVocabulary.USERACCOUNT_PASSWORD_LINK_EXPIRES);
|
||||
protected DatatypeProperty USERACCOUNT_PASSWORD_CHANGE_REQUIRED = _constModel.createDatatypeProperty(VitroVocabulary.USERACCOUNT_PASSWORD_CHANGE_REQUIRED);
|
||||
|
|
|
@ -98,6 +98,7 @@ public class UserAccountsDaoJena extends JenaBaseDao implements UserAccountsDao
|
|||
u.setPasswordChangeRequired(getPropertyBooleanValue(r,
|
||||
USERACCOUNT_PASSWORD_CHANGE_REQUIRED));
|
||||
u.setLoginCount(getPropertyIntValue(r, USERACCOUNT_LOGIN_COUNT));
|
||||
u.setLastLoginTime(getPropertyLongValue(r, USERACCOUNT_LAST_LOGIN_TIME));
|
||||
u.setStatusFromString(getPropertyStringValue(r, USERACCOUNT_STATUS));
|
||||
u.setExternalAuthId(getPropertyStringValue(r,
|
||||
USERACCOUNT_EXTERNAL_AUTH_ID));
|
||||
|
@ -190,6 +191,8 @@ public class UserAccountsDaoJena extends JenaBaseDao implements UserAccountsDao
|
|||
userAccount.isPasswordChangeRequired(), model);
|
||||
addPropertyIntValue(res, USERACCOUNT_LOGIN_COUNT,
|
||||
userAccount.getLoginCount(), model);
|
||||
addPropertyLongValue(res, USERACCOUNT_LAST_LOGIN_TIME,
|
||||
userAccount.getLastLoginTime(), model);
|
||||
if (userAccount.getStatus() != null) {
|
||||
addPropertyStringValue(res, USERACCOUNT_STATUS, userAccount
|
||||
.getStatus().toString(), model);
|
||||
|
@ -247,6 +250,8 @@ public class UserAccountsDaoJena extends JenaBaseDao implements UserAccountsDao
|
|||
userAccount.isPasswordChangeRequired(), model, true);
|
||||
updatePropertyIntValue(res, USERACCOUNT_LOGIN_COUNT,
|
||||
userAccount.getLoginCount(), model);
|
||||
updatePropertyLongValue(res, USERACCOUNT_LAST_LOGIN_TIME,
|
||||
userAccount.getLastLoginTime(), model);
|
||||
if (userAccount.getStatus() == null) {
|
||||
updatePropertyStringValue(res, USERACCOUNT_STATUS, null, model);
|
||||
} else {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue