import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
+import javax.mail.internet.AddressException;
+
import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
+import org.springframework.mail.MailException;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.Authentication;
import org.vaadin.spring.events.EventBusListener;
import org.vaadin.spring.events.annotation.EventBusListenerMethod;
+import com.vaadin.data.validator.AbstractStringValidator;
import com.vaadin.spring.annotation.SpringComponent;
import com.vaadin.spring.annotation.ViewScope;
import com.vaadin.ui.themes.ValoTheme;
import eu.etaxonomy.cdm.api.application.ICdmRepository;
+import eu.etaxonomy.cdm.api.service.security.AccountSelfManagementException;
import eu.etaxonomy.cdm.vaadin.event.AuthenticationAttemptEvent;
import eu.etaxonomy.cdm.vaadin.event.AuthenticationSuccessEvent;
import eu.etaxonomy.cdm.vaadin.event.UserAccountEvent;
log.warn("Performing autologin with user " + System.getProperty(PROPNAME_USER));
authenticate(System.getProperty(PROPNAME_USER), System.getProperty(PROPNAME_PASSWORD));
}
+
+ getView().getLoginDialog().getEmail().addValidator(new AbstractStringValidator("An account for this email address already exits. You may want to use the \"Password Revovery\" tab intsead?") {
+ private static final long serialVersionUID = 1L;
+ @Override
+ protected boolean isValidValue(String value) {
+ return !repo.getAccountRegistrationService().emailAddressExists(value);
+ }
+ });
}
@Override
}
@EventBusListenerMethod
- public void onPasswordRevoveryEvent(UserAccountEvent event) throws MalformedURLException, ExecutionException {
+ public void onPasswordRevoveryEvent(UserAccountEvent event) throws MalformedURLException, ExecutionException, MailException, AddressException, AccountSelfManagementException {
if(event.getAction().equals(UserAccountEvent.UserAccountAction.REQUEST_PASSWORD_RESET)) {
requestPasswordReset();
+ } else if(event.getAction().equals(UserAccountEvent.UserAccountAction.REGISTER_ACCOUNT)) {
+ requestAccountCreation();
}
}
private void requestPasswordReset() throws MalformedURLException, ExecutionException {
String userNameOrEmail = getView().getLoginDialog().getUserNameOrEmail().getValue();
URL servletBaseUrl = VaadinServletUtilities.getServletBaseUrl();
- logger.debug("PasswordRevoveryEvent for " + servletBaseUrl + ", userNameOrEmail:" + userNameOrEmail);
+ logger.debug("UserAccountAction.REQUEST_PASSWORD_RESET for " + servletBaseUrl + ", userNameOrEmail:" + userNameOrEmail);
// Implementation note: UI modifications allied in the below callback methods will not affect the UI
// immediately, therefore we use a CountDownLatch
CountDownLatch finshedSignal = new CountDownLatch(1);
}
if(!asyncException.isEmpty()) {
getView().getLoginDialog().getMessageSendRecoveryEmailLabel()
- .setValue("Sending an password reset email to you has failed. Please try again later or contect the support in case this error persists.");
+ .setValue("Sending the password reset email to you has failed. Please try again later or contect the support in case this error persists.");
getView().getLoginDialog().getMessageSendRecoveryEmailLabel().setStyleName(ValoTheme.LABEL_FAILURE);
} else {
if(!asyncTimeout && result) {
}
}
+ private void requestAccountCreation() throws MalformedURLException, MailException, AddressException, AccountSelfManagementException, ExecutionException {
+ String emailAddress = getView().getLoginDialog().getEmail().getValue();
+ URL servletBaseUrl = VaadinServletUtilities.getServletBaseUrl();
+
+ logger.debug("UserAccountAction.REGISTER_ACCOUNT for " + servletBaseUrl + ", emailAddress:" + emailAddress);
+
+ CountDownLatch finshedSignal = new CountDownLatch(1);
+ List<Throwable> asyncException = new ArrayList<>(1);
+ ListenableFuture<Boolean> futureResult = repo.getAccountRegistrationService().emailAccountRegistrationRequest(emailAddress,
+ servletBaseUrl.toString() + "/app/" + UserAccountSelfManagementUI.PATH + "#!" + AccountRegistrationViewBean.NAME + "/%s");
+ futureResult.addCallback(
+ successFuture -> {
+ finshedSignal.countDown();
+ },
+ exception -> {
+ // possible MailException
+ asyncException.add(exception);
+ finshedSignal.countDown();
+ }
+ );
+ boolean asyncTimeout = false;
+ Boolean result = false;
+ try {
+ finshedSignal.await(2, TimeUnit.SECONDS);
+ result = futureResult.get();
+ } catch (InterruptedException e) {
+ asyncTimeout = true;
+ }
+ if(!asyncException.isEmpty()) {
+ getView().getLoginDialog().getRegisterMessageLabel()
+ .setValue("Sending the account resitration email to you has failed. Please try again later or contect the support in case this error persists.");
+ getView().getLoginDialog().getRegisterMessageLabel().setStyleName(ValoTheme.LABEL_FAILURE);
+ } else {
+ if(!asyncTimeout && result) {
+ getView().getLoginDialog().getRegisterMessageLabel().setValue("An email with with further instructions has been sent to you.");
+ getView().getLoginDialog().getRegisterMessageLabel().setStyleName(ValoTheme.LABEL_SUCCESS);
+ getView().getLoginDialog().getEmail().setEnabled(false);
+ getView().getLoginDialog().getRegisterButton().setEnabled(false);
+
+ } else {
+ getView().getLoginDialog().getRegisterMessageLabel().setValue("A timeout has occured, please try again.");
+ getView().getLoginDialog().getRegisterMessageLabel().setStyleName(ValoTheme.LABEL_FAILURE);
+ }
+ }
+ }
+
}
*/
package eu.etaxonomy.cdm.vaadin.view;
+import org.apache.commons.lang3.StringUtils;
import org.vaadin.spring.events.EventScope;
+import com.vaadin.data.validator.EmailValidator;
import com.vaadin.data.validator.StringLengthValidator;
import com.vaadin.event.ShortcutAction.KeyCode;
import com.vaadin.navigator.View;
import eu.etaxonomy.cdm.vaadin.component.LoginDialog;
import eu.etaxonomy.cdm.vaadin.event.AuthenticationAttemptEvent;
-import eu.etaxonomy.cdm.vaadin.event.RegisterNewUserEvent;
import eu.etaxonomy.cdm.vaadin.event.UserAccountEvent;
import eu.etaxonomy.vaadin.mvp.AbstractView;
import eu.etaxonomy.vaadin.ui.navigation.NavigationEvent;
root.setComponentAlignment(loginDialog, Alignment.MIDDLE_CENTER);
setCompositionRoot(root);
+ // --- login tab
loginDialog.getLoginButton().addClickListener(e -> handleLoginClick(e));
loginDialog.getLoginButton().setClickShortcut(KeyCode.ENTER);
- loginDialog.getRegisterButton().addClickListener(e -> getViewEventBus().publish(EventScope.UI, this, new RegisterNewUserEvent(e)));
- loginDialog.getSendOnetimeLogin().addClickListener(e -> {
- getViewEventBus().publish(this, new UserAccountEvent(UserAccountEvent.UserAccountAction.REQUEST_PASSWORD_RESET,e));
- });
// NOTE: null viewName will be replaced by the default view name in NavigationManagerBean
loginDialog.getCancelLoginButton().addClickListener(e -> getViewEventBus().publish(EventScope.UI, this, new NavigationEvent(null)));
+ // --- Register tab
+ loginDialog.getRegisterButton().addClickListener(e -> {
+ getViewEventBus().publish(this, new UserAccountEvent(UserAccountEvent.UserAccountAction.REGISTER_ACCOUNT, e));
+ }
+ );
loginDialog.getCancelRegistrationButton().addClickListener(e -> getViewEventBus().publish(EventScope.UI, this, new NavigationEvent(null)));
+ loginDialog.getEmail().addValidator(new EmailValidator("The enterd E-mail address is not valid."));
+ loginDialog.getEmail().addValueChangeListener(e -> updateRegisterButtonState());
+ // further validators added in the presenter
+ // --- Password reset tab
StringLengthValidator nameOrEmailValidator = new StringLengthValidator("Please enter your username or email address.");
loginDialog.getUserNameOrEmail().addValidator(nameOrEmailValidator);
loginDialog.getUserNameOrEmail().addTextChangeListener(e -> {
String text = e.getText();
- logger.debug("text: " + text);
loginDialog.getSendOnetimeLogin().setEnabled(text != null && text.length() > 1);
});
+ loginDialog.getSendOnetimeLogin().addClickListener(e -> {
+ getViewEventBus().publish(this, new UserAccountEvent(UserAccountEvent.UserAccountAction.REQUEST_PASSWORD_RESET,e));
+ });
+ }
+
+ private void updateRegisterButtonState() {
+ loginDialog.getRegisterButton().setEnabled(StringUtils.isNoneBlank(loginDialog.getEmail().getValue()) && loginDialog.getEmail().getErrorMessage() == null);
}
private void handleLoginClick(ClickEvent e) {