📄 cmslogin.java
字号:
html.append(".");
html.append(PARAM_USERNAME);
html.append(".select();\n");
html.append("\tdocument.");
html.append(PARAM_FORM);
html.append(".");
html.append(PARAM_USERNAME);
html.append(".focus();\n");
if (message != null) {
html.append("\tshowAlert();\n");
}
html.append("}\n");
html.append("</script>\n");
}
/**
* Appends the JavaScript that opens the Workplace window after a successful login
* to the given HTML buffer.<p>
*
* @param html the html buffer to append the script to
* @param requestedResource the requested resource to open in a new window
* @param message the message to display if the originally requested resource is not available
*/
protected void appendWorkplaceOpenerScript(StringBuffer html, String requestedResource, CmsMessageContainer message) {
String winId = "OpenCms" + System.currentTimeMillis();
html.append("<script type=\"text/javascript\">\n");
html.append("function doOnload() {\n");
// display missing resource warning if required
if (message != null) {
html.append("\talert(\"");
html.append(CmsStringUtil.escapeJavaScript(message.key(m_locale)));
html.append("\");\n");
}
// display login message if required
CmsLoginMessage loginMessage = OpenCms.getLoginManager().getLoginMessage();
if ((loginMessage != null) && (loginMessage.isActive())) {
String msg;
if (loginMessage.isLoginForbidden()) {
// login forbidden for normal users, current user must be Administrator
msg = Messages.get().container(
Messages.GUI_LOGIN_SUCCESS_WITH_MESSAGE_2,
loginMessage.getMessage(),
new Date(loginMessage.getTimeEnd())).key(m_locale);
} else {
// just display the message
msg = loginMessage.getMessage();
}
html.append("\talert(\"");
html.append(CmsStringUtil.escapeJavaScript(msg));
html.append("\");\n");
}
html.append("\tvar openUri = \"");
html.append(link(requestedResource));
html.append("\";\n");
html.append("\tvar workplaceWin = openWorkplace(openUri, \"");
html.append(winId);
html.append("\");\n");
html.append("\tif (window.name != \"");
html.append(winId);
html.append("\") {\n");
html.append("\t\twindow.opener = workplaceWin;\n");
html.append("\t\tif (workplaceWin != null) {\n");
html.append("\t\t\twindow.close();\n");
html.append("\t\t}\n");
html.append("\t}\n");
html.append("}\n");
html.append("function openWorkplace(url, name) {\n");
html.append("\tvar isInWin = (window.name.match(/^OpenCms\\d+$/) != null);\n");
html.append("\tif (window.innerHeight) {\n");
// Mozilla
html.append("\t\tvar winHeight = window.innerHeight;\n");
html.append("\t\tvar winWidth = window.innerWidth;\n");
html.append("\t} else if (document.documentElement && document.documentElement.clientHeight) {\n");
// IE 6 "strict" mode
html.append("\t\tvar winHeight = document.documentElement.clientHeight;\n");
html.append("\t\tvar winWidth = document.documentElement.clientWidth;\n");
html.append("\t} else if (document.body && document.body.clientHeight) {\n");
// IE 5, IE 6 "relaxed" mode
html.append("\t\tvar winHeight = document.body.clientWidth;\n");
html.append("\t\tvar winWidth = document.body.clientHeight;\n");
html.append("\t}\n");
html.append("\tif (window.screenY) {\n");
// Mozilla
html.append("\t\tvar winTop = window.screenY;\n");
html.append("\t\tvar winLeft = window.screenX;\n");
html.append("\t\tif (! isInWin) {\n");
html.append("\t\t\twinTop += 25;\n");
html.append("\t\t\twinLeft += 25;\n");
html.append("\t\t}\n");
html.append("\t} else if (window.screenTop) {\n");
// IE
html.append("\t\tvar winTop = window.screenTop;\n");
html.append("\t\tvar winLeft = window.screenLeft;\n");
html.append("\t}\n");
html.append("\n");
if (requestedResource.startsWith(CmsWorkplace.VFS_PATH_WORKPLACE)) {
html.append("\tvar openerStr = \"width=\" + winWidth + \",height=\" + winHeight + \",left=\" + winLeft + \",top=\" + winTop + \",scrollbars=no,location=no,toolbar=no,menubar=no,directories=no,status=yes,resizable=yes\";\n");
} else {
html.append("\tvar openerStr = \"width=\" + winWidth + \",height=\" + winHeight + \",left=\" + winLeft + \",top=\" + winTop + \",scrollbars=yes,location=yes,toolbar=yes,menubar=yes,directories=no,status=yes,resizable=yes\";\n");
}
html.append("\tvar OpenCmsWin = window.open(url, name, openerStr);\n");
html.append("\n");
html.append("\ttry{\n");
html.append("\t\tif (! OpenCmsWin.opener) {\n");
html.append("\t\t\tOpenCmsWin.opener = self;\n");
html.append("\t\t}\n");
html.append("\t\tif (OpenCmsWin.focus) {\n");
html.append("\t\t\tOpenCmsWin.focus();\n");
html.append("\t\t}\n");
html.append("\t} catch (e) {}\n");
html.append("\n");
html.append("\treturn OpenCmsWin;\n");
html.append("}\n");
html.append("</script>\n");
}
/**
* Returns the HTML for the login form.<p>
*
* @return the HTML for the login form
*/
protected String displayLoginForm() {
StringBuffer html = new StringBuffer();
html.append("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\">\n");
html.append("<html><head>\n");
html.append("<title>");
html.append(Messages.get().getBundle(m_locale).key(Messages.GUI_LOGIN_TITLE_0));
html.append("OpenCms " + OpenCms.getSystemInfo().getVersionName());
html.append("</title>\n");
String encoding = getRequestContext().getEncoding();
html.append("<meta HTTP-EQUIV=\"Content-Type\" CONTENT=\"text/html; charset=");
html.append(encoding);
html.append("\">\n");
html.append("<link rel=\"stylesheet\" type=\"text/css\" href=\"");
html.append(CmsWorkplace.getStyleUri(this, "workplace.css"));
html.append("\">\n");
if (m_action == ACTION_DISPLAY) {
// append default script
appendDefaultLoginScript(html, m_message);
} else if (m_action == ACTION_LOGIN) {
// append window opener script
appendWorkplaceOpenerScript(html, m_requestedResource, m_message);
}
html.append("</head>\n");
html.append("<body class=\"dialog\" onload=\"doOnload();\">\n");
html.append("<div style=\"text-align: center; padding-top: 50px;\">");
html.append("<img src=\"");
html.append(CmsWorkplace.getResourceUri("commons/login_logo.png"));
html.append("\" alt=\"OpenCms Logo\">");
html.append("</div>\n");
html.append("<table class=\"logindialog\" cellpadding=\"0\" cellspacing=\"0\"><tr><td>\n");
html.append("<table class=\"dialogbox\" cellpadding=\"0\" cellspacing=\"0\"><tr><td>\n");
html.append("<div class=\"dialoghead\">");
if (m_action == ACTION_DISPLAY) {
html.append(Messages.get().getBundle(m_locale).key(Messages.GUI_LOGIN_HEADLINE_0));
} else if (m_action == ACTION_LOGIN) {
html.append(Messages.get().getBundle(m_locale).key(Messages.GUI_LOGIN_HEADLINE_ALREADY_IN_0));
}
html.append("</div>\n");
if (m_action == ACTION_DISPLAY) {
// start form
html.append("<form style=\"margin: 0px; padding: 0px;\" action=\"");
html.append(getFormLink());
html.append("\"");
appendId(html, PARAM_FORM);
html.append("method=\"POST\">\n");
}
html.append("<div class=\"dialogcontent\">\n");
html.append("<table border=\"0\">\n");
html.append("<tr>\n");
html.append("<td></td>\n<td colspan=\"2\" style=\"white-space: nowrap;\">\n");
html.append("<div style=\"padding-bottom: 10px;\">");
if (m_action == ACTION_DISPLAY) {
html.append(CmsStringUtil.escapeHtml(Messages.get().getBundle(m_locale).key(Messages.GUI_LOGIN_MESSAGE_0)));
} else if (m_action == ACTION_LOGIN) {
html.append(CmsStringUtil.escapeHtml(Messages.get().getBundle(m_locale).key(
Messages.GUI_LOGIN_MESSAGE_ALREADY_IN_0)));
}
html.append("</div>\n");
html.append("</td>\n");
html.append("</tr>\n");
html.append("<tr>\n");
html.append("<td style=\"width: 60px; text-align: center; vertical-align: top\" rowspan=\"3\">");
html.append("<img src=\"");
html.append(CmsWorkplace.getResourceUri("commons/login.png"));
html.append("\" height=\"48\" width=\"48\" alt=\"\">");
html.append("</td>\n");
html.append("<td style=\"white-space: nowrap;\"><b>");
html.append(Messages.get().getBundle(m_locale).key(Messages.GUI_LOGIN_USERNAME_0));
html.append("</b> </td>\n");
html.append("<td style=\"width: 300px; white-space: nowrap;\">");
if (m_action == ACTION_DISPLAY) {
// append input for user name
html.append("<input style=\"width: 100%\" type=\"text\"");
appendId(html, PARAM_USERNAME);
html.append("value=\"");
html.append(CmsStringUtil.isEmpty(m_username) ? "" : CmsEncoder.escapeXml(m_username));
html.append("\">");
} else if (m_action == ACTION_LOGIN) {
// append name of user that has been logged in
html.append(getRequestContext().currentUser().getFullName());
}
html.append("</td>\n");
html.append("</tr>\n");
if (m_action == ACTION_DISPLAY) {
// append 2 rows: input for user name and login button
html.append("<tr>\n");
html.append("<td style=\"white-space: nowrap;\"><b>");
html.append(Messages.get().getBundle(m_locale).key(Messages.GUI_LOGIN_PASSWORD_0));
html.append("</b> </td>\n");
html.append("<td style=\"width: 300px; white-space: nowrap;\">");
html.append("<input style=\"width: 100%\" type=\"password\"");
appendId(html, PARAM_PASSWORD);
html.append(">");
html.append("</td>\n");
html.append("</tr>\n");
html.append("<tr>\n");
html.append("<td></td>\n<td style=\"white-space: nowrap;\">\n");
html.append("<input type=\"hidden\"");
appendId(html, PARAM_ACTION_LOGIN);
html.append("value=\"true\">\n");
if (m_requestedResource != null) {
html.append("<input type=\"hidden\"");
appendId(html, CmsWorkplaceManager.PARAM_LOGIN_REQUESTED_RESOURCE);
html.append("value=\"");
html.append(CmsEncoder.encode(m_requestedResource));
html.append("\">\n");
}
html.append("<input class=\"loginbutton\" type=\"submit\" value=\"");
html.append(Messages.get().getBundle(m_locale).key(Messages.GUI_LOGIN_BUTTON_0));
html.append("\">\n");
html.append("</td>\n");
html.append("</tr>\n");
} else if (m_action == ACTION_LOGIN) {
// append 2 rows: one empty, other for button with re-open window script
html.append("<tr><td></td><td></td></tr>\n");
html.append("<tr>\n");
html.append("<td></td>\n");
html.append("<td style=\"width:100%; white-space: nowrap;\">\n");
html.append("<input class=\"loginbutton\" type=\"button\" value=\"");
html.append(Messages.get().getBundle(m_locale).key(Messages.GUI_LOGIN_BUTTON_ALREADY_IN_0));
html.append("\" onclick=\"doOnload()\">\n");
html.append("</td>\n");
html.append("</tr>\n");
}
html.append("</table>\n");
html.append("</div>");
if (m_action == ACTION_DISPLAY) {
// end form
html.append("</form>\n");
}
html.append("</td></tr></table>\n");
html.append("</td></tr></table>\n");
html.append("<div style=\"text-align: center; font-size: 10px; white-space: nowrap;\">");
html.append("<a href=\"http://www.opencms.org\" target=\"_blank\">OpenCms</a> ");
html.append(Messages.get().getBundle(m_locale).key(Messages.GUI_LOGIN_OPENCMS_IS_FREE_SOFTWARE_0));
html.append("</div>\n");
html.append("<div style=\"text-align: center; font-size: 10px; white-space: nowrap;\">");
html.append(Messages.get().getBundle(m_locale).key(Messages.GUI_LOGIN_TRADEMARKS_0));
html.append("</div>\n");
html.append("<div style=\"text-align: center; font-size: 10px; white-space: nowrap;\">");
html.append("© 2006 Alkacon Software GmbH. ");
html.append(Messages.get().getBundle(m_locale).key(Messages.GUI_LOGIN_RIGHTS_RESERVED_0));
html.append("</div>\n");
html.append("<noscript>\n");
html.append("<div style=\"text-align: center; font-size: 14px; border: 2px solid black; margin: 50px; padding: 20px; background-color: red; color: white; white-space: nowrap;\"><b>");
html.append(CmsStringUtil.escapeHtml(Messages.get().getBundle(m_locale).key(
Messages.GUI_LOGIN_NOSCRIPT_1,
OpenCms.getSiteManager().getWorkplaceSiteMatcher())));
html.append("</b></div>\n");
html.append("</noscript>\n");
html.append("</body></html>");
return html.toString();
}
/**
* Appends the HTML form name/id code for the given id to the given html.<p>
*
* @param html the html where to append the id to
* @param id the id to append
*/
private void appendId(StringBuffer html, String id) {
html.append(" name=\"");
html.append(id);
html.append("\" id=\"");
html.append(id);
html.append("\" ");
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -