diff --git a/lib/Alchemy/Phrasea/Controller/Root/Account.php b/lib/Alchemy/Phrasea/Controller/Root/Account.php index cb23bee256..eb8ea1e337 100644 --- a/lib/Alchemy/Phrasea/Controller/Root/Account.php +++ b/lib/Alchemy/Phrasea/Controller/Root/Account.php @@ -93,18 +93,13 @@ class Account implements ControllerProviderInterface $data = $form->getData(); $password = $data['password']; - $passwordConfirm = $data['passwordConfirm']; $user = $app['authentication']->getUser(); - if ($password !== $passwordConfirm) { - $app->addFlash('error', _('forms::les mots de passe ne correspondent pas')); - } elseif (strlen(trim($password)) < 5) { - $app->addFlash('error', _('forms::la valeur donnee est trop courte')); - } elseif (trim($password) != str_replace(array("\r\n", "\n", "\r", "\t", " "), "_", $password)) { + if (trim($password) != str_replace(array("\r\n", "\n", "\r", "\t", " "), "_", $password)) { $app->addFlash('error', _('forms::la valeur donnee contient des caracteres invalides')); } elseif ($app['auth.password-encoder']->isPasswordValid($user->get_password(), $data['oldPassword'], $user->get_nonce())) { - $user->set_password($passwordConfirm); + $user->set_password($password); $app->addFlash('success', _('login::notification: Mise a jour du mot de passe avec succes')); return $app->redirectPath('account'); diff --git a/templates/web/account/change-password.html.twig b/templates/web/account/change-password.html.twig index 69833116d6..3fe7963ec9 100644 --- a/templates/web/account/change-password.html.twig +++ b/templates/web/account/change-password.html.twig @@ -20,13 +20,10 @@
{{ account_macro.flashes() }}
@@ -38,22 +35,9 @@ {{ auth_macro.fieldInput(form.oldPassword, "passwordChangeForm", 'icon-lock') }}
-
-
- {{ auth_macro.fieldInput(form.password, "passwordChangeForm", 'icon-lock') }} -
-
-
-
- {{ auth_macro.fieldInput(form.passwordConfirm, "passwordChangeForm", 'icon-lock', { - "ui-validate" : " '$value==" ~ form.password.vars.name ~ "' ", - "ui-validate-watch" : "'" ~ form.password.vars.name ~ "'" - }, { - "validate_message" : "Passwords do not match"|trans - }) - }} -
-
+ + {{ auth_macro.repeatedInput(form.password, "passwordChangeForm", 'icon-lock') }} + {{ form_rest(form) }}
@@ -67,3 +51,8 @@
{% endblock %} + +{% block scripts %} + {{ parent() }} + +{% endblock %} diff --git a/templates/web/login/renew-password.html.twig b/templates/web/login/renew-password.html.twig index 3100ac1fd4..c2e0a9cb0a 100644 --- a/templates/web/login/renew-password.html.twig +++ b/templates/web/login/renew-password.html.twig @@ -50,5 +50,5 @@ {% block scripts %} {{ parent() }} - + {% endblock %} diff --git a/tests/Alchemy/Tests/Phrasea/Controller/Root/AccountTest.php b/tests/Alchemy/Tests/Phrasea/Controller/Root/AccountTest.php index 390f079a34..e020dd2af2 100644 --- a/tests/Alchemy/Tests/Phrasea/Controller/Root/AccountTest.php +++ b/tests/Alchemy/Tests/Phrasea/Controller/Root/AccountTest.php @@ -398,8 +398,10 @@ class AccountTest extends \PhraseanetWebTestCaseAuthenticatedAbstract self::$DI['app']['authentication']->getUser()->set_password($oldPassword); $crawler = self::$DI['client']->request('POST', '/account/reset-password/', array( - 'password' => $password, - 'passwordConfirm' => $passwordConfirm, + 'password' => array( + 'password' => $password, + 'confirm' => $passwordConfirm + ), 'oldPassword' => $oldPassword, '_token' => 'token', )); @@ -407,14 +409,16 @@ class AccountTest extends \PhraseanetWebTestCaseAuthenticatedAbstract $response = self::$DI['client']->getResponse(); $this->assertFalse($response->isRedirect()); - $this->assertFlashMessage($crawler, 'error', 1); + $this->assertFormOrFlashError($crawler, 1); } public function testPostRenewPasswordBadOldPassword() { $crawler = self::$DI['client']->request('POST', '/account/reset-password/', array( - 'password' => 'password', - 'passwordConfirm' => 'password', + 'password' => array( + 'password' => 'password', + 'confirm' => 'password' + ), 'oldPassword' => 'oulala', '_token' => 'token', )); @@ -431,8 +435,10 @@ class AccountTest extends \PhraseanetWebTestCaseAuthenticatedAbstract self::$DI['app']['authentication']->getUser()->set_password($password); $crawler = self::$DI['client']->request('POST', '/account/reset-password/', array( - 'password' => 'password', - 'passwordConfirm' => 'password', + 'password' => array( + 'password' => 'password', + 'confirm' => 'password' + ), 'oldPassword' => $password, )); @@ -449,8 +455,10 @@ class AccountTest extends \PhraseanetWebTestCaseAuthenticatedAbstract self::$DI['app']['authentication']->getUser()->set_password($password); self::$DI['client']->request('POST', '/account/reset-password/', array( - 'password' => 'password', - 'passwordConfirm' => 'password', + 'password' => array( + 'password' => 'password', + 'confirm' => 'password' + ), 'oldPassword' => $password, '_token' => 'token', )); diff --git a/www/scripts/apps/login/home/recoverPassword.js b/www/scripts/apps/login/home/recoverPassword.js new file mode 100644 index 0000000000..85c00ac991 --- /dev/null +++ b/www/scripts/apps/login/home/recoverPassword.js @@ -0,0 +1,42 @@ +/* + * This file is part of Phraseanet + * + * (c) 2005-2013 Alchemy + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +require([ + "jquery", + "i18n", + "apps/login/home/common", + "apps/login/home/views/form" +], function($, i18n, Common, RenewPassword) { + i18n.init({ + resGetPath: Common.languagePath, + useLocalStorage: true + }, function() { + Common.initialize(); + + new RenewPassword({ + el : $("form[name=passwordRenewForm]"), + rules: [{ + name: "password[password]", + rules: "required", + message: i18n.t("validation_blank") + },{ + name: "password[password]", + rules: "min_length[5]", + message: i18n.t("validation_length_min", { + postProcess: "sprintf", + sprintf: ["5"] + }) + },{ + name: "password[confirm]", + rules: "matches[password[password]]", + message: i18n.t("password_match") + }] + }); + }); +}); diff --git a/www/scripts/apps/login/home/renewPassword.js b/www/scripts/apps/login/home/renewPassword.js index 469770b8d5..06c4844ccf 100644 --- a/www/scripts/apps/login/home/renewPassword.js +++ b/www/scripts/apps/login/home/renewPassword.js @@ -20,7 +20,7 @@ require([ Common.initialize(); new RenewPassword({ - el : $("form[name=passwordRenewForm]"), + el : $("form[name=passwordChangeForm]"), rules: [{ name: "oldPassword", rules: "required",