Added a button to cancel the loginscreen

git-svn-id: https://svn.libreccm.org/ccm/trunk@4184 8810af33-2d31-482b-a856-94f89814c4df
master
konermann 2016-07-01 11:56:29 +00:00
parent 0f956a2f7d
commit 10f2a7a5fe
6 changed files with 168 additions and 128 deletions

View File

@ -27,6 +27,8 @@ public interface LoginConstants
{
public final static GlobalizedMessage SUBMIT =
LoginHelper.getMessage("login.submit");
public final static GlobalizedMessage LOGIN =
LoginHelper.getMessage("login.login");
public final static GlobalizedMessage PRIMARY_EMAIL =
LoginHelper.getMessage("login.primaryEmail");
public final static GlobalizedMessage ADDITIONAL_EMAIL =
@ -69,6 +71,8 @@ public interface LoginConstants
LoginHelper.getMessage("login.error.badEmail");
public final static GlobalizedMessage ERROR_BANNED_EMAIL =
LoginHelper.getMessage("login.error.bannedEmail");
public final static GlobalizedMessage ERROR_NO_EMAIL =
LoginHelper.getMessage("login.error.noEmail");
public final static String FORM_EMAIL =
"emailAddress";

View File

@ -64,3 +64,5 @@ login.changePasswortForm.greeting=Welcome {0}
login.changePasswortForm.introText=To change your passwort please fill out this form.
login.userForm.couldnt_load_user=Could not load User
login.userLoginForm.couldnt_create_timestamp=Could not create timestamp
login.login=Login
login.error.noEmail=Please enter a valid email address.

View File

@ -64,3 +64,5 @@ login.changePasswortForm.greeting=Willkommen {0}
login.changePasswortForm.introText=Um ihr Passwort zu \u00e4ndern, f\u00fcllen sie bitte das folgende Formular aus.
login.userForm.couldnt_load_user=User konnte nicht geladen werden
login.userLoginForm.couldnt_create_timestamp=Konnte den Timestamp nicht erstellen
login.login=Login
login.error.noEmail=Bitte geben Sie eine g\u00fcltige Email Adresse an.

View File

@ -64,3 +64,5 @@ login.changePasswortForm.greeting=Welcome {0}
login.changePasswortForm.introText=To change your passwort please fill out this form.
login.userForm.couldnt_load_user=Could not load User
login.userLoginForm.couldnt_create_timestamp=Could not create timestamp
login.login=Login
login.error.noEmail=Please enter a valid email address.

View File

@ -64,3 +64,5 @@ login.error.bannedEmail=User cannot currently access system
login.error.loginFail=User cannot currently access system
login.userForm.couldnt_load_user=Impossible de charger l'utilisateur
login.userLoginForm.couldnt_create_timestamp=Impossible de cr\u00e9er timestamp
login.login=Login
login.error.noEmail=Please enter a valid email address.

View File

@ -18,16 +18,7 @@
*/
package com.arsdigita.ui.login;
import com.arsdigita.bebop.BoxPanel;
import com.arsdigita.bebop.ColumnPanel;
import com.arsdigita.bebop.Container;
import com.arsdigita.bebop.ElementComponent;
import com.arsdigita.bebop.Form;
import com.arsdigita.bebop.FormData;
import com.arsdigita.bebop.FormProcessException;
import com.arsdigita.bebop.Label;
import com.arsdigita.bebop.PageState;
import com.arsdigita.bebop.SimpleContainer;
import com.arsdigita.bebop.*;
import com.arsdigita.bebop.event.FormInitListener;
import com.arsdigita.bebop.event.FormProcessListener;
import com.arsdigita.bebop.event.FormSectionEvent;
@ -36,10 +27,8 @@ import com.arsdigita.bebop.form.CheckboxGroup;
import com.arsdigita.bebop.form.Hidden;
import com.arsdigita.bebop.form.Option;
import com.arsdigita.bebop.form.Password;
import com.arsdigita.bebop.form.Submit;
import com.arsdigita.bebop.form.TextField;
import com.arsdigita.bebop.parameters.EmailParameter;
import com.arsdigita.bebop.parameters.NotNullValidationListener;
import com.arsdigita.bebop.parameters.StringParameter;
import com.arsdigita.bebop.parameters.URLParameter;
import com.arsdigita.kernel.Kernel;
@ -60,24 +49,25 @@ import javax.security.auth.login.LoginException;
import javax.servlet.http.HttpServletRequest;
import org.apache.log4j.Logger;
import java.net.URI;
import java.net.URISyntaxException;
/**
* A Bebop form that accepts login and password from the user and attempts
* to authenticate and then log in the user.
* A Bebop form that accepts login and password from the user and attempts to
* authenticate and then log in the user.
*
* Depending on security configuration it may generate a link to a NewUser
* registration form, where a new user may register itself. LoginServlet has
* to ensure that this page is created appropriately and is available.
* registration form, where a new user may register itself. LoginServlet has to
* ensure that this page is created appropriately and is available.
*
* According to documentation in r1230
* Simple SSO implementation: /ccm/register first tries to do SSO login,
* falling back to normal form-based login.
* Set waf.sso_login=true only after you make sure webapp can *only* be accessed
* According to documentation in r1230 Simple SSO implementation: /ccm/register
* first tries to do SSO login, falling back to normal form-based login. Set
* waf.sso_login=true only after you make sure webapp can *only* be accessed
* through the frontend webserver doing the authentication.
*
* To make this work with Tomcat/mod_jk/Apache HTTPD:
* - use latest mod_jk (tested with 1.2.15)
* - add attribute Connector@tomcatAuthentication="false" to JK definition
* in server.xml
* To make this work with Tomcat/mod_jk/Apache HTTPD: - use latest mod_jk
* (tested with 1.2.15) - add attribute Connector@tomcatAuthentication="false"
* to JK definition in server.xml
*
* @author Roger Hsueh
* @author Michael Bryzek
@ -89,13 +79,14 @@ public class UserLoginForm extends Form
implements LoginConstants, FormInitListener,
FormValidationListener, FormProcessListener {
private static final Logger s_log =
Logger.getLogger(UserLoginForm.class);
private static final Logger s_log
= Logger.getLogger(UserLoginForm.class);
// package friendly static form name makes writing HttpUnitTest easier
final static String FORM_NAME = "user-login";
private CheckboxGroup m_isPersistent;
private Hidden m_timestamp;
private SaveCancelSection m_saveCancelSection;
private Hidden m_returnURL;
private TextField m_loginName;
private Password m_password;
@ -167,7 +158,10 @@ public class UserLoginForm extends Form
LoginServlet.getCookiesExplainPageURL()));
add(cookiePanel);
add(new Submit(SUBMIT), ColumnPanel.CENTER | ColumnPanel.FULL_WIDTH);
//add(new Submit(SUBMIT), ColumnPanel.CENTER | ColumnPanel.FULL_WIDTH);
m_saveCancelSection = new SaveCancelSection(new SimpleContainer());
m_saveCancelSection.getSaveButton().setButtonLabel(LOGIN);
add(m_saveCancelSection);
if (securityConfig.getEnableQuestion()) {
add(new DynamicLink("login.userRegistrationForm.forgotPasswordLink",
@ -187,11 +181,10 @@ public class UserLoginForm extends Form
* Sets up the login form parameters
*/
private void setupLogin() {
SimpleContainer loginMessage =
new SimpleContainer("subsite:loginPromptMsg",
SimpleContainer loginMessage
= new SimpleContainer("subsite:loginPromptMsg",
LoginServlet.SUBSITE_NS_URI);
if (Kernel.getConfig().emailIsPrimaryIdentifier()) {
loginMessage.setClassAttr("email");
} else {
@ -213,7 +206,7 @@ public class UserLoginForm extends Form
addInitListener(new ScreenNameInitListener((StringParameter) m_loginName.
getParameterModel()));
}
m_loginName.addValidationListener(new NotNullValidationListener());
//m_loginName.addValidationListener(new NotNullValidationListener());
add(m_loginName);
}
@ -265,6 +258,14 @@ public class UserLoginForm extends Form
FormData data = event.getFormData();
PageState state = event.getPageState();
if (m_saveCancelSection.getSaveButton().isSelected(state)) {
//check if an email adress has been entered at all
final Object loginname = m_loginName.getValue(state);
if (loginname == null) {
data.addError(ERROR_NO_EMAIL);
}
try {
// check timestamp
try {
@ -289,6 +290,7 @@ public class UserLoginForm extends Form
}
}
}
}
/**
*
@ -301,6 +303,9 @@ public class UserLoginForm extends Form
final PageState state = event.getPageState();
final HttpServletRequest req = state.getRequest();
//Login:
if (m_saveCancelSection.getSaveButton().isSelected(state)) {
// Redirect to workspace or return URL, if specified.
final String path = UI.getUserRedirectURL(req);
@ -308,16 +313,37 @@ public class UserLoginForm extends Form
throw new ReturnSignal(req, url);
}
//Cancel:
if (m_saveCancelSection.getCancelButton().isSelected(state)) {
//redirect the user to the place they came from.
try {
String refererURI = new URI(req.getHeader("referer")).getPath();
if (refererURI.equals("/ccm/register/")) {
final String path = UI.getRootPageURL(req);
throw new RedirectSignal(com.arsdigita.web.URL.there(req, path), true);
}
throw new ReturnSignal(req, refererURI);
} catch (URISyntaxException e) {
e.printStackTrace();
}
}
}
/**
* Logs in the user using the username, password, and "Remember this
* login?" request stored in the given form event. Subclasses can
* override this method or just one of the specific case handlers
* (onLoginSuccess, onBadPassword, onAccountNotFound, onLoginException).
* Logs in the user using the username, password, and "Remember this login?"
* request stored in the given form event. Subclasses can override this
* method or just one of the specific case handlers (onLoginSuccess,
* onBadPassword, onAccountNotFound, onLoginException).
*
* @param event
* @throws FormProcessException if there is an unexpected login error
**/
*
*/
protected void loginUser(FormSectionEvent event)
throws FormProcessException {
PageState state = event.getPageState();
@ -354,9 +380,11 @@ public class UserLoginForm extends Form
/**
* Executed when login succeeds. Default implementation does nothing.
*
* @param event
* @throws com.arsdigita.bebop.FormProcessException
**/
*
*/
protected void onLoginSuccess(FormSectionEvent event)
throws FormProcessException {
// do nothing
@ -375,14 +403,15 @@ public class UserLoginForm extends Form
}
/**
* Executed when login fails with a bad password or when
* autoLoginOn is set to false and the user doesn't exist.
* Default implementation marks password parameter with an error
* message.
* Executed when login fails with a bad password or when autoLoginOn is set
* to false and the user doesn't exist. Default implementation marks
* password parameter with an error message.
*
* @param event
* @param e
* @throws com.arsdigita.bebop.FormProcessException
**/
*
*/
protected void onLoginFail(FormSectionEvent event,
LoginException e)
throws FormProcessException {
@ -393,9 +422,10 @@ public class UserLoginForm extends Form
/**
* Executed when login fails for an unrecognized user. Default
* implementation sets a flag so that the client is redirected to the
* new user page (see the process() method code).
**/
* implementation sets a flag so that the client is redirected to the new
* user page (see the process() method code).
*
*/
protected void onAccountNotFound(FormSectionEvent event,
AccountNotFoundException e)
throws FormProcessException {
@ -416,7 +446,8 @@ public class UserLoginForm extends Form
/**
* Executed when login fails for an unrecognized problem. Default
* implementation logs the error and throws FormProcessException.
**/
*
*/
protected void onLoginException(FormSectionEvent event,
LoginException e)
throws FormProcessException {
@ -426,14 +457,13 @@ public class UserLoginForm extends Form
}
/**
* Determines whether a persistent cookie is requested in the given
* form.
* Determines whether a persistent cookie is requested in the given form.
*
* @return true if the specified formdata has a field named
* FORM_PERSISTENT_LOGIN_P whose value is equal to "1". If there
* is no such field in the form data, returns the specified default
* value.
**/
* FORM_PERSISTENT_LOGIN_P whose value is equal to "1". If there is no such
* field in the form data, returns the specified default value.
*
*/
protected boolean getPersistentLoginValue(PageState state,
boolean defaultValue) {
// Problem:
@ -445,19 +475,17 @@ public class UserLoginForm extends Form
Object persistentLoginValue = m_isPersistent.getValue(state);
String value ;
String value;
if (persistentLoginValue == null) {
return defaultValue;
}
if (persistentLoginValue instanceof String[]) {
value = ((String[])persistentLoginValue)[0];
}
else if (persistentLoginValue instanceof String) {
value = ((String[]) persistentLoginValue)[0];
} else if (persistentLoginValue instanceof String) {
value = (String) persistentLoginValue;
}
else {
} else {
value = "0";
}