This is an automated email from the git hooks/post-receive script. New commit to branch develop in repository wao. See http://git.codelutin.com/wao.git commit 6955ed4f77d88c859f4c24d7fa51122413ebec5c Author: dcosse <cosse@codelutin.com> Date: Fri Mar 27 16:35:59 2015 +0100 refs 6844 Remise en place de la fonctionnalité de demande de réinitialisation de mot de passe --- .../service/administration/WaoUsersService.java | 37 +++++++++++ .../java/fr/ifremer/wao/web/WaoInterceptor.java | 5 +- .../authentication/ForgottenPasswordAction.java | 71 ++++++++++++++++++++++ .../main/resources/i18n/wao-web_en_GB.properties | 3 + .../main/resources/i18n/wao-web_fr_FR.properties | 3 + .../content/authentication/forgotten-password.jsp | 48 +++++++++++++++ .../WEB-INF/content/authentication/login.jsp | 22 ++++++- wao-web/src/main/webapp/WEB-INF/decorators.xml | 1 + 8 files changed, 187 insertions(+), 3 deletions(-) diff --git a/wao-services/src/main/java/fr/ifremer/wao/services/service/administration/WaoUsersService.java b/wao-services/src/main/java/fr/ifremer/wao/services/service/administration/WaoUsersService.java index 6bead99..2e31b91 100644 --- a/wao-services/src/main/java/fr/ifremer/wao/services/service/administration/WaoUsersService.java +++ b/wao-services/src/main/java/fr/ifremer/wao/services/service/administration/WaoUsersService.java @@ -291,4 +291,41 @@ public class WaoUsersService extends WaoServiceSupport { commit(); } + + protected UpdateWaoUserCommand getPasswordRecoveryUpdateWaoUserCommand(WaoUser waoUser) { + UpdateWaoUserCommand updateWaoUserCommand = new UpdateWaoUserCommand(); + updateWaoUserCommand.setWaoUser(waoUser); + updateWaoUserCommand.setPasswordStrategy(UpdateWaoUserCommandPasswordStrategy.GENERATE_NEW_PASSWORD); + updateWaoUserCommand.setPasswordStrategies(UpdateWaoUserCommandPasswordStrategy.getPasswordStrategiesForWaoUserCreation()); + return updateWaoUserCommand; + } + + public void askForPasswordReminder(String login) throws WrongCredentialsException, InactiveWaoUserException, NoRoleAttributedException { + WaoUserTopiaDao dao = getWaoUserDao(); + + Optional<WaoUser> optionalWaoUser = dao.tryFindByEmailAndFetchCollections(login); + + WaoUser waoUser; + + if ( ! optionalWaoUser.isPresent()) { + if (log.isInfoEnabled()) { + log.info("no such user " + login); + } + throw new WrongCredentialsException(); + } + + waoUser = optionalWaoUser.get(); + + if ( ! waoUser.isActive()) { + throw new InactiveWaoUserException(waoUser); + } + + if (waoUser.isUserProfileEmpty()) { + throw new NoRoleAttributedException(waoUser); + } + + UpdateWaoUserCommand updateWaoUserCommand = getPasswordRecoveryUpdateWaoUserCommand(waoUser); + + save(updateWaoUserCommand); + } } diff --git a/wao-web/src/main/java/fr/ifremer/wao/web/WaoInterceptor.java b/wao-web/src/main/java/fr/ifremer/wao/web/WaoInterceptor.java index 448c87e..a36cc45 100644 --- a/wao-web/src/main/java/fr/ifremer/wao/web/WaoInterceptor.java +++ b/wao-web/src/main/java/fr/ifremer/wao/web/WaoInterceptor.java @@ -30,6 +30,7 @@ import fr.ifremer.wao.WaoTopiaPersistenceContext; import fr.ifremer.wao.services.WaoApplicationContext; import fr.ifremer.wao.services.WaoService; import fr.ifremer.wao.services.WaoServiceContext; +import fr.ifremer.wao.web.action.authentication.ForgottenPasswordAction; import fr.ifremer.wao.web.action.authentication.LoginAction; import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.logging.Log; @@ -44,8 +45,8 @@ public class WaoInterceptor implements Interceptor { private static final Log log = LogFactory.getLog(WaoInterceptor.class); - protected static final ImmutableSet<Class<LoginAction>> ACTIONS_ACCESSIBLE_WITHOUT_LOGIN = - ImmutableSet.of(LoginAction.class); + protected static final ImmutableSet<Class<? extends WaoJspActionSupport>> ACTIONS_ACCESSIBLE_WITHOUT_LOGIN = + ImmutableSet.of(LoginAction.class, ForgottenPasswordAction.class); @Override public void init() { diff --git a/wao-web/src/main/java/fr/ifremer/wao/web/action/authentication/ForgottenPasswordAction.java b/wao-web/src/main/java/fr/ifremer/wao/web/action/authentication/ForgottenPasswordAction.java new file mode 100644 index 0000000..e3cb2ec --- /dev/null +++ b/wao-web/src/main/java/fr/ifremer/wao/web/action/authentication/ForgottenPasswordAction.java @@ -0,0 +1,71 @@ +package fr.ifremer.wao.web.action.authentication; + +import fr.ifremer.wao.services.service.administration.InactiveWaoUserException; +import fr.ifremer.wao.services.service.administration.NoRoleAttributedException; +import fr.ifremer.wao.services.service.administration.WaoUsersService; +import fr.ifremer.wao.services.service.administration.WrongCredentialsException; +import fr.ifremer.wao.web.WaoJspActionSupport; +import org.apache.struts2.convention.annotation.Action; +import org.apache.struts2.convention.annotation.Result; + +/** + * Created by davidcosse on 26/03/15. + */ +public class ForgottenPasswordAction extends WaoJspActionSupport { + + private static final long serialVersionUID = 1L; + + protected transient WaoUsersService service; + + protected String login; + + protected boolean recovered; + + public void setService(WaoUsersService service) { + this.service = service; + } + + @Override + @Action("forgotten-password-input") + public String input() throws Exception { + return super.input(); + } + + @Override + @Action(results = { + @Result(name="success", type="redirectAction", params = { "namespace", "/authentication", "actionName", "forgotten-password!input", "recovered", "%{recovered}", "login", "%{login}"})}) + public String execute() throws Exception { + try { + service.askForPasswordReminder(login); + recovered = true; + addActionMessage(t("wao.ui.reminderSent")); + } catch (WrongCredentialsException credentialException) { + addFieldError("login", t("wao.ui.form.authentication.error.wrongCredentials")); + return INPUT; + } catch (InactiveWaoUserException inactiveWaoUserException) { + addFieldError("login", t("wao.ui.form.authentication.error.noRoleAttributed")); + return INPUT; + } catch (NoRoleAttributedException noRoleAttributedException) { + addFieldError("login", t("wao.ui.form.authentication.error.inactiveWaoUser")); + return INPUT; + } + + return SUCCESS; + } + + public void setLogin(String login) { + this.login = login; + } + + public String getLogin() { + return login; + } + + public boolean isRecovered() { + return recovered; + } + + public void setRecovered(boolean recovered) { + this.recovered = recovered; + } +} diff --git a/wao-web/src/main/resources/i18n/wao-web_en_GB.properties b/wao-web/src/main/resources/i18n/wao-web_en_GB.properties index 98da054..303aee2 100644 --- a/wao-web/src/main/resources/i18n/wao-web_en_GB.properties +++ b/wao-web/src/main/resources/i18n/wao-web_en_GB.properties @@ -378,6 +378,8 @@ wao.ui.form.authentication.error.inactiveWaoUser=This wao user is not active. Pl wao.ui.form.authentication.error.noRoleAttributed=This wao user has no role affected. Please, contact an administrator wao.ui.form.authentication.error.userMustAcceptCgu=You must accept the end-user agreement wao.ui.form.authentication.error.wrongCredentials=Incorrect credentials +wao.ui.form.authentication.forgottenPassword.recoverButton=RESET PASSWORD +wao.ui.form.authentication.forgottenPassword.title=Reset your WAO's password wao.ui.form.authentication.title=WAO authentication wao.ui.form.boardingFrom=Boardings since wao.ui.form.boatName.placeholder=Name of boat @@ -530,6 +532,7 @@ wao.ui.page.waoUsers.titleForCompany=Users for company %s wao.ui.periodToMustBeAfterPeriodFrom=The end of the period must be after the beginning wao.ui.publishedByProgram=Pusblished by program wao.ui.publishedByYourCompany=Published by company +wao.ui.reminderSent= wao.ui.removeBoatEligibility.confirm=Are you sure you want to make this boat ineligible for sample row ? wao.ui.sampleRow.creation=Creation of a sample row wao.ui.sampleRow.edition=Edition of line %s diff --git a/wao-web/src/main/resources/i18n/wao-web_fr_FR.properties b/wao-web/src/main/resources/i18n/wao-web_fr_FR.properties index 00b2b0d..68f026d 100644 --- a/wao-web/src/main/resources/i18n/wao-web_fr_FR.properties +++ b/wao-web/src/main/resources/i18n/wao-web_fr_FR.properties @@ -379,6 +379,8 @@ wao.ui.form.authentication.error.inactiveWaoUser=Ce compte est inactif, veuillez wao.ui.form.authentication.error.noRoleAttributed=Aucun rôle n'est attribué à ce compte, veuillez contacter un responsable wao.ui.form.authentication.error.userMustAcceptCgu=Vous devez accepter les conditions générales d'utilisation wao.ui.form.authentication.error.wrongCredentials=Les informations d'authenfication ne sont pas correctes +wao.ui.form.authentication.forgottenPassword.recoverButton=RÉINITIALISER +wao.ui.form.authentication.forgottenPassword.title=Récupération de votre mot de passe WAO wao.ui.form.authentication.title=Identification WAO wao.ui.form.boardingFrom=Sollicitations du navire depuis le wao.ui.form.boatName.placeholder=Nom du bateau @@ -531,6 +533,7 @@ wao.ui.page.waoUsers.titleForCompany=Utilisateurs de la société %s wao.ui.periodToMustBeAfterPeriodFrom=La période de temps doit se terminer après avoir commencé wao.ui.publishedByProgram=Publiée par le programme wao.ui.publishedByYourCompany=Publiée par la société +wao.ui.reminderSent=Email de récupération du mot de passe envoyé, consultez votre boîte mail wao.ui.removeBoatEligibility.confirm=Êtes-vous sûr de vouloir rendre le navire inéligible pour cette ligne ? wao.ui.sampleRow.creation=Création d'une ligne du plan d'échantillonnage wao.ui.sampleRow.edition=Modification de la ligne %s diff --git a/wao-web/src/main/webapp/WEB-INF/content/authentication/forgotten-password.jsp b/wao-web/src/main/webapp/WEB-INF/content/authentication/forgotten-password.jsp new file mode 100644 index 0000000..8fa421e --- /dev/null +++ b/wao-web/src/main/webapp/WEB-INF/content/authentication/forgotten-password.jsp @@ -0,0 +1,48 @@ +<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%> +<%@taglib prefix="s" uri="/struts-tags" %> +<%@taglib prefix="sj" uri="/struts-jquery-tags" %> + +<html> + <head> + <title> + <s:text name="wao.ui.form.authentication.forgottenPassword.title" /> + </title> + </head> + <body> + + <h1> + <s:text name="wao.ui.form.authentication.forgottenPassword.title" /> + </h1> + + <s:form action="forgotten-password" namespace="/authentication" method="POST" cssClass="form-horizontal"> + + <fieldset> + <s:if test="recovered"> + <s:text name="wao.ui.reminderSent"/> + </s:if> + <s:else> + <s:textfield name="login" + label="%{getText('wao.ui.field.WaoUser.login')}"/> + </s:else> + </fieldset> + + <div class="form-actions"> + <s:if test="recovered"> + <s:url namespace="/authentication" action="login!input" id="loginUrl"> + <s:param name="login" value="login" /> + </s:url> + <s:a href="%{loginUrl}" cssClass="btn"> + <s:text name="wao.ui.form.authentication.action.submit"/> + </s:a> + </s:if> + <s:else> + <s:submit type="button" cssClass="btn btn-primary"> + <s:text name="wao.ui.form.authentication.forgottenPassword.recoverButton"/> + </s:submit> + </s:else> + </div> + + </s:form> + + </body> +</html> diff --git a/wao-web/src/main/webapp/WEB-INF/content/authentication/login.jsp b/wao-web/src/main/webapp/WEB-INF/content/authentication/login.jsp index 2e13d0a..41382b4 100644 --- a/wao-web/src/main/webapp/WEB-INF/content/authentication/login.jsp +++ b/wao-web/src/main/webapp/WEB-INF/content/authentication/login.jsp @@ -19,7 +19,7 @@ #L% --%> <%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%> -<%@taglib prefix="s" uri="/struts-tags" %> +<%@taglib prefix="s" uri="/struts-tags" %> <%@taglib prefix="sj" uri="/struts-jquery-tags" %> <html> @@ -32,6 +32,11 @@ $('input[name="login"]').focus(); }); </script> + <script type="text/javascript"> + function getLogin() { + return login = $('input[name="login"]').val(); + } + </script> </head> <body> @@ -60,6 +65,14 @@ </s:else> + <s:if test="credentialsAsked"> + <s:url namespace="/authentication" action="forgotten-password" id="recoverPasswordURL"> + </s:url> + <s:a href="%{recoverPasswordURL}"> + <s:text name="wao.ui.forgotPassword"/> + </s:a> + </s:if> + <s:if test="userProfileAsked"> <s:radio name="userProfileId" list="userProfiles" label="%{getText('wao.ui.form.authentication.chooseUserProfile')}" /> @@ -75,6 +88,13 @@ </fieldset> <div class="form-actions"> + <s:if test="credentialsAsked"> + <s:submit type="button" cssClass="btn btn-primary"> + <s:param name="userPassordReminderAsked">true</s:param> + <s:text name="wao.ui.forgotPassword"/> + </s:submit> + </s:if> + <s:submit type="button" cssClass="btn btn-primary"> <s:text name="wao.ui.form.authentication.action.submit"/> </s:submit> diff --git a/wao-web/src/main/webapp/WEB-INF/decorators.xml b/wao-web/src/main/webapp/WEB-INF/decorators.xml index 774ea9f..a6bce8d 100644 --- a/wao-web/src/main/webapp/WEB-INF/decorators.xml +++ b/wao-web/src/main/webapp/WEB-INF/decorators.xml @@ -28,6 +28,7 @@ <decorator name="layout-login" page="layout-login.jsp"> <pattern>/authentication/login*</pattern> + <pattern>/authentication/forgotten-password*</pattern> </decorator> <decorator name="layout" page="layout.jsp"> -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.