mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-18 15:33:15 +00:00
Fix account tests
This commit is contained in:
@@ -123,9 +123,12 @@ return call_user_func(function($environment = null) {
|
|||||||
} elseif ($e instanceof \Exception_NotFound) {
|
} elseif ($e instanceof \Exception_NotFound) {
|
||||||
$code = 404;
|
$code = 404;
|
||||||
$message = 'Not Found';
|
$message = 'Not Found';
|
||||||
|
} elseif($e instanceof \Exception_UnauthorizedAction) {
|
||||||
|
$code = 403;
|
||||||
|
$message = 'Forbidden';
|
||||||
} else {
|
} else {
|
||||||
$code = 500;
|
$code = 500;
|
||||||
$message = 'Server Error';
|
$message = 'Server Error' . ($app['debug'] ? ' : ' . $e->getMessage() : '');
|
||||||
}
|
}
|
||||||
|
|
||||||
return new Response($message, $code, array('X-Status-Code' => $code));
|
return new Response($message, $code, array('X-Status-Code' => $code));
|
||||||
|
@@ -11,12 +11,13 @@
|
|||||||
|
|
||||||
namespace Alchemy\Phrasea\Controller\Root;
|
namespace Alchemy\Phrasea\Controller\Root;
|
||||||
|
|
||||||
use Silex\Application;
|
use Alchemy\Phrasea\Application as PhraseaApplication;
|
||||||
use Silex\ControllerProviderInterface;
|
|
||||||
use Alchemy\Phrasea\Exception\InvalidArgumentException;
|
use Alchemy\Phrasea\Exception\InvalidArgumentException;
|
||||||
use Alchemy\Phrasea\Notification\Receiver;
|
use Alchemy\Phrasea\Notification\Receiver;
|
||||||
use Alchemy\Phrasea\Notification\Mail\MailRequestEmailUpdate;
|
use Alchemy\Phrasea\Notification\Mail\MailRequestEmailUpdate;
|
||||||
use Alchemy\Phrasea\Form\Login\PhraseaRenewPasswordForm;
|
use Alchemy\Phrasea\Form\Login\PhraseaRenewPasswordForm;
|
||||||
|
use Silex\Application;
|
||||||
|
use Silex\ControllerProviderInterface;
|
||||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||||
use Symfony\Component\HttpFoundation\Request;
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
use Symfony\Component\HttpFoundation\RedirectResponse;
|
use Symfony\Component\HttpFoundation\RedirectResponse;
|
||||||
@@ -226,9 +227,11 @@ class Account implements ControllerProviderInterface
|
|||||||
if ('POST' === $request->getMethod()) {
|
if ('POST' === $request->getMethod()) {
|
||||||
$form->bind($request);
|
$form->bind($request);
|
||||||
|
|
||||||
if($form->isValid()) {
|
if ($form->isValid()) {
|
||||||
$password = $request->request->get('password');
|
$data = $form->getData();
|
||||||
$passwordConfirm = $request->request->get('passwordConfirm');
|
|
||||||
|
$password = $data['password'];
|
||||||
|
$passwordConfirm = $data['passwordConfirm'];
|
||||||
|
|
||||||
$user = $app['authentication']->getUser();
|
$user = $app['authentication']->getUser();
|
||||||
|
|
||||||
@@ -238,19 +241,17 @@ class Account implements ControllerProviderInterface
|
|||||||
$app->addFlash('error', _('forms::la valeur donnee est trop courte'));
|
$app->addFlash('error', _('forms::la valeur donnee est trop courte'));
|
||||||
} elseif (trim($password) != str_replace(array("\r\n", "\n", "\r", "\t", " "), "_", $password)) {
|
} elseif (trim($password) != str_replace(array("\r\n", "\n", "\r", "\t", " "), "_", $password)) {
|
||||||
$app->addFlash('error', _('forms::la valeur donnee contient des caracteres invalides'));
|
$app->addFlash('error', _('forms::la valeur donnee contient des caracteres invalides'));
|
||||||
} elseif ($app['auth.password-encoder']->isPasswordValid($user->get_password(), $request->request->get('oldPassword'), $user->get_nonce())) {
|
} elseif ($app['auth.password-encoder']->isPasswordValid($user->get_password(), $data['oldPassword'], $user->get_nonce())) {
|
||||||
$user->set_password($passwordConfirm);
|
$user->set_password($passwordConfirm);
|
||||||
$app->addFlash('success', _('login::notification: Mise a jour du mot de passe avec succes'));
|
$app->addFlash('success', _('login::notification: Mise a jour du mot de passe avec succes'));
|
||||||
return $app->redirect($app->path('account'));
|
return $app->redirect($app->path('account'));
|
||||||
} else {
|
} else {
|
||||||
$app->addFlash('error', _('Password update failed'));
|
$app->addFlash('error', _('Invalid password provided'));
|
||||||
}
|
}
|
||||||
|
|
||||||
return $app->redirect($app->path('reset_password'));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $app['twig']->render('login/change-password.html.twig', array(
|
return $app['twig']->render('account/change-password.html.twig', array(
|
||||||
'form' => $form->createView(),
|
'form' => $form->createView(),
|
||||||
'login' => new \login(),
|
'login' => new \login(),
|
||||||
));
|
));
|
||||||
@@ -263,21 +264,8 @@ class Account implements ControllerProviderInterface
|
|||||||
* @param Request $request
|
* @param Request $request
|
||||||
* @return RedirectResponse
|
* @return RedirectResponse
|
||||||
*/
|
*/
|
||||||
public function resetEmail(Application $app, Request $request)
|
public function resetEmail(PhraseaApplication $app, Request $request)
|
||||||
{
|
{
|
||||||
if (null !== $token = $request->request->get('token')) {
|
|
||||||
try {
|
|
||||||
$datas = $app['tokens']->helloToken($token);
|
|
||||||
$user = \User_Adapter::getInstance((int) $datas['usr_id'], $app);
|
|
||||||
$user->set_email($datas['datas']);
|
|
||||||
$app['tokens']->removeToken($token);
|
|
||||||
|
|
||||||
return $app->redirect('/account/reset-email/?update=ok');
|
|
||||||
} catch (\Exception $e) {
|
|
||||||
return $app->redirect('/account/reset-email/?update=ko');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (null === ($password = $request->request->get('form_password'))
|
if (null === ($password = $request->request->get('form_password'))
|
||||||
|| null === ($email = $request->request->get('form_email'))
|
|| null === ($email = $request->request->get('form_email'))
|
||||||
|| null === ($emailConfirm = $request->request->get('form_email_confirm'))) {
|
|| null === ($emailConfirm = $request->request->get('form_email_confirm'))) {
|
||||||
@@ -287,16 +275,22 @@ class Account implements ControllerProviderInterface
|
|||||||
|
|
||||||
$user = $app['authentication']->getUser();
|
$user = $app['authentication']->getUser();
|
||||||
|
|
||||||
if ($app['auth.password-encoder']->isPasswordValid($user->get_password(), $password, $user->get_nonce())) {
|
if (!$app['auth.password-encoder']->isPasswordValid($user->get_password(), $password, $user->get_nonce())) {
|
||||||
return $app->redirect('/account/reset-email/?notice=bad-password');
|
$app->addFlash('error', _('admin::compte-utilisateur:ftp: Le mot de passe est errone'));
|
||||||
|
|
||||||
|
return $app->redirect($app->path('account_reset_email'));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!\Swift_Validate::email($email)) {
|
if (!\Swift_Validate::email($email)) {
|
||||||
return $app->redirect('/account/reset-email/?notice=mail-invalid');
|
$app->addFlash('error', _('forms::l\'email semble invalide'));
|
||||||
|
|
||||||
|
return $app->redirect($app->path('account_reset_email'));
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($email !== $emailConfirm) {
|
if ($email !== $emailConfirm) {
|
||||||
return $app->redirect('/account/reset-email/?notice=mail-match');
|
$app->addFlash('error', _('forms::les emails ne correspondent pas'));
|
||||||
|
|
||||||
|
return $app->redirect($app->path('account_reset_email'));
|
||||||
}
|
}
|
||||||
|
|
||||||
$date = new \DateTime('1 day');
|
$date = new \DateTime('1 day');
|
||||||
@@ -306,7 +300,9 @@ class Account implements ControllerProviderInterface
|
|||||||
try {
|
try {
|
||||||
$receiver = Receiver::fromUser($app['authentication']->getUser());
|
$receiver = Receiver::fromUser($app['authentication']->getUser());
|
||||||
} catch (InvalidArgumentException $e) {
|
} catch (InvalidArgumentException $e) {
|
||||||
return $app->redirect('/account/reset-email/?notice=mail-not-send');
|
$app->addFlash('error', _('phraseanet::erreur: echec du serveur de mail'));
|
||||||
|
|
||||||
|
return $app->redirect($app->path('account_reset_email'));
|
||||||
}
|
}
|
||||||
|
|
||||||
$mail = MailRequestEmailUpdate::create($app, $receiver, null);
|
$mail = MailRequestEmailUpdate::create($app, $receiver, null);
|
||||||
@@ -315,7 +311,9 @@ class Account implements ControllerProviderInterface
|
|||||||
|
|
||||||
$app['notification.deliverer']->deliver($mail);
|
$app['notification.deliverer']->deliver($mail);
|
||||||
|
|
||||||
return $app->redirect('/account/reset-email/?update=mail-send');
|
$app->addFlash('info', _('admin::compte-utilisateur un email de confirmation vient de vous etre envoye. Veuillez suivre les instructions contenue pour continuer'));
|
||||||
|
|
||||||
|
return $app->redirect($app->path('account'));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -327,41 +325,24 @@ class Account implements ControllerProviderInterface
|
|||||||
*/
|
*/
|
||||||
public function displayResetEmailForm(Application $app, Request $request)
|
public function displayResetEmailForm(Application $app, Request $request)
|
||||||
{
|
{
|
||||||
if (null !== $noticeMsg = $request->query->get('notice')) {
|
if (null !== $token = $request->query->get('token')) {
|
||||||
switch ($noticeMsg) {
|
try {
|
||||||
case 'mail-server':
|
$datas = $app['tokens']->helloToken($token);
|
||||||
$noticeMsg = _('phraseanet::erreur: echec du serveur de mail');
|
$user = \User_Adapter::getInstance((int) $datas['usr_id'], $app);
|
||||||
break;
|
$user->set_email($datas['datas']);
|
||||||
case 'mail-match':
|
$app['tokens']->removeToken($token);
|
||||||
$noticeMsg = _('forms::les emails ne correspondent pas');
|
|
||||||
break;
|
$app->addFlash('success', _('admin::compte-utilisateur: L\'email a correctement ete mis a jour'));
|
||||||
case 'mail-invalid':
|
|
||||||
$noticeMsg = _('forms::l\'email semble invalide');
|
return $app->redirect($app->path('account'));
|
||||||
break;
|
} catch (\Exception $e) {
|
||||||
case 'bad-password':
|
$app->addFlash('error', _('admin::compte-utilisateur: erreur lors de la mise a jour'));
|
||||||
$noticeMsg = _('admin::compte-utilisateur:ftp: Le mot de passe est errone');
|
|
||||||
break;
|
return $app->redirect($app->path('account'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (null !== $updateMsg = $request->query->get('update')) {
|
return $app['twig']->render('account/reset-email.html.twig');
|
||||||
switch ($updateMsg) {
|
|
||||||
case 'ok':
|
|
||||||
$updateMsg = _('admin::compte-utilisateur: L\'email a correctement ete mis a jour');
|
|
||||||
break;
|
|
||||||
case 'ko':
|
|
||||||
$updateMsg = _('admin::compte-utilisateur: erreur lors de la mise a jour');
|
|
||||||
break;
|
|
||||||
case 'mail-send':
|
|
||||||
$updateMsg = _('admin::compte-utilisateur un email de confirmation vient de vous etre envoye. Veuillez suivre les instructions contenue pour continuer');
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return $app['twig']->render('account/reset-email.html.twig', array(
|
|
||||||
'noticeMsg' => $noticeMsg,
|
|
||||||
'updateMsg' => $updateMsg,
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -455,27 +436,8 @@ class Account implements ControllerProviderInterface
|
|||||||
*/
|
*/
|
||||||
public function displayAccount(Application $app, Request $request)
|
public function displayAccount(Application $app, Request $request)
|
||||||
{
|
{
|
||||||
switch ($notice = $request->query->get('notice', '')) {
|
|
||||||
case 'pass-ok':
|
|
||||||
$notice = _('login::notification: Mise a jour du mot de passe avec succes');
|
|
||||||
break;
|
|
||||||
case 'pass-ko':
|
|
||||||
$notice = _('Password update failed');
|
|
||||||
break;
|
|
||||||
case 'account-update-ok':
|
|
||||||
$notice = _('login::notification: Changements enregistres');
|
|
||||||
break;
|
|
||||||
case 'account-update-bad':
|
|
||||||
$notice = _('forms::erreurs lors de l\'enregistrement des modifications');
|
|
||||||
break;
|
|
||||||
case 'demand-ok':
|
|
||||||
$notice = _('login::notification: Vos demandes ont ete prises en compte');
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $app['twig']->render('account/account.html.twig', array(
|
return $app['twig']->render('account/account.html.twig', array(
|
||||||
'user' => $app['authentication']->getUser(),
|
'user' => $app['authentication']->getUser(),
|
||||||
'notice' => $notice,
|
|
||||||
'evt_mngr' => $app['events-manager'],
|
'evt_mngr' => $app['events-manager'],
|
||||||
'notifications' => $app['events-manager']->list_notifications_available($app['authentication']->getUser()->get_id()),
|
'notifications' => $app['events-manager']->list_notifications_available($app['authentication']->getUser()->get_id()),
|
||||||
));
|
));
|
||||||
@@ -484,14 +446,12 @@ class Account implements ControllerProviderInterface
|
|||||||
/**
|
/**
|
||||||
* Update account informations
|
* Update account informations
|
||||||
*
|
*
|
||||||
* @param Application $app A Silex application where the controller is mounted on
|
* @param PhraseaApplication $app A Silex application where the controller is mounted on
|
||||||
* @param Request $request The current request
|
* @param Request $request The current request
|
||||||
* @return Response
|
* @return Response
|
||||||
*/
|
*/
|
||||||
public function updateAccount(Application $app, Request $request)
|
public function updateAccount(PhraseaApplication $app, Request $request)
|
||||||
{
|
{
|
||||||
$notice = 'account-update-bad';
|
|
||||||
|
|
||||||
$demands = (array) $request->request->get('demand', array());
|
$demands = (array) $request->request->get('demand', array());
|
||||||
|
|
||||||
if (0 !== count($demands)) {
|
if (0 !== count($demands)) {
|
||||||
@@ -500,7 +460,7 @@ class Account implements ControllerProviderInterface
|
|||||||
foreach ($demands as $baseId) {
|
foreach ($demands as $baseId) {
|
||||||
try {
|
try {
|
||||||
$register->add_request($app['authentication']->getUser(), \collection::get_from_base_id($app, $baseId));
|
$register->add_request($app['authentication']->getUser(), \collection::get_from_base_id($app, $baseId));
|
||||||
$notice = 'demand-ok';
|
$app->addFlash('success', _('login::notification: Vos demandes ont ete prises en compte'));
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -523,7 +483,8 @@ class Account implements ControllerProviderInterface
|
|||||||
'form_loginFTP',
|
'form_loginFTP',
|
||||||
'form_pwdFTP',
|
'form_pwdFTP',
|
||||||
'form_destFTP',
|
'form_destFTP',
|
||||||
'form_prefixFTPfolder'
|
'form_prefixFTPfolder',
|
||||||
|
'form_retryFTP'
|
||||||
);
|
);
|
||||||
|
|
||||||
if (0 === count(array_diff($accountFields, array_keys($request->request->all())))) {
|
if (0 === count(array_diff($accountFields, array_keys($request->request->all())))) {
|
||||||
@@ -567,10 +528,10 @@ class Account implements ControllerProviderInterface
|
|||||||
->set_ftp_dir_prefix($request->request->get("form_prefixFTPfolder"))
|
->set_ftp_dir_prefix($request->request->get("form_prefixFTPfolder"))
|
||||||
->set_defaultftpdatas($defaultDatas);
|
->set_defaultftpdatas($defaultDatas);
|
||||||
|
|
||||||
|
$app->addFlash('success', _('login::notification: Changements enregistres'));
|
||||||
$app['phraseanet.appbox']->get_connection()->commit();
|
$app['phraseanet.appbox']->get_connection()->commit();
|
||||||
|
|
||||||
$notice = 'account-update-ok';
|
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
|
$app->addFlash('error', _('forms::erreurs lors de l\'enregistrement des modifications'));
|
||||||
$app['phraseanet.appbox']->get_connection()->rollBack();
|
$app['phraseanet.appbox']->get_connection()->rollBack();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -590,7 +551,7 @@ class Account implements ControllerProviderInterface
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $app->redirect(sprintf('/account/?notice=%s', $notice), 201);
|
return $app->redirect($app->path('account'));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -409,6 +409,8 @@ class User_Adapter implements User_Interface, cache_cacheableInterface
|
|||||||
$stmt->execute(array(':password' => $password, ':usr_id' => $this->get_id()));
|
$stmt->execute(array(':password' => $password, ':usr_id' => $this->get_id()));
|
||||||
$stmt->closeCursor();
|
$stmt->closeCursor();
|
||||||
|
|
||||||
|
$this->password = $password;
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
{% extends "account/base.html.twig" %}
|
{% extends "account/base.html.twig" %}
|
||||||
|
|
||||||
{% import "login/common/macros.html.twig" as auth_macro %}
|
{% import "common/macros.html.twig" as auth_macro %}
|
||||||
|
|
||||||
{% set selected = "informations" %}
|
{% set selected = "informations" %}
|
||||||
|
|
||||||
@@ -20,10 +20,6 @@
|
|||||||
{% block content %}
|
{% block content %}
|
||||||
<div class="row-fluid">
|
<div class="row-fluid">
|
||||||
<div class="span12">
|
<div class="span12">
|
||||||
{% if notice | trim != "" %}
|
|
||||||
<div class="alert alert-error">{{ notice }}</div>
|
|
||||||
{% endif %}
|
|
||||||
|
|
||||||
{{ auth_macro.flashes() }}
|
{{ auth_macro.flashes() }}
|
||||||
|
|
||||||
<form name="account" id="account" class="form-horizontal" action="{{ path("submit_update_account") }}" method="post">
|
<form name="account" id="account" class="form-horizontal" action="{{ path("submit_update_account") }}" method="post">
|
||||||
@@ -40,7 +36,7 @@
|
|||||||
<div class="control-group">
|
<div class="control-group">
|
||||||
<label class="form_label control-label" for="form_gender"><strong>{% trans "admin::compte-utilisateur sexe" %}</strong></label>
|
<label class="form_label control-label" for="form_gender"><strong>{% trans "admin::compte-utilisateur sexe" %}</strong></label>
|
||||||
<div class="controls">
|
<div class="controls">
|
||||||
<select class="input-xlarge">
|
<select name="form_gender" class="input-xlarge">
|
||||||
<option {% if app["authentication"].getUser().get_gender() == "0" %}selected{% endif %} value="0" >
|
<option {% if app["authentication"].getUser().get_gender() == "0" %}selected{% endif %} value="0" >
|
||||||
{% trans "admin::compte-utilisateur:sexe: mademoiselle" %}
|
{% trans "admin::compte-utilisateur:sexe: mademoiselle" %}
|
||||||
</option>
|
</option>
|
||||||
|
@@ -1,5 +1,6 @@
|
|||||||
{% extends "login/layout/sidebar-layout.html.twig" %}
|
{% extends "login/layout/sidebar-layout.html.twig" %}
|
||||||
|
|
||||||
|
{% import "common/macros.html.twig" as account_macro %}
|
||||||
{% import "login/common/macros.html.twig" as auth_macro %}
|
{% import "login/common/macros.html.twig" as auth_macro %}
|
||||||
|
|
||||||
{% block title %}
|
{% block title %}
|
||||||
@@ -17,7 +18,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="row-fluid">
|
<div class="row-fluid">
|
||||||
<div class="span12">
|
<div class="span12">
|
||||||
{{ auth_macro.flashes() }}
|
{{ account_macro.flashes() }}
|
||||||
<form
|
<form
|
||||||
ng-controller="passwordChangeFormCtrl"
|
ng-controller="passwordChangeFormCtrl"
|
||||||
novalidate
|
novalidate
|
@@ -1,5 +1,7 @@
|
|||||||
{% extends "account/base.html.twig" %}
|
{% extends "account/base.html.twig" %}
|
||||||
|
|
||||||
|
{% import "common/macros.html.twig" as auth_macro %}
|
||||||
|
|
||||||
{% block title %}
|
{% block title %}
|
||||||
{% trans "Change my email address" %}
|
{% trans "Change my email address" %}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
@@ -48,62 +50,48 @@ $(document).ready(function() {
|
|||||||
{% set selected = "" %}
|
{% set selected = "" %}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
|
<div class="row-fluid">
|
||||||
{% if updateMsg is not none %}
|
<div class="span12">
|
||||||
<div class="alert alert-info">
|
{{ auth_macro.flashes() }}
|
||||||
<div>{{ updateMsg }}</div>
|
<form method="POST" action="{{ path("reset_email") }}" id="mainform" class="form-horizontal">
|
||||||
<a href="{{ path("account") }}" target="_self">{% trans "admin::compte-utilisateur retour a mon compte"%}</a>
|
<div class="control-group">
|
||||||
</div>
|
<label class="form_label control-label" for="form_login">{% trans "admin::compte-utilisateur identifiant" %}</label>
|
||||||
{% else %}
|
<div class="controls">
|
||||||
|
<p style="line-height: 30px;">{{ app["authentication"].getUser().get_login() }}</p>
|
||||||
{% if noticeMsg is not none %}
|
<p class="form_alert help-block"></p>
|
||||||
<div class="notice" style="text-align:center;margin:20px 0">
|
</div>
|
||||||
{% trans "phraseanet::erreur : oups ! une erreur est survenue pendant l\'operation !" %}
|
</div>
|
||||||
</div>
|
<div class="control-group">
|
||||||
<div class="notice" style="text-align:center;margin:20px 0">
|
<label class="form_label control-label" for="form_password">{% trans "admin::compte-utilisateur mot de passe" %}</label>
|
||||||
{{ noticeMsg }}
|
<div class="controls">
|
||||||
</div>
|
<input type="password" id="form_password" name="form_password" autocomplete="off" />
|
||||||
<a href="{{ path("reset_password") }}" target="_self">{% trans "admin::compte-utilisateur retour a mon compte" %}</a>
|
{#<p class="form_alert help-block"><?php echo isset($needed["form_password"]) ? $needed["form_password"] : "" ?></p>#}
|
||||||
{% endif %}
|
</div>
|
||||||
|
</div>
|
||||||
<form method="POST" action="{{ path("reset_email") }}" id="mainform" class="form-horizontal">
|
<div class="control-group">
|
||||||
<div class="control-group">
|
<label class="form_label control-label" for="form_email">{% trans "admin::compte-utilisateur nouvelle adresse email" %}</label>
|
||||||
<label class="form_label control-label" for="form_login">{% trans "admin::compte-utilisateur identifiant" %}</label>
|
<div class="controls">
|
||||||
<div class="controls">
|
<input type="text" id="form_email" name="form_email" />
|
||||||
<p style="line-height: 30px;">{{ app["authentication"].getUser().get_login() }}</p>
|
{#<p class="form_alert help-block"><?php echo isset($needed["form_email"]) ? $needed["form_email"] : "" ?></p>#}
|
||||||
<p class="form_alert help-block"></p>
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="control-group">
|
||||||
|
<label class="form_label control-label" for="form_email_confirm">{% trans "admin::compte-utilisateur confirmer la nouvelle adresse email" %}</label>
|
||||||
|
<div class="controls">
|
||||||
|
<input type="text" id="form_email_confirm" name="form_email_confirm" autocomplete="off" />
|
||||||
|
{#<p class="form_alert help-block"><?php echo isset($needed["form_email_confirm"]) ? $needed["form_email_confirm"] : "" ?></p>#}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="form-actions" style="background-color: transparent;">
|
||||||
|
<input type="submit" class="btn btn-success" value="{% trans "boutton::valider" %}" style="margin: 20px auto;" />
|
||||||
|
<input type="button" class="btn" value="{% trans "boutton::annuler" %}" onclick="self.location.replace('/account/');" />
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
<div class="well well-small alert-info">
|
||||||
|
{% trans "admin::compte-utilisateur: Pourquoi me demande-t-on mon mot de passe pour changer mon adresse email ?"%}
|
||||||
|
<br />
|
||||||
|
{% trans "admin::compte-utilisateur: Votre adresse e-mail sera utilisee lors de la perte de votre mot de passe afin de pouvoir le reinitialiser, il est important que vous soyez la seule personne a pouvoir la changer."%}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="control-group">
|
|
||||||
<label class="form_label control-label" for="form_password">{% trans "admin::compte-utilisateur mot de passe" %}</label>
|
|
||||||
<div class="controls">
|
|
||||||
<input type="password" id="form_password" name="form_password" autocomplete="off" />
|
|
||||||
{#<p class="form_alert help-block"><?php echo isset($needed["form_password"]) ? $needed["form_password"] : "" ?></p>#}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="control-group">
|
|
||||||
<label class="form_label control-label" for="form_email">{% trans "admin::compte-utilisateur nouvelle adresse email" %}</label>
|
|
||||||
<div class="controls">
|
|
||||||
<input type="text" id="form_email" name="form_email" />
|
|
||||||
{#<p class="form_alert help-block"><?php echo isset($needed["form_email"]) ? $needed["form_email"] : "" ?></p>#}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="control-group">
|
|
||||||
<label class="form_label control-label" for="form_email_confirm">{% trans "admin::compte-utilisateur confirmer la nouvelle adresse email" %}</label>
|
|
||||||
<div class="controls">
|
|
||||||
<input type="text" id="form_email_confirm" name="form_email_confirm" autocomplete="off" />
|
|
||||||
{#<p class="form_alert help-block"><?php echo isset($needed["form_email_confirm"]) ? $needed["form_email_confirm"] : "" ?></p>#}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="form-actions" style="background-color: transparent;">
|
|
||||||
<input type="submit" class="btn btn-success" value="{% trans "boutton::valider" %}" style="margin: 20px auto;" />
|
|
||||||
<input type="button" class="btn" value="{% trans "boutton::annuler" %}" onclick="self.location.replace('/account/');" />
|
|
||||||
</div>
|
|
||||||
</form>
|
|
||||||
<div class="well well-small alert-info">
|
|
||||||
{% trans "admin::compte-utilisateur: Pourquoi me demande-t-on mon mot de passe pour changer mon adresse email ?"%}
|
|
||||||
<br />
|
|
||||||
{% trans "admin::compte-utilisateur: Votre adresse e-mail sera utilisee lors de la perte de votre mot de passe afin de pouvoir le reinitialiser, il est important que vous soyez la seule personne a pouvoir la changer."%}
|
|
||||||
</div>
|
</div>
|
||||||
{% endif %}
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
@@ -59,3 +59,23 @@
|
|||||||
<input type="hidden" name="recaptcha_response_field" value="manual_challenge">
|
<input type="hidden" name="recaptcha_response_field" value="manual_challenge">
|
||||||
</noscript>
|
</noscript>
|
||||||
{% endmacro %}
|
{% endmacro %}
|
||||||
|
|
||||||
|
{% macro flashes() %}
|
||||||
|
{% for type in ["warning", "info", "success", "error"] %}
|
||||||
|
{% for message in app.getFlash(type) %}
|
||||||
|
<div class="alert alert-{{ type }}">
|
||||||
|
<table>
|
||||||
|
<tr>
|
||||||
|
<td class="alert-block-logo">
|
||||||
|
<i class="icon-2x icon-white icon-exclamation-sign"></i>
|
||||||
|
</td>
|
||||||
|
<td class="alert-block-content">{{ message }}</td>
|
||||||
|
<td class="alert-block-close">
|
||||||
|
<a href="#"><b>×</b></a>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
{% endfor %}
|
||||||
|
{% endfor %}
|
||||||
|
{% endmacro %}
|
@@ -48,30 +48,18 @@ class AccountTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dataProvider msgProvider
|
* @dataProvider noticeProvider
|
||||||
*/
|
*/
|
||||||
public function testGetAccountNotice($msg)
|
public function testGetAccountNotice($type, $message)
|
||||||
{
|
{
|
||||||
$crawler = self::$DI['client']->request('GET', '/account/', array(
|
self::$DI['app']->addFlash($type, $message);
|
||||||
'notice' => $msg
|
$crawler = self::$DI['client']->request('GET', '/account/');
|
||||||
));
|
|
||||||
|
|
||||||
$response = self::$DI['client']->getResponse();
|
$response = self::$DI['client']->getResponse();
|
||||||
|
|
||||||
$this->assertTrue($response->isOk());
|
$this->assertTrue($response->isOk());
|
||||||
|
|
||||||
$this->assertEquals(1, $crawler->filter('.notice')->count());
|
$this->assertFlashMessage($crawler, $type, 1, $message);
|
||||||
}
|
|
||||||
|
|
||||||
public function msgProvider()
|
|
||||||
{
|
|
||||||
return array(
|
|
||||||
array('pass-ok'),
|
|
||||||
array('pass-ko'),
|
|
||||||
array('account-update-ok'),
|
|
||||||
array('account-update-bad'),
|
|
||||||
array('demand-ok'),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -89,33 +77,37 @@ class AccountTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
|
|||||||
/**
|
/**
|
||||||
* @covers \Alchemy\Phrasea\Controller\Root\Account::resetEmail
|
* @covers \Alchemy\Phrasea\Controller\Root\Account::resetEmail
|
||||||
*/
|
*/
|
||||||
public function testPostResetMailWithToken()
|
public function testGetResetMailWithToken()
|
||||||
{
|
{
|
||||||
$token = self::$DI['app']['tokens']->getUrlToken(\random::TYPE_EMAIL, self::$DI['user']->get_id(), null, 'new_email@email.com');
|
$token = self::$DI['app']['tokens']->getUrlToken(\random::TYPE_EMAIL, self::$DI['user']->get_id(), null, 'new_email@email.com');
|
||||||
self::$DI['client']->request('POST', '/account/reset-email/', array('token' => $token));
|
$crawler = self::$DI['client']->request('GET', '/account/reset-email/', array('token' => $token));
|
||||||
$response = self::$DI['client']->getResponse();
|
$response = self::$DI['client']->getResponse();
|
||||||
$this->assertTrue($response->isRedirect());
|
$this->assertTrue($response->isRedirect());
|
||||||
$this->assertEquals('/account/reset-email/?update=ok', $response->headers->get('location'));
|
$this->assertEquals('/account/', $response->headers->get('location'));
|
||||||
|
|
||||||
$this->assertEquals('new_email@email.com', self::$DI['user']->get_email());
|
$this->assertEquals('new_email@email.com', self::$DI['user']->get_email());
|
||||||
self::$DI['user']->set_email('noone@example.com');
|
self::$DI['user']->set_email('noone@example.com');
|
||||||
try {
|
try {
|
||||||
self::$DI['app']['tokens']->helloToken($token);
|
self::$DI['app']['tokens']->helloToken($token);
|
||||||
$this->fail('TOken has not been removed');
|
$this->fail('Token has not been removed');
|
||||||
} catch (\Exception_NotFound $e) {
|
} catch (\Exception_NotFound $e) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$this->assertFlashMessagePopulated(self::$DI['app'], 'success', 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @covers \Alchemy\Phrasea\Controller\Root\Account::resetEmail
|
* @covers \Alchemy\Phrasea\Controller\Root\Account::resetEmail
|
||||||
*/
|
*/
|
||||||
public function testPostResetMailWithBadToken()
|
public function testGetResetMailWithBadToken()
|
||||||
{
|
{
|
||||||
self::$DI['client']->request('POST', '/account/reset-email/', array('token' => '134dT0k3n'));
|
self::$DI['client']->request('GET', '/account/reset-email/', array('token' => '134dT0k3n'));
|
||||||
$response = self::$DI['client']->getResponse();
|
$response = self::$DI['client']->getResponse();
|
||||||
$this->assertTrue($response->isRedirect());
|
$this->assertTrue($response->isRedirect());
|
||||||
$this->assertEquals('/account/reset-email/?update=ko', $response->headers->get('location'));
|
$this->assertEquals('/account/', $response->headers->get('location'));
|
||||||
|
|
||||||
|
$this->assertFlashMessagePopulated(self::$DI['app'], 'error', 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -141,7 +133,9 @@ class AccountTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
|
|||||||
|
|
||||||
$response = self::$DI['client']->getResponse();
|
$response = self::$DI['client']->getResponse();
|
||||||
$this->assertTrue($response->isRedirect());
|
$this->assertTrue($response->isRedirect());
|
||||||
$this->assertEquals('/account/reset-email/?notice=bad-password', $response->headers->get('location'));
|
$this->assertEquals('/account/reset-email/', $response->headers->get('location'));
|
||||||
|
|
||||||
|
$this->assertFlashMessagePopulated(self::$DI['app'], 'error', 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -159,7 +153,9 @@ class AccountTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
|
|||||||
|
|
||||||
$response = self::$DI['client']->getResponse();
|
$response = self::$DI['client']->getResponse();
|
||||||
$this->assertTrue($response->isRedirect());
|
$this->assertTrue($response->isRedirect());
|
||||||
$this->assertEquals('/account/reset-email/?notice=mail-invalid', $response->headers->get('location'));
|
$this->assertEquals('/account/reset-email/', $response->headers->get('location'));
|
||||||
|
|
||||||
|
$this->assertFlashMessagePopulated(self::$DI['app'], 'error', 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -177,7 +173,9 @@ class AccountTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
|
|||||||
|
|
||||||
$response = self::$DI['client']->getResponse();
|
$response = self::$DI['client']->getResponse();
|
||||||
$this->assertTrue($response->isRedirect());
|
$this->assertTrue($response->isRedirect());
|
||||||
$this->assertEquals('/account/reset-email/?notice=mail-match', $response->headers->get('location'));
|
$this->assertEquals('/account/reset-email/', $response->headers->get('location'));
|
||||||
|
|
||||||
|
$this->assertFlashMessagePopulated(self::$DI['app'], 'error', 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -197,53 +195,31 @@ class AccountTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
|
|||||||
|
|
||||||
$response = self::$DI['client']->getResponse();
|
$response = self::$DI['client']->getResponse();
|
||||||
$this->assertTrue($response->isRedirect());
|
$this->assertTrue($response->isRedirect());
|
||||||
$this->assertEquals('/account/reset-email/?update=mail-send', $response->headers->get('location'));
|
$this->assertEquals('/account/', $response->headers->get('location'));
|
||||||
|
|
||||||
|
$this->assertFlashMessagePopulated(self::$DI['app'], 'info', 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dataProvider noticeProvider
|
* @dataProvider noticeProvider
|
||||||
*/
|
*/
|
||||||
public function testGetResetMailNotice($notice)
|
public function testGetResetMailNotice($type, $message)
|
||||||
{
|
{
|
||||||
$crawler = self::$DI['client']->request('GET', '/account/reset-email/', array(
|
self::$DI['app']->addFlash($type, $message);
|
||||||
'notice' => $notice
|
|
||||||
));
|
$crawler = self::$DI['client']->request('GET', '/account/reset-email/');
|
||||||
|
|
||||||
$this->assertTrue(self::$DI['client']->getResponse()->isOk());
|
$this->assertTrue(self::$DI['client']->getResponse()->isOk());
|
||||||
|
|
||||||
$this->assertEquals(2, $crawler->filter('.notice')->count());
|
$this->assertFlashMessage($crawler, $type, 1, $message);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function noticeProvider()
|
public function noticeProvider()
|
||||||
{
|
{
|
||||||
return array(
|
return array(
|
||||||
array('mail-server'),
|
array('error', 'An error occured'),
|
||||||
array('mail-match'),
|
array('info', 'You need to do something more'),
|
||||||
array('mail-invalid'),
|
array('success', "Success operation !"),
|
||||||
array('bad-password'),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @dataProvider updateMsgProvider
|
|
||||||
*/
|
|
||||||
public function testGetResetMailUpdate($updateMessage)
|
|
||||||
{
|
|
||||||
$crawler = self::$DI['client']->request('GET', '/account/reset-email/', array(
|
|
||||||
'update' => $updateMessage
|
|
||||||
));
|
|
||||||
|
|
||||||
$this->assertTrue(self::$DI['client']->getResponse()->isOk());
|
|
||||||
|
|
||||||
$this->assertEquals(1, $crawler->filter('.alert-info')->count());
|
|
||||||
}
|
|
||||||
|
|
||||||
public function updateMsgProvider()
|
|
||||||
{
|
|
||||||
return array(
|
|
||||||
array('ok'),
|
|
||||||
array('ko'),
|
|
||||||
array('mail-send'),
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -284,28 +260,19 @@ class AccountTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dataProvider passwordMsgProvider
|
* @dataProvider noticeProvider
|
||||||
*/
|
*/
|
||||||
public function testGetResetPasswordPassError($msg)
|
public function testGetResetPasswordPassError($type, $message)
|
||||||
{
|
{
|
||||||
$crawler = self::$DI['client']->request('GET', '/account/reset-password/', array(
|
self::$DI['app']->addFlash($type, $message);
|
||||||
'pass-error' => $msg
|
|
||||||
));
|
$crawler = self::$DI['client']->request('GET', '/account/reset-password/');
|
||||||
|
|
||||||
$response = self::$DI['client']->getResponse();
|
$response = self::$DI['client']->getResponse();
|
||||||
|
|
||||||
$this->assertTrue($response->isOk());
|
$this->assertTrue($response->isOk());
|
||||||
|
|
||||||
$this->assertEquals(1, $crawler->filter('.alert-error')->count());
|
$this->assertFlashMessage($crawler, $type, 1, $message);
|
||||||
}
|
|
||||||
|
|
||||||
public function passwordMsgProvider()
|
|
||||||
{
|
|
||||||
return array(
|
|
||||||
array('pass-match'),
|
|
||||||
array('pass-short'),
|
|
||||||
array('pass-invalid'),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -434,34 +401,35 @@ class AccountTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
|
|||||||
/**
|
/**
|
||||||
* @dataProvider passwordProvider
|
* @dataProvider passwordProvider
|
||||||
*/
|
*/
|
||||||
public function testPostRenewPasswordBadArguments($oldPassword, $password, $passwordConfirm, $redirect)
|
public function testPostRenewPasswordBadArguments($oldPassword, $password, $passwordConfirm)
|
||||||
{
|
{
|
||||||
self::$DI['app']['authentication']->getUser()->set_password($oldPassword);
|
self::$DI['app']['authentication']->getUser()->set_password($oldPassword);
|
||||||
|
|
||||||
self::$DI['client']->request('POST', '/account/reset-password/', array(
|
$crawler = self::$DI['client']->request('POST', '/account/reset-password/', array(
|
||||||
'form_password' => $password,
|
'password' => $password,
|
||||||
'form_password_confirm' => $passwordConfirm,
|
'passwordConfirm' => $passwordConfirm,
|
||||||
'form_old_password' => $oldPassword
|
'oldPassword' => $oldPassword,
|
||||||
|
'_token' => 'token',
|
||||||
));
|
));
|
||||||
|
|
||||||
$response = self::$DI['client']->getResponse();
|
$response = self::$DI['client']->getResponse();
|
||||||
|
|
||||||
$this->assertTrue($response->isRedirect());
|
$this->assertFalse($response->isRedirect());
|
||||||
$this->assertEquals($redirect, $response->headers->get('location'));
|
$this->assertFlashMessage($crawler, 'error', 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testPostRenewPasswordBadOldPassword()
|
public function testPostRenewPasswordBadOldPassword()
|
||||||
{
|
{
|
||||||
self::$DI['client']->request('POST', '/account/reset-password/', array(
|
$crawler = self::$DI['client']->request('POST', '/account/reset-password/', array(
|
||||||
'form_password' => 'password',
|
'password' => 'password',
|
||||||
'form_password_confirm' => 'password',
|
'passwordConfirm' => 'password',
|
||||||
'form_old_password' => 'oulala'
|
'oldPassword' => 'oulala',
|
||||||
|
'_token' => 'token',
|
||||||
));
|
));
|
||||||
|
|
||||||
$response = self::$DI['client']->getResponse();
|
$response = self::$DI['client']->getResponse();
|
||||||
|
$this->assertFalse($response->isRedirect());
|
||||||
$this->assertTrue($response->isRedirect());
|
$this->assertFlashMessage($crawler, 'error', 1);
|
||||||
$this->assertEquals('/account/?notice=pass-ko', $response->headers->get('location'));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testPostRenewPassword()
|
public function testPostRenewPassword()
|
||||||
@@ -471,23 +439,25 @@ class AccountTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
|
|||||||
self::$DI['app']['authentication']->getUser()->set_password($password);
|
self::$DI['app']['authentication']->getUser()->set_password($password);
|
||||||
|
|
||||||
self::$DI['client']->request('POST', '/account/reset-password/', array(
|
self::$DI['client']->request('POST', '/account/reset-password/', array(
|
||||||
'form_password' => 'password',
|
'password' => 'password',
|
||||||
'form_password_confirm' => 'password',
|
'passwordConfirm' => 'password',
|
||||||
'form_old_password' => $password
|
'oldPassword' => $password,
|
||||||
|
'_token' => 'token',
|
||||||
));
|
));
|
||||||
|
|
||||||
$response = self::$DI['client']->getResponse();
|
$response = self::$DI['client']->getResponse();
|
||||||
|
|
||||||
$this->assertTrue($response->isRedirect());
|
$this->assertTrue($response->isRedirect());
|
||||||
$this->assertEquals('/account/?notice=pass-ok', $response->headers->get('location'));
|
$this->assertEquals('/account/', $response->headers->get('location'));
|
||||||
|
|
||||||
|
$this->assertFlashMessagePopulated(self::$DI['app'], 'success', 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function passwordProvider()
|
public function passwordProvider()
|
||||||
{
|
{
|
||||||
return array(
|
return array(
|
||||||
array(\random::generatePassword(), 'password', 'not_identical_password', '/account/reset-password/?pass-error=pass-match'),
|
array(\random::generatePassword(), 'password', 'not_identical_password'),
|
||||||
array(\random::generatePassword(), 'min', 'min', '/account/reset-password/?pass-error=pass-short'),
|
array(\random::generatePassword(), "invalid\n", "invalid\n"),
|
||||||
array(\random::generatePassword(), 'invalid password \n', 'invalid password \n', '/account/reset-password/?pass-error=pass-invalid'),
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user