Remove icon definitions and error message markup from login controller and handle in templates instead.

This commit is contained in:
rjy7 2010-08-30 19:58:12 +00:00
parent 2c6ddaab64
commit 79da8d30ed
2 changed files with 15 additions and 17 deletions

View file

@ -40,10 +40,8 @@ public class FreemarkerSiteAdminController extends FreemarkerHttpServlet {
// Not logged in: just show login form // Not logged in: just show login form
if (loginHandler == null || !"authenticated".equals(loginStatus)) { if (loginHandler == null || !"authenticated".equals(loginStatus)) {
//return new LoginTemplateHelper(vreq).showLoginPage(vreq, body, config);
body.put("loginPanel", new LoginTemplateHelper(vreq).showLoginPage(vreq, body, config)); body.put("loginPanel", new LoginTemplateHelper(vreq).showLoginPage(vreq, body, config));
return mergeBodyToTemplate("siteAdmin-main.ftl", body, config); return mergeBodyToTemplate("siteAdmin-main.ftl", body, config);
} }
int securityLevel = Integer.parseInt( loginHandler.getLoginRole() ); int securityLevel = Integer.parseInt( loginHandler.getLoginRole() );

View file

@ -37,20 +37,16 @@ public class LoginTemplateHelper extends LoginTemplateHelperBase {
/** If they are changing their password on first login, show them this form. */ /** If they are changing their password on first login, show them this form. */
public static final String TEMPLATE_FORCE_PASSWORD_CHANGE = "login-forcedPasswordChange.ftl"; public static final String TEMPLATE_FORCE_PASSWORD_CHANGE = "login-forcedPasswordChange.ftl";
/** Show error message */
public static final String TEMPLATE_SERVER_ERROR = "errorMessage.ftl";
public static final String BODY_LOGIN_NAME = "loginName"; public static final String BODY_LOGIN_NAME = "loginName";
public static final String BODY_FORM_ACTION = "formAction"; public static final String BODY_FORM_ACTION = "formAction";
public static final String BODY_INFO_MESSAGE = "infoMessage"; public static final String BODY_INFO_MESSAGE = "infoMessage";
public static final String BODY_ERROR_MESSAGE = "errorMessage"; public static final String BODY_ERROR_MESSAGE = "errorMessage";
public static final String BODY_ALERT_ICON_URL = "alertImageUrl";
public static final String BODY_CANCEL_URL = "cancelUrl"; public static final String BODY_CANCEL_URL = "cancelUrl";
/** Use this icon for an info message. */
public static final String URL_INFO_ICON = "/images/iconAlert.png";
/** Use this icon for an error message. */
public static final String URL_ERROR_ICON = "/images/iconAlert.png";
/** If no portal is specified in the request, use this one. */ /** If no portal is specified in the request, use this one. */
private static final int DEFAULT_PORTAL_ID = 1; private static final int DEFAULT_PORTAL_ID = 1;
@ -60,9 +56,9 @@ public class LoginTemplateHelper extends LoginTemplateHelperBase {
/** Version for JSP page */ /** Version for JSP page */
public String showLoginPage(HttpServletRequest request) { public String showLoginPage(HttpServletRequest request) {
VitroRequest vreq = new VitroRequest(request);
try { try {
VitroRequest vreq = new VitroRequest(request);
State state = getCurrentLoginState(vreq); State state = getCurrentLoginState(vreq);
log.debug("State on exit: " + state); log.debug("State on exit: " + state);
@ -76,7 +72,7 @@ public class LoginTemplateHelper extends LoginTemplateHelperBase {
} }
} catch (Exception e) { } catch (Exception e) {
log.error(e); log.error(e);
return "<h2>Internal server error:<br/>" + e + "</h2>"; return doTemplate(vreq, showError(request, e));
} }
} }
@ -97,7 +93,7 @@ public class LoginTemplateHelper extends LoginTemplateHelperBase {
} }
} catch (Exception e) { } catch (Exception e) {
log.error(e); log.error(e);
return "<h2>Internal server error:<br/>" + e + "</h2>"; return doTemplate(vreq, showError(vreq, e), body, config);
} }
} }
@ -120,12 +116,10 @@ public class LoginTemplateHelper extends LoginTemplateHelperBase {
String infoMessage = bean.getInfoMessage(); String infoMessage = bean.getInfoMessage();
if (!infoMessage.isEmpty()) { if (!infoMessage.isEmpty()) {
trv.put(BODY_INFO_MESSAGE, infoMessage); trv.put(BODY_INFO_MESSAGE, infoMessage);
trv.put(BODY_ALERT_ICON_URL, UrlBuilder.getUrl(URL_INFO_ICON));
} }
String errorMessage = bean.getErrorMessage(); String errorMessage = bean.getErrorMessage();
if (!errorMessage.isEmpty()) { if (!errorMessage.isEmpty()) {
trv.put(BODY_ERROR_MESSAGE, errorMessage); trv.put(BODY_ERROR_MESSAGE, errorMessage);
trv.put(BODY_ALERT_ICON_URL, UrlBuilder.getUrl(URL_ERROR_ICON));
} }
return trv; return trv;
} }
@ -147,10 +141,16 @@ public class LoginTemplateHelper extends LoginTemplateHelperBase {
String errorMessage = bean.getErrorMessage(); String errorMessage = bean.getErrorMessage();
if (!errorMessage.isEmpty()) { if (!errorMessage.isEmpty()) {
trv.put(BODY_ERROR_MESSAGE, errorMessage); trv.put(BODY_ERROR_MESSAGE, errorMessage);
trv.put(BODY_ALERT_ICON_URL, UrlBuilder.getUrl(URL_ERROR_ICON));
} }
return trv; return trv;
} }
private TemplateResponseValues showError(HttpServletRequest request, Exception e) {
TemplateResponseValues trv = new TemplateResponseValues(
TEMPLATE_SERVER_ERROR);
trv.put(BODY_ERROR_MESSAGE, "Internal server error:<br /> " + e);
return trv;
}
/** /**
* We processed a response, and want to show a template. * We processed a response, and want to show a template.