KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > opencms > workplace > CmsLogin


1 /*
2  * File : $Source: /usr/local/cvs/opencms/src/org/opencms/workplace/CmsLogin.java,v $
3  * Date : $Date: 2006/03/27 14:52:43 $
4  * Version: $Revision: 1.24 $
5  *
6  * This library is part of OpenCms -
7  * the Open Source Content Mananagement System
8  *
9  * Copyright (c) 2005 Alkacon Software GmbH (http://www.alkacon.com)
10  *
11  * This library is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU Lesser General Public
13  * License as published by the Free Software Foundation; either
14  * version 2.1 of the License, or (at your option) any later version.
15  *
16  * This library is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19  * Lesser General Public License for more details.
20  *
21  * For further information about Alkacon Software GmbH, please see the
22  * company website: http://www.alkacon.com
23  *
24  * For further information about OpenCms, please see the
25  * project website: http://www.opencms.org
26  *
27  * You should have received a copy of the GNU Lesser General Public
28  * License along with this library; if not, write to the Free Software
29  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30  */

31
32 package org.opencms.workplace;
33
34 import org.opencms.db.CmsLoginMessage;
35 import org.opencms.db.CmsUserSettings;
36 import org.opencms.file.CmsObject;
37 import org.opencms.file.CmsProject;
38 import org.opencms.file.CmsResourceFilter;
39 import org.opencms.i18n.CmsAcceptLanguageHeaderParser;
40 import org.opencms.i18n.CmsEncoder;
41 import org.opencms.i18n.CmsMessageContainer;
42 import org.opencms.jsp.CmsJspLoginBean;
43 import org.opencms.main.CmsLog;
44 import org.opencms.main.OpenCms;
45 import org.opencms.util.CmsRequestUtil;
46 import org.opencms.util.CmsStringUtil;
47 import org.opencms.util.CmsUriSplitter;
48
49 import java.io.IOException JavaDoc;
50 import java.util.Date JavaDoc;
51 import java.util.List JavaDoc;
52 import java.util.Locale JavaDoc;
53
54 import javax.servlet.http.HttpServletRequest JavaDoc;
55 import javax.servlet.http.HttpServletResponse JavaDoc;
56 import javax.servlet.http.HttpSession JavaDoc;
57 import javax.servlet.jsp.PageContext JavaDoc;
58
59 import org.apache.commons.logging.Log;
60
61 /**
62  * Handles the login of Users to the OpenCms workplace.<p>
63  *
64  * @author Alexander Kandzior
65  *
66  * @version $Revision: 1.24 $
67  *
68  * @since 6.0.0
69  */

70 public class CmsLogin extends CmsJspLoginBean {
71
72     /** Action constant: Default action, display the dialog. */
73     private static final int ACTION_DISPLAY = 0;
74
75     /** Action constant: Login sucessful. */
76     private static final int ACTION_LOGIN = 1;
77
78     /** Action constant: Logout. */
79     private static final int ACTION_LOGOUT = 2;
80
81     /** The log object for this class. */
82     private static final Log LOG = CmsLog.getLog(CmsLogin.class);
83
84     /** The parameter name for the "login" action. */
85     private static final String JavaDoc PARAM_ACTION_LOGIN = "login";
86
87     /** The parameter name for the "logout" action. */
88     private static final String JavaDoc PARAM_ACTION_LOGOUT = "logout";
89
90     /** The html id for the login form. */
91     private static final String JavaDoc PARAM_FORM = "ocLoginForm";
92
93     /** The parameter name for the password. */
94     private static final String JavaDoc PARAM_PASSWORD = "ocPword";
95
96     /** The parameter name for the user name. */
97     private static final String JavaDoc PARAM_USERNAME = "ocUname";
98
99     /** The action to perform. */
100     private int m_action;
101
102     /** The value of the "login" action parameter. */
103     private String JavaDoc m_actionLogin;
104
105     /** The value of the "logout" action parameter. */
106     private String JavaDoc m_actionLogout;
107
108     /** The locale to use for display, this will not be the workplace locale, but the browser locale. */
109     private Locale JavaDoc m_locale;
110
111     /** The message to display with the dialog in a JavaScrip alert. */
112     private CmsMessageContainer m_message;
113
114     /** The value of the password parameter. */
115     private String JavaDoc m_password;
116
117     /** The redirect URL after a successful login. */
118     private String JavaDoc m_requestedResource;
119
120     /** The value of the user name parameter. */
121     private String JavaDoc m_username;
122
123     /**
124      * Public constructor for login page.<p>
125      *
126      * @param context the JSP page context object
127      * @param req the JSP request
128      * @param res the JSP response
129      */

130     public CmsLogin(PageContext JavaDoc context, HttpServletRequest JavaDoc req, HttpServletResponse JavaDoc res) {
131
132         super(context, req, res);
133
134         // this page must never be cached
135
res.setDateHeader(CmsRequestUtil.HEADER_LAST_MODIFIED, System.currentTimeMillis());
136         CmsRequestUtil.setNoCacheHeaders(res);
137
138         // divine the best locale from the users browser settings
139
CmsAcceptLanguageHeaderParser parser = new CmsAcceptLanguageHeaderParser(
140             req,
141             OpenCms.getWorkplaceManager().getDefaultLocale());
142         List JavaDoc acceptedLocales = parser.getAcceptedLocales();
143         List JavaDoc workplaceLocales = OpenCms.getWorkplaceManager().getLocales();
144         m_locale = OpenCms.getLocaleManager().getFirstMatchingLocale(acceptedLocales, workplaceLocales);
145         if (m_locale == null) {
146             // no match found - use OpenCms default locale
147
m_locale = OpenCms.getWorkplaceManager().getDefaultLocale();
148         }
149     }
150
151     /**
152      * Returns the HTML for the login dialog in it's current state.<p>
153      *
154      * @return the HTML for the login dialog
155      *
156      * @throws IOException in case a redirect fails
157      */

158     public String JavaDoc displayDialog() throws IOException JavaDoc {
159
160         if ((OpenCms.getSiteManager().getSites().size() > 1)
161             && !OpenCms.getSiteManager().isWorkplaceRequest(getRequest())) {
162
163             // this is a multi site-configuration, but not a request to the configured Workplace site
164
StringBuffer JavaDoc loginLink = new StringBuffer JavaDoc();
165             loginLink.append(OpenCms.getSiteManager().getWorkplaceSiteMatcher().toString());
166             loginLink.append(getFormLink());
167             // send a redirect to the workplace site
168
getResponse().sendRedirect(loginLink.toString());
169             return null;
170         }
171
172         CmsObject cms = getCmsObject();
173
174         m_message = null;
175         if (cms.getRequestContext().currentUser().isGuestUser()) {
176
177             // user is not currently logged in
178
m_action = ACTION_DISPLAY;
179             m_username = CmsRequestUtil.getNotEmptyParameter(getRequest(), PARAM_USERNAME);
180             if (m_username != null) {
181                 // remove white spaces, can only lead to confusion on user name
182
m_username = m_username.trim();
183             }
184             m_password = CmsRequestUtil.getNotEmptyParameter(getRequest(), PARAM_PASSWORD);
185             m_actionLogin = CmsRequestUtil.getNotEmptyParameter(getRequest(), PARAM_ACTION_LOGIN);
186
187         } else {
188
189             // user is already logged in
190
m_action = ACTION_LOGIN;
191             m_actionLogout = CmsRequestUtil.getNotEmptyParameter(getRequest(), PARAM_ACTION_LOGOUT);
192         }
193
194         m_requestedResource = CmsRequestUtil.getNotEmptyParameter(
195             getRequest(),
196             CmsWorkplaceManager.PARAM_LOGIN_REQUESTED_RESOURCE);
197         if (m_requestedResource == null) {
198             // no resource was requested, use default workplace URI
199
m_requestedResource = CmsFrameset.JSP_WORKPLACE_URI;
200         } else {
201             if (m_actionLogin != null) {
202                 m_requestedResource = CmsEncoder.decode(m_requestedResource);
203             }
204         }
205
206         if (Boolean.valueOf(m_actionLogin).booleanValue()) {
207
208             // login was requested
209
if ((m_username == null) && (m_password == null)) {
210                 m_message = Messages.get().container(Messages.GUI_LOGIN_NO_DATA_0);
211             } else if (m_username == null) {
212                 m_message = Messages.get().container(Messages.GUI_LOGIN_NO_NAME_0);
213             } else if (m_password == null) {
214                 m_message = Messages.get().container(Messages.GUI_LOGIN_NO_PASSWORD_0);
215             } else if ((m_username != null) && (m_password != null)) {
216
217                 // try to login with the given user information
218
login(m_username, m_password);
219
220                 if (getLoginException() == null) {
221                     // the login was successful
222
m_action = ACTION_LOGIN;
223
224                     // set the default project of the user
225
CmsUserSettings settings = new CmsUserSettings(cms);
226                     try {
227                         CmsProject project = cms.readProject(settings.getStartProject());
228                         if (cms.getAllAccessibleProjects().contains(project)) {
229                             // user has access to the project, set this as current project
230
cms.getRequestContext().setCurrentProject(project);
231                         }
232                     } catch (Exception JavaDoc e) {
233                         // unable to set the startup project, bad but not critical
234
LOG.warn(Messages.get().getBundle().key(
235                             Messages.LOG_LOGIN_NO_STARTUP_PROJECT_2,
236                             m_username,
237                             settings.getStartProject()), e);
238                     }
239                 } else {
240                     // there was an error during login
241

242                     if (org.opencms.security.Messages.ERR_LOGIN_FAILED_DISABLED_3 == getLoginException().getMessageContainer().getKey()) {
243                         // the user account is disabled
244
m_message = Messages.get().container(Messages.GUI_LOGIN_FAILED_DISABLED_0);
245                     } else if (org.opencms.security.Messages.ERR_LOGIN_FAILED_TEMP_DISABLED_5 == getLoginException().getMessageContainer().getKey()) {
246                         // the user account is temporarily disabled because of too many login failures
247
m_message = Messages.get().container(Messages.GUI_LOGIN_FAILED_TEMP_DISABLED_0);
248                     } else if (org.opencms.security.Messages.ERR_LOGIN_FAILED_WITH_MESSAGE_1 == getLoginException().getMessageContainer().getKey()) {
249                         // all logins have been diasabled be the Administration
250
CmsLoginMessage loginMessage = OpenCms.getLoginManager().getLoginMessage();
251                         if (loginMessage != null) {
252                             m_message = Messages.get().container(
253                                 Messages.GUI_LOGIN_FAILED_WITH_MESSAGE_1,
254                                 loginMessage.getMessage());
255                         }
256                     }
257                     if (m_message == null) {
258                         // any other error - display default message
259
m_message = Messages.get().container(Messages.GUI_LOGIN_FAILED_0);
260                     }
261                 }
262             }
263
264         } else if (Boolean.valueOf(m_actionLogout).booleanValue()) {
265
266             m_action = ACTION_LOGOUT;
267             // after logout this will automatically redirect to the login form again
268
logout();
269             return null;
270         }
271
272         if (m_action == ACTION_LOGIN) {
273             // clear message
274
m_message = null;
275             // login is successful, check if the requested resource can be read
276
CmsUriSplitter splitter = new CmsUriSplitter(m_requestedResource, true);
277             String JavaDoc resource = splitter.getPrefix();
278             if (CmsStringUtil.isEmptyOrWhitespaceOnly(resource)) {
279                 // bad resource name, use workplace as default
280
resource = CmsFrameset.JSP_WORKPLACE_URI;
281             }
282             if (!getCmsObject().existsResource(resource, CmsResourceFilter.ONLY_VISIBLE_NO_DELETED)) {
283                 // requested resource does either not exist or is not readable by user
284
if (CmsFrameset.JSP_WORKPLACE_URI.equals(resource)) {
285                     // we know the Workplace exists, so the user does not have access to the Workplace
286
// probalbly this is a "Guest" user in a default setup where "Guest" has no access to the Workplace
287
m_message = Messages.get().container(Messages.GUI_LOGIN_FAILED_NO_WORKPLACE_PERMISSIONS_0);
288                     m_action = ACTION_DISPLAY;
289                 } else if (getCmsObject().existsResource(CmsFrameset.JSP_WORKPLACE_URI)) {
290                     // resource does either not exist or is not readable, but general workplace permissions are granted
291
m_message = Messages.get().container(Messages.GUI_LOGIN_UNKNOWN_RESOURCE_1, m_requestedResource);
292                     m_requestedResource = CmsFrameset.JSP_WORKPLACE_URI;
293                 } else {
294                     // resource does not exist and no general workplace permissions granted
295
m_message = Messages.get().container(
296                         Messages.GUI_LOGIN_FAILED_NO_TARGET_PERMISSIONS_1,
297                         m_requestedResource);
298                     m_action = ACTION_DISPLAY;
299                 }
300             }
301             if (m_action == ACTION_DISPLAY) {
302                 // the login was invalid
303
m_requestedResource = null;
304                 // destroy the generated session
305
HttpSession JavaDoc session = getRequest().getSession(false);
306                 if (session != null) {
307                     session.invalidate();
308                 }
309             }
310         }
311
312         return displayLoginForm();
313     }
314
315     /**
316      * Appends the JavaScript for the login screen
317      * to the given HTML buffer.<p>
318      *
319      * @param html the html buffer to append the script to
320      * @param message the message to display after an unsuccessful login
321      */

322     protected void appendDefaultLoginScript(StringBuffer JavaDoc html, CmsMessageContainer message) {
323
324         html.append("<script type=\"text/javascript\">\n");
325
326         if (message != null) {
327             html.append("function showAlert() {\n");
328             html.append("\talert(\"");
329             html.append(CmsStringUtil.escapeJavaScript(message.key(m_locale)));
330             html.append("\");\n");
331             html.append("}\n");
332         }
333
334         html.append("function doOnload() {\n");
335         html.append("\tdocument.");
336         html.append(PARAM_FORM);
337         html.append(".");
338         html.append(PARAM_USERNAME);
339         html.append(".select();\n");
340         html.append("\tdocument.");
341         html.append(PARAM_FORM);
342         html.append(".");
343         html.append(PARAM_USERNAME);
344         html.append(".focus();\n");
345         if (message != null) {
346             html.append("\tshowAlert();\n");
347         }
348         html.append("}\n");
349
350         html.append("</script>\n");
351     }
352
353     /**
354      * Appends the JavaScript that opens the Workplace window after a successful login
355      * to the given HTML buffer.<p>
356      *
357      * @param html the html buffer to append the script to
358      * @param requestedResource the requested resource to open in a new window
359      * @param message the message to display if the originally requested resource is not available
360      */

361     protected void appendWorkplaceOpenerScript(StringBuffer JavaDoc html, String JavaDoc requestedResource, CmsMessageContainer message) {
362
363         String JavaDoc winId = "OpenCms" + System.currentTimeMillis();
364
365         html.append("<script type=\"text/javascript\">\n");
366
367         html.append("function doOnload() {\n");
368
369         // display missing resource warning if required
370
if (message != null) {
371             html.append("\talert(\"");
372             html.append(CmsStringUtil.escapeJavaScript(message.key(m_locale)));
373             html.append("\");\n");
374         }
375
376         // display login message if required
377
CmsLoginMessage loginMessage = OpenCms.getLoginManager().getLoginMessage();
378         if ((loginMessage != null) && (loginMessage.isActive())) {
379             String JavaDoc msg;
380             if (loginMessage.isLoginForbidden()) {
381                 // login forbidden for normal users, current user must be Administrator
382
msg = Messages.get().container(
383                     Messages.GUI_LOGIN_SUCCESS_WITH_MESSAGE_2,
384                     loginMessage.getMessage(),
385                     new Date JavaDoc(loginMessage.getTimeEnd())).key(m_locale);
386             } else {
387                 // just display the message
388
msg = loginMessage.getMessage();
389             }
390             html.append("\talert(\"");
391             html.append(CmsStringUtil.escapeJavaScript(msg));
392             html.append("\");\n");
393         }
394
395         html.append("\tvar openUri = \"");
396         html.append(link(requestedResource));
397         html.append("\";\n");
398         html.append("\tvar workplaceWin = openWorkplace(openUri, \"");
399         html.append(winId);
400         html.append("\");\n");
401         html.append("\tif (window.name != \"");
402         html.append(winId);
403         html.append("\") {\n");
404         html.append("\t\twindow.opener = workplaceWin;\n");
405         html.append("\t\tif (workplaceWin != null) {\n");
406         html.append("\t\t\twindow.close();\n");
407         html.append("\t\t}\n");
408         html.append("\t}\n");
409         html.append("}\n");
410
411         html.append("function openWorkplace(url, name) {\n");
412         html.append("\tvar isInWin = (window.name.match(/^OpenCms\\d+$/) != null);\n");
413         html.append("\tif (window.innerHeight) {\n");
414         // Mozilla
415
html.append("\t\tvar winHeight = window.innerHeight;\n");
416         html.append("\t\tvar winWidth = window.innerWidth;\n");
417         html.append("\t} else if (document.documentElement && document.documentElement.clientHeight) {\n");
418         // IE 6 "strict" mode
419
html.append("\t\tvar winHeight = document.documentElement.clientHeight;\n");
420         html.append("\t\tvar winWidth = document.documentElement.clientWidth;\n");
421         html.append("\t} else if (document.body && document.body.clientHeight) {\n");
422         // IE 5, IE 6 "relaxed" mode
423
html.append("\t\tvar winHeight = document.body.clientWidth;\n");
424         html.append("\t\tvar winWidth = document.body.clientHeight;\n");
425         html.append("\t}\n");
426         html.append("\tif (window.screenY) {\n");
427         // Mozilla
428
html.append("\t\tvar winTop = window.screenY;\n");
429         html.append("\t\tvar winLeft = window.screenX;\n");
430         html.append("\t\tif (! isInWin) {\n");
431         html.append("\t\t\twinTop += 25;\n");
432         html.append("\t\t\twinLeft += 25;\n");
433         html.append("\t\t}\n");
434         html.append("\t} else if (window.screenTop) {\n");
435         // IE
436
html.append("\t\tvar winTop = window.screenTop;\n");
437         html.append("\t\tvar winLeft = window.screenLeft;\n");
438         html.append("\t}\n");
439         html.append("\n");
440
441         if (requestedResource.startsWith(CmsWorkplace.VFS_PATH_WORKPLACE)) {
442             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");
443         } else {
444             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");
445         }
446         html.append("\tvar OpenCmsWin = window.open(url, name, openerStr);\n");
447         html.append("\n");
448         html.append("\ttry{\n");
449         html.append("\t\tif (! OpenCmsWin.opener) {\n");
450         html.append("\t\t\tOpenCmsWin.opener = self;\n");
451         html.append("\t\t}\n");
452         html.append("\t\tif (OpenCmsWin.focus) {\n");
453         html.append("\t\t\tOpenCmsWin.focus();\n");
454         html.append("\t\t}\n");
455         html.append("\t} catch (e) {}\n");
456         html.append("\n");
457         html.append("\treturn OpenCmsWin;\n");
458         html.append("}\n");
459
460         html.append("</script>\n");
461     }
462
463     /**
464      * Returns the HTML for the login form.<p>
465      *
466      * @return the HTML for the login form
467      */

468     protected String JavaDoc displayLoginForm() {
469
470         StringBuffer JavaDoc html = new StringBuffer JavaDoc();
471
472         html.append("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\">\n");
473         html.append("<html><head>\n");
474         html.append("<title>");
475
476         html.append(Messages.get().getBundle(m_locale).key(Messages.GUI_LOGIN_TITLE_0));
477         html.append("OpenCms " + OpenCms.getSystemInfo().getVersionName());
478
479         html.append("</title>\n");
480
481         String JavaDoc encoding = getRequestContext().getEncoding();
482         html.append("<meta HTTP-EQUIV=\"Content-Type\" CONTENT=\"text/html; charset=");
483         html.append(encoding);
484         html.append("\">\n");
485
486         html.append("<link rel=\"stylesheet\" type=\"text/css\" HREF=\"");
487         html.append(CmsWorkplace.getStyleUri(this, "workplace.css"));
488         html.append("\">\n");
489
490         if (m_action == ACTION_DISPLAY) {
491             // append default script
492
appendDefaultLoginScript(html, m_message);
493         } else if (m_action == ACTION_LOGIN) {
494             // append window opener script
495
appendWorkplaceOpenerScript(html, m_requestedResource, m_message);
496         }
497
498         html.append("</head>\n");
499
500         html.append("<body class=\"dialog\" onload=\"doOnload();\">\n");
501
502         html.append("<div style=\"text-align: center; padding-top: 50px;\">");
503         html.append("<img SRC=\"");
504         html.append(CmsWorkplace.getResourceUri("commons/login_logo.png"));
505         html.append("\" alt=\"OpenCms Logo\">");
506         html.append("</div>\n");
507
508         html.append("<table class=\"logindialog\" cellpadding=\"0\" cellspacing=\"0\"><tr><td>\n");
509         html.append("<table class=\"dialogbox\" cellpadding=\"0\" cellspacing=\"0\"><tr><td>\n");
510         html.append("<div class=\"dialoghead\">");
511
512         if (m_action == ACTION_DISPLAY) {
513             html.append(Messages.get().getBundle(m_locale).key(Messages.GUI_LOGIN_HEADLINE_0));
514         } else if (m_action == ACTION_LOGIN) {
515             html.append(Messages.get().getBundle(m_locale).key(Messages.GUI_LOGIN_HEADLINE_ALREADY_IN_0));
516         }
517
518         html.append("</div>\n");
519
520         if (m_action == ACTION_DISPLAY) {
521             // start form
522
html.append("<form style=\"margin: 0px; padding: 0px;\" action=\"");
523             html.append(getFormLink());
524             html.append("\"");
525             appendId(html, PARAM_FORM);
526             html.append("method=\"POST\">\n");
527         }
528
529         html.append("<div class=\"dialogcontent\">\n");
530         html.append("<table border=\"0\">\n");
531
532         html.append("<tr>\n");
533         html.append("<td></td>\n<td colspan=\"2\" style=\"white-space: nowrap;\">\n");
534         html.append("<div style=\"padding-bottom: 10px;\">");
535
536         if (m_action == ACTION_DISPLAY) {
537             html.append(CmsStringUtil.escapeHtml(Messages.get().getBundle(m_locale).key(Messages.GUI_LOGIN_MESSAGE_0)));
538         } else if (m_action == ACTION_LOGIN) {
539             html.append(CmsStringUtil.escapeHtml(Messages.get().getBundle(m_locale).key(
540                 Messages.GUI_LOGIN_MESSAGE_ALREADY_IN_0)));
541         }
542
543         html.append("</div>\n");
544         html.append("</td>\n");
545         html.append("</tr>\n");
546
547         html.append("<tr>\n");
548
549         html.append("<td style=\"width: 60px; text-align: center; vertical-align: top\" rowspan=\"3\">");
550         html.append("<img SRC=\"");
551         html.append(CmsWorkplace.getResourceUri("commons/login.png"));
552         html.append("\" height=\"48\" width=\"48\" alt=\"\">");
553         html.append("</td>\n");
554
555         html.append("<td style=\"white-space: nowrap;\"><b>");
556         html.append(Messages.get().getBundle(m_locale).key(Messages.GUI_LOGIN_USERNAME_0));
557         html.append("</b>&nbsp;&nbsp;</td>\n");
558         html.append("<td style=\"width: 300px; white-space: nowrap;\">");
559
560         if (m_action == ACTION_DISPLAY) {
561             // append input for user name
562
html.append("<input style=\"width: 100%\" type=\"text\"");
563             appendId(html, PARAM_USERNAME);
564             html.append("value=\"");
565             html.append(CmsStringUtil.isEmpty(m_username) ? "" : CmsEncoder.escapeXml(m_username));
566             html.append("\">");
567         } else if (m_action == ACTION_LOGIN) {
568             // append name of user that has been logged in
569
html.append(getRequestContext().currentUser().getFullName());
570         }
571
572         html.append("</td>\n");
573         html.append("</tr>\n");
574
575         if (m_action == ACTION_DISPLAY) {
576             // append 2 rows: input for user name and login button
577
html.append("<tr>\n");
578             html.append("<td style=\"white-space: nowrap;\"><b>");
579             html.append(Messages.get().getBundle(m_locale).key(Messages.GUI_LOGIN_PASSWORD_0));
580             html.append("</b>&nbsp;&nbsp;</td>\n");
581             html.append("<td style=\"width: 300px; white-space: nowrap;\">");
582             html.append("<input style=\"width: 100%\" type=\"password\"");
583             appendId(html, PARAM_PASSWORD);
584             html.append(">");
585             html.append("</td>\n");
586             html.append("</tr>\n");
587
588             html.append("<tr>\n");
589             html.append("<td></td>\n<td style=\"white-space: nowrap;\">\n");
590             html.append("<input type=\"hidden\"");
591             appendId(html, PARAM_ACTION_LOGIN);
592             html.append("value=\"true\">\n");
593
594             if (m_requestedResource != null) {
595                 html.append("<input type=\"hidden\"");
596                 appendId(html, CmsWorkplaceManager.PARAM_LOGIN_REQUESTED_RESOURCE);
597                 html.append("value=\"");
598                 html.append(CmsEncoder.encode(m_requestedResource));
599                 html.append("\">\n");
600             }
601
602             html.append("<input class=\"loginbutton\" type=\"submit\" value=\"");
603             html.append(Messages.get().getBundle(m_locale).key(Messages.GUI_LOGIN_BUTTON_0));
604             html.append("\">\n");
605
606             html.append("</td>\n");
607             html.append("</tr>\n");
608         } else if (m_action == ACTION_LOGIN) {
609             // append 2 rows: one empty, other for button with re-open window script
610
html.append("<tr><td></td><td></td></tr>\n");
611
612             html.append("<tr>\n");
613             html.append("<td></td>\n");
614             html.append("<td style=\"width:100%; white-space: nowrap;\">\n");
615             html.append("<input class=\"loginbutton\" type=\"button\" value=\"");
616             html.append(Messages.get().getBundle(m_locale).key(Messages.GUI_LOGIN_BUTTON_ALREADY_IN_0));
617             html.append("\" onclick=\"doOnload()\">\n");
618             html.append("</td>\n");
619             html.append("</tr>\n");
620         }
621
622         html.append("</table>\n");
623         html.append("</div>");
624
625         if (m_action == ACTION_DISPLAY) {
626             // end form
627
html.append("</form>\n");
628         }
629
630         html.append("</td></tr></table>\n");
631         html.append("</td></tr></table>\n");
632
633         html.append("<div style=\"text-align: center; font-size: 10px; white-space: nowrap;\">");
634         html.append("<a HREF=\"http://www.opencms.org\" target=\"_blank\">OpenCms</a> ");
635         html.append(Messages.get().getBundle(m_locale).key(Messages.GUI_LOGIN_OPENCMS_IS_FREE_SOFTWARE_0));
636         html.append("</div>\n");
637         html.append("<div style=\"text-align: center; font-size: 10px; white-space: nowrap;\">");
638         html.append(Messages.get().getBundle(m_locale).key(Messages.GUI_LOGIN_TRADEMARKS_0));
639         html.append("</div>\n");
640         html.append("<div style=\"text-align: center; font-size: 10px; white-space: nowrap;\">");
641         html.append("&copy; 2006 Alkacon Software GmbH. ");
642         html.append(Messages.get().getBundle(m_locale).key(Messages.GUI_LOGIN_RIGHTS_RESERVED_0));
643         html.append("</div>\n");
644
645         html.append("<noscript>\n");
646         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>");
647         html.append(CmsStringUtil.escapeHtml(Messages.get().getBundle(m_locale).key(
648             Messages.GUI_LOGIN_NOSCRIPT_1,
649             OpenCms.getSiteManager().getWorkplaceSiteMatcher())));
650         html.append("</b></div>\n");
651         html.append("</noscript>\n");
652
653         html.append("</body></html>");
654
655         return html.toString();
656     }
657
658     /**
659      * Appends the HTML form name/id code for the given id to the given html.<p>
660      *
661      * @param html the html where to append the id to
662      * @param id the id to append
663      */

664     private void appendId(StringBuffer JavaDoc html, String JavaDoc id) {
665
666         html.append(" name=\"");
667         html.append(id);
668         html.append("\" id=\"");
669         html.append(id);
670         html.append("\" ");
671     }
672 }
Popular Tags