Skip to content
Snippets Groups Projects
Commit d461d202 authored by Laurent's avatar Laurent
Browse files

Merge branch 'hotline#96483_lien_de_reinitialisation_mdp' into 'hotline'

Hotline#96483 lien de reinitialisation mdp

See merge request !3246
parents 5fe28402 7df2a18d
Branches
Tags
3 merge requests!3297WIP: Master,!3252Hotline,!3246Hotline#96483 lien de reinitialisation mdp
Pipeline #8333 failed with stage
in 35 minutes and 58 seconds
- ticket #96483 : Compte utilisateur : Les liens de réinitialisation de mot de passe envoyés par courriel expirent désormais en 24h
\ No newline at end of file
......@@ -76,17 +76,7 @@ class Class_Mail {
if (!$this->isMailValid($destinataire))
return $this->_("L'adresse e-mail du destinataire est incorrecte.");
// Fusion
if($data)
{
foreach($data as $var => $valeur)
{
$var="{".$var."}";
$body=str_replace($var,$valeur,$body);
}
}
$body = wordwrap($body, 60);
$body = $this->_injectDatasInto($data, $body);
$statut = $this->mail($destinataire, $sujet, $body);
......@@ -96,6 +86,17 @@ class Class_Mail {
}
protected function _injectDatasInto($data, $body) {
if (!$data)
return $body;
foreach ($data as $name => $value)
$body = str_replace('{' . $name . '}', $value, $body);
return $body;
}
public function isMailValid($mail) {
$validator = new Zend_Validate_EmailAddress();
return $validator->isValid($mail);
......@@ -105,4 +106,4 @@ class Class_Mail {
public function getMailFrom() {
return $this->mail_from;
}
}
\ No newline at end of file
}
......@@ -24,7 +24,7 @@ class Class_User_LostPass {
use Trait_TimeSource, Trait_Translator;
const MAX_MINUTES = 30;
const MAX_HOURS = 24;
const TOKEN_SEPARATOR = '@';
const TOKEN_DATE_FORMAT = 'YmdHis';
......@@ -56,7 +56,7 @@ class Class_User_LostPass {
public function tokenHasExpiredFrom($date) {
$from = DateTime::createFromFormat(static::TOKEN_DATE_FORMAT, $date);
$now = new DateTime($this->getCurrentDateTime());
$from->add(new DateInterval('PT' . static::MAX_MINUTES . 'M'));
$from->add(new DateInterval('PT' . static::MAX_HOURS . 'H'));
return $from < $now;
}
......@@ -141,9 +141,9 @@ class Class_User_LostPassResetLink extends Class_User_LostPassSender{
'id' => $user->getId(),
'token' => $token,
'created' => $created_at_part], null, true))
. $this->_("ATTENTION : ce lien créé à %s est valide pendant %s minutes\n",
. $this->_("ATTENTION : ce lien créé à %s est valide pendant %s heures\n",
date('H:i', $created_at),
Class_User_LostPass::MAX_MINUTES)
Class_User_LostPass::MAX_HOURS)
. sprintf("%s\n\n", $this->_('Bonne navigation sur le portail'));
}
......
......@@ -96,7 +96,7 @@ class AuthControllerLostPasswordActionTest extends AuthControllerLostPasswordTes
class AuthControllerLostPasswordValidPostTest extends AuthControllerLostPasswordTestCase {
protected $_mail_transport;
protected $_mail_transport, $_mail;
public function setUp() {
parent::setUp();
......@@ -124,19 +124,27 @@ class AuthControllerLostPasswordValidPostTest extends AuthControllerLostPassword
$user->beAbonneSIGB()->assertSave();
$this->postDispatch('/opac/auth/lostpass', ['lost_username' => 'Chambelle']);
$this->_mail = $this->_mail_transport->sent_mail;
}
/** @test */
public function mailShouldBeSent() {
$this->assertNotNull($this->_mail_transport->sent_mail);
$this->assertNotNull($this->_mail);
}
/** @test */
public function mailShouldContainsVousAvezFaitUneDemande() {
$this->assertContains('Vous avez fait une demande',
$this->_mail_transport->sent_mail->getBodyText(true));
$this->_mail->getBodyText(true));
}
/** @test */
public function mailShouldContainsExpirationIn24H() {
$this->assertContains('est valide pendant 24 heures',
$this->_mail->getBodyText(true));
}
}
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment