Proof of concept - User accounts
This commit is contained in:
parent
bf2ed5c339
commit
8f1f084c5b
45 changed files with 826 additions and 610 deletions
|
@ -25,6 +25,8 @@ import edu.cornell.mannlib.vitro.webapp.dao.VClassDao;
|
|||
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.jena.ModelContext;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.jena.OntModelSelector;
|
||||
import edu.cornell.mannlib.vitro.webapp.i18n.I18n;
|
||||
import edu.cornell.mannlib.vitro.webapp.i18n.I18nBundle;
|
||||
|
||||
/**
|
||||
* A base class with some utility routines for page handler (created by
|
||||
|
@ -39,6 +41,7 @@ public abstract class AbstractPageHandler {
|
|||
private static final Log log = LogFactory.getLog(AbstractPageHandler.class);
|
||||
|
||||
protected final VitroRequest vreq;
|
||||
protected final I18nBundle i18n;
|
||||
protected final ServletContext ctx;
|
||||
protected final OntModel userAccountsModel;
|
||||
protected final OntModel unionModel;
|
||||
|
@ -50,6 +53,7 @@ public abstract class AbstractPageHandler {
|
|||
|
||||
protected AbstractPageHandler(VitroRequest vreq) {
|
||||
this.vreq = vreq;
|
||||
this.i18n = I18n.bundle(vreq);
|
||||
this.ctx = vreq.getSession().getServletContext();
|
||||
|
||||
OntModelSelector oms = ModelContext.getUnionOntModelSelector(ctx);
|
||||
|
@ -154,7 +158,8 @@ public abstract class AbstractPageHandler {
|
|||
private static final String ATTRIBUTE = Message.class.getName();
|
||||
|
||||
public static void setMessage(HttpServletRequest req, Message message) {
|
||||
log.debug("Added message to session: " + message.getMessageInfoMap());
|
||||
log.debug("Added message to session: "
|
||||
+ message.getMessageInfoMap());
|
||||
req.getSession().setAttribute(ATTRIBUTE, message);
|
||||
}
|
||||
|
||||
|
|
|
@ -103,7 +103,7 @@ public abstract class UserAccountsAddPageStrategy extends UserAccountsPage {
|
|||
FreemarkerEmailMessage email = FreemarkerEmailFactory
|
||||
.createNewMessage(vreq);
|
||||
email.addRecipient(TO, page.getAddedAccount().getEmailAddress());
|
||||
email.setSubject("Your VIVO account has been created.");
|
||||
email.setSubject(i18n.text("account_created_subject", getSiteName()));
|
||||
if (page.isExternalAuthOnly()) {
|
||||
email.setTemplate(EMAIL_TEMPLATE_NO_PASSWORD);
|
||||
} else {
|
||||
|
|
|
@ -2,6 +2,8 @@
|
|||
|
||||
package edu.cornell.mannlib.vitro.webapp.controller.accounts.admin;
|
||||
|
||||
import static edu.cornell.mannlib.vitro.webapp.controller.accounts.user.UserAccountsUserController.getBogusStandardMessage;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
@ -15,7 +17,6 @@ import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.usepages.ManageRoot
|
|||
import edu.cornell.mannlib.vitro.webapp.beans.UserAccount;
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.accounts.UserAccountsPage;
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.accounts.user.UserAccountsUserController;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
|
||||
|
||||
/**
|
||||
|
@ -51,7 +52,7 @@ public class UserAccountsDeleter extends UserAccountsPage {
|
|||
UserAccount loggedInAccount = LoginStatusBean.getCurrentUser(vreq);
|
||||
if (loggedInAccount == null) {
|
||||
log.warn("Trying to delete accounts while not logged in!");
|
||||
bogusMessage = UserAccountsUserController.BOGUS_STANDARD_MESSAGE;
|
||||
bogusMessage = getBogusStandardMessage(vreq);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -61,14 +62,14 @@ public class UserAccountsDeleter extends UserAccountsPage {
|
|||
if (u == null) {
|
||||
log.warn("Delete account for '" + uri
|
||||
+ "' is bogus: no such user");
|
||||
bogusMessage = UserAccountsUserController.BOGUS_STANDARD_MESSAGE;
|
||||
bogusMessage = getBogusStandardMessage(vreq);
|
||||
return;
|
||||
}
|
||||
|
||||
if (u.getUri().equals(loggedInAccount.getUri())) {
|
||||
log.warn("'" + u.getUri()
|
||||
+ "' is trying to delete his own account.");
|
||||
bogusMessage = UserAccountsUserController.BOGUS_STANDARD_MESSAGE;
|
||||
bogusMessage = getBogusStandardMessage(vreq);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -78,7 +79,7 @@ public class UserAccountsDeleter extends UserAccountsPage {
|
|||
log.warn("Attempting to delete the root account, "
|
||||
+ "but not authorized. Logged in as "
|
||||
+ LoginStatusBean.getCurrentUser(vreq));
|
||||
bogusMessage = UserAccountsUserController.BOGUS_STANDARD_MESSAGE;
|
||||
bogusMessage = getBogusStandardMessage(vreq);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,6 +2,8 @@
|
|||
|
||||
package edu.cornell.mannlib.vitro.webapp.controller.accounts.admin;
|
||||
|
||||
import static edu.cornell.mannlib.vitro.webapp.controller.accounts.user.UserAccountsUserController.getBogusStandardMessage;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
|
@ -20,7 +22,6 @@ import edu.cornell.mannlib.vitro.webapp.beans.SelfEditingConfiguration;
|
|||
import edu.cornell.mannlib.vitro.webapp.beans.UserAccount;
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.accounts.UserAccountsPage;
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.accounts.user.UserAccountsUserController;
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.authenticate.Authenticator;
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.responsevalues.ResponseValues;
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.responsevalues.TemplateResponseValues;
|
||||
|
@ -116,7 +117,7 @@ public class UserAccountsEditPage extends UserAccountsPage {
|
|||
if (userAccount == null) {
|
||||
log.warn("Edit account for '" + userUri
|
||||
+ "' is bogus: no such user");
|
||||
bogusMessage = UserAccountsUserController.BOGUS_STANDARD_MESSAGE;
|
||||
bogusMessage = getBogusStandardMessage(vreq);
|
||||
return;
|
||||
}
|
||||
if (userAccount.isRootUser()) {
|
||||
|
@ -125,7 +126,7 @@ public class UserAccountsEditPage extends UserAccountsPage {
|
|||
log.warn("User is attempting to edit the root account, "
|
||||
+ "but is not authorized to do so. Logged in as: "
|
||||
+ LoginStatusBean.getCurrentUser(vreq));
|
||||
bogusMessage = UserAccountsUserController.BOGUS_STANDARD_MESSAGE;
|
||||
bogusMessage = getBogusStandardMessage(vreq);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -46,14 +46,12 @@ public class UserAccountsCreatePasswordPage extends
|
|||
|
||||
@Override
|
||||
protected String alreadyLoggedInMessage(String currentUserEmail) {
|
||||
return "You may not activate the account for " + userEmail
|
||||
+ " while you are logged in as " + currentUserEmail
|
||||
+ ". Please log out and try again.";
|
||||
return i18n.text("cant_activate_while_logged_in", userEmail, currentUserEmail);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String passwordChangeNotPendingMessage() {
|
||||
return "The account for " + userEmail + " has already been activated.";
|
||||
return i18n.text("account_already_activated", userEmail);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -69,7 +67,7 @@ public class UserAccountsCreatePasswordPage extends
|
|||
FreemarkerEmailMessage email = FreemarkerEmailFactory
|
||||
.createNewMessage(vreq);
|
||||
email.addRecipient(TO, userAccount.getEmailAddress());
|
||||
email.setSubject("Password successfully created.");
|
||||
email.setSubject(i18n.text("password_created_subject", getSiteName()));
|
||||
email.setTemplate(EMAIL_TEMPLATE);
|
||||
email.setBodyMap(body);
|
||||
email.processTemplate();
|
||||
|
|
|
@ -115,18 +115,17 @@ public class UserAccountsFirstTimeExternalPage extends UserAccountsPage {
|
|||
|
||||
private void validateExternalAuthId() {
|
||||
if (externalAuthId.isEmpty()) {
|
||||
bogusMessage = "Login failed - External ID is not found.";
|
||||
bogusMessage = i18n.text("external_id_not_provided");
|
||||
return;
|
||||
}
|
||||
if (null != userAccountsDao
|
||||
.getUserAccountByExternalAuthId(externalAuthId)) {
|
||||
bogusMessage = "User account already exists for '" + externalAuthId
|
||||
+ "'";
|
||||
bogusMessage = i18n.text("external_id_already_in_use",
|
||||
externalAuthId);
|
||||
return;
|
||||
}
|
||||
if (!Authenticator.getInstance(vreq).isUserPermittedToLogin(null)) {
|
||||
bogusMessage = "User logins are temporarily disabled "
|
||||
+ "while the system is being maintained.";
|
||||
bogusMessage = i18n.text("logins_disabled_for_maintenance");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -73,7 +73,7 @@ public abstract class UserAccountsFirstTimeExternalPageStrategy extends
|
|||
FreemarkerEmailMessage email = FreemarkerEmailFactory
|
||||
.createNewMessage(vreq);
|
||||
email.addRecipient(TO, ua.getEmailAddress());
|
||||
email.setSubject("Your VIVO account has been created.");
|
||||
email.setSubject(i18n.text("account_created_subject", getSiteName()));
|
||||
email.setTemplate(EMAIL_TEMPLATE);
|
||||
email.setBodyMap(body);
|
||||
email.processTemplate();
|
||||
|
|
|
@ -178,7 +178,7 @@ public abstract class UserAccountsMyAccountPageStrategy extends
|
|||
FreemarkerEmailMessage email = FreemarkerEmailFactory
|
||||
.createNewMessage(vreq);
|
||||
email.addRecipient(TO, page.getUserAccount().getEmailAddress());
|
||||
email.setSubject("Your VIVO email account has been changed.");
|
||||
email.setSubject(i18n.text("email_changed_subject"));
|
||||
email.setTemplate(EMAIL_TEMPLATE);
|
||||
email.setBodyMap(body);
|
||||
email.processTemplate();
|
||||
|
|
|
@ -23,8 +23,6 @@ public abstract class UserAccountsPasswordBasePage extends UserAccountsPage {
|
|||
private static final Log log = LogFactory
|
||||
.getLog(UserAccountsPasswordBasePage.class);
|
||||
|
||||
public static final String BOGUS_MESSAGE_NO_SUCH_ACCOUNT = "The account you are trying to set a password on is no longer available. Please contact your system administrator if you think this is an error.";
|
||||
|
||||
private static final String PARAMETER_SUBMIT = "submit";
|
||||
private static final String PARAMETER_USER = "user";
|
||||
private static final String PARAMETER_KEY = "key";
|
||||
|
@ -79,7 +77,7 @@ public abstract class UserAccountsPasswordBasePage extends UserAccountsPage {
|
|||
if (userAccount == null) {
|
||||
log.warn("Password request for '" + userEmail
|
||||
+ "' is bogus: no such user");
|
||||
bogusMessage = BOGUS_MESSAGE_NO_SUCH_ACCOUNT;
|
||||
bogusMessage = i18n.text("account_no_longer_exists");
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -170,9 +168,9 @@ public abstract class UserAccountsPasswordBasePage extends UserAccountsPage {
|
|||
|
||||
public String getSuccessMessage() {
|
||||
if (loggedIn) {
|
||||
return "Your password has been saved.";
|
||||
return i18n.text("password_saved");
|
||||
} else {
|
||||
return "Your password has been saved. Please log in.";
|
||||
return i18n.text("password_saved_please_login");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -46,14 +46,13 @@ public class UserAccountsResetPasswordPage extends UserAccountsPasswordBasePage
|
|||
|
||||
@Override
|
||||
protected String alreadyLoggedInMessage(String currentUserEmail) {
|
||||
return "You may not reset the password for " + userEmail
|
||||
+ " while you are logged in as " + currentUserEmail
|
||||
+ ". Please log out and try again.";
|
||||
return i18n.text("cant_change_password_while_logged_in", userEmail,
|
||||
currentUserEmail);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String passwordChangeNotPendingMessage() {
|
||||
return "The password for " + userEmail + " has already been reset.";
|
||||
return i18n.text("password_change_not_pending", userEmail);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -69,7 +68,7 @@ public class UserAccountsResetPasswordPage extends UserAccountsPasswordBasePage
|
|||
FreemarkerEmailMessage email = FreemarkerEmailFactory
|
||||
.createNewMessage(vreq);
|
||||
email.addRecipient(TO, userAccount.getEmailAddress());
|
||||
email.setSubject("Password changed.");
|
||||
email.setSubject(i18n.text("password_changed_subject"));
|
||||
email.setTemplate(EMAIL_TEMPLATE);
|
||||
email.setBodyMap(body);
|
||||
email.processTemplate();
|
||||
|
|
|
@ -4,6 +4,8 @@ package edu.cornell.mannlib.vitro.webapp.controller.accounts.user;
|
|||
|
||||
import static edu.cornell.mannlib.vedit.beans.LoginStatusBean.AuthenticationSource.EXTERNAL;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
|
@ -18,6 +20,7 @@ import edu.cornell.mannlib.vitro.webapp.controller.authenticate.LoginRedirector;
|
|||
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.FreemarkerHttpServlet;
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.responsevalues.RedirectResponseValues;
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.responsevalues.ResponseValues;
|
||||
import edu.cornell.mannlib.vitro.webapp.i18n.I18n;
|
||||
|
||||
/**
|
||||
* Parcel out the different actions required of the UserAccounts GUI.
|
||||
|
@ -26,8 +29,6 @@ public class UserAccountsUserController extends FreemarkerHttpServlet {
|
|||
private static final Log log = LogFactory
|
||||
.getLog(UserAccountsUserController.class);
|
||||
|
||||
public static final String BOGUS_STANDARD_MESSAGE = "Request failed. Please contact your system administrator.";
|
||||
|
||||
private static final String ACTION_CREATE_PASSWORD = "/createPassword";
|
||||
private static final String ACTION_RESET_PASSWORD = "/resetPassword";
|
||||
private static final String ACTION_MY_ACCOUNT = "/myAccount";
|
||||
|
@ -116,7 +117,7 @@ public class UserAccountsUserController extends FreemarkerHttpServlet {
|
|||
return showLoginRedirection(vreq, page.getAfterLoginUrl());
|
||||
} catch (LoginNotPermitted e) {
|
||||
// This should have been anticipated by the page.
|
||||
return showHomePage(vreq, BOGUS_STANDARD_MESSAGE);
|
||||
return showHomePage(vreq, getBogusStandardMessage(vreq));
|
||||
}
|
||||
} else {
|
||||
return page.showPage();
|
||||
|
@ -124,7 +125,7 @@ public class UserAccountsUserController extends FreemarkerHttpServlet {
|
|||
}
|
||||
|
||||
private ResponseValues handleInvalidRequest(VitroRequest vreq) {
|
||||
return showHomePage(vreq, BOGUS_STANDARD_MESSAGE);
|
||||
return showHomePage(vreq, getBogusStandardMessage(vreq));
|
||||
}
|
||||
|
||||
private ResponseValues showHomePage(VitroRequest vreq, String message) {
|
||||
|
@ -159,4 +160,8 @@ public class UserAccountsUserController extends FreemarkerHttpServlet {
|
|||
}
|
||||
return uri;
|
||||
}
|
||||
|
||||
public static String getBogusStandardMessage(HttpServletRequest req) {
|
||||
return I18n.bundle(req).text("request_failed");
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue