8
Fixed !
I changed actions "Show message" instead of header redirection ! using customized messages ...
Code :
<?php
include dirname(__FILE__) . DIRECTORY_SEPARATOR . 'mainfile.php';
$xoopsPreload =& XoopsPreload::getInstance();
$xoopsPreload->triggerEvent('core.lostpass.start');
xoops_loadLanguage('user');
$email = isset($_GET['email']) ? trim($_GET['email']) : '';
$email = isset($_POST['email']) ? trim($_POST['email']) : $email;
if ($email == '') {
redirect_header("user.php", 2, _US_SORRYNOTFOUND);
exit();
}
$myts =& MyTextSanitizer::getInstance();
$member_handler =& xoops_gethandler('member');
$getuser =& $member_handler->getUsers(new Criteria('email', $myts->addSlashes($email)));
if (empty($getuser)) {
include $GLOBALS['xoops']->path('header.php');
echo "<br><br><br>
<div class='alert alert-danger'><p><strong>Oups!</strong><br>Aucun utilisateur n'est enregistré avec l'adresse e-mail mentionnée. Merci de réessayer ou contactez l'administrateur : <strong>contact@tafraout.net</strong></p>
<p><a href='user.php' class='btn btn-primary'>Réessayer</a></p>
</div>";
include $GLOBALS['xoops']->path('footer.php');
exit();
} else {
$code = isset($_GET['code']) ? trim($_GET['code']) : '';
$areyou = substr($getuser[0]->getVar("pass"), 0, 5);
if ($code != '' && $areyou == $code) {
$newpass = xoops_makepass();
$xoopsMailer =& xoops_getMailer();
$xoopsMailer->useMail();
$xoopsMailer->setTemplate("lostpass2.tpl");
$xoopsMailer->assign("SITENAME", $xoopsConfig['sitename']);
$xoopsMailer->assign("ADMINMAIL", $xoopsConfig['adminmail']);
$xoopsMailer->assign("SITEURL", XOOPS_URL . "/");
$xoopsMailer->assign("IP", $_SERVER['REMOTE_ADDR']);
$xoopsMailer->assign("NEWPWD", $newpass);
$xoopsMailer->setToUsers($getuser[0]);
$xoopsMailer->setFromEmail($xoopsConfig['adminmail']);
$xoopsMailer->setFromName($xoopsConfig['sitename']);
$xoopsMailer->setSubject(sprintf(_US_NEWPWDREQ, XOOPS_URL));
if (! $xoopsMailer->send()) {
echo $xoopsMailer->getErrors();
}
// Next step: add the new password to the database
$sql = sprintf("UPDATE %s SET pass = '%s' WHERE uid = %u", $xoopsDB->prefix("users"), md5($newpass), $getuser[0]->getVar('uid'));
if (!$xoopsDB->queryF($sql)) {
include $GLOBALS['xoops']->path('header.php');
echo _US_MAILPWDNG;
include $GLOBALS['xoops']->path('footer.php');
exit();
}
include $GLOBALS['xoops']->path('header.php');
echo "<br><br><br><div class='alert alert-success'><strong>Votre mot de passe a été changé avec succès.</strong><br>
Nous avons envoyé un nouveau mot de passe à votre adresse e-mail. Merci de consulter votre boite de réception.</div>";
include $GLOBALS['xoops']->path('footer.php');
header( "refresh:10;url=user.php" );
// If no Code, send it
} else {
$xoopsMailer =& xoops_getMailer();
$xoopsMailer->useMail();
$xoopsMailer->setTemplate("lostpass1.tpl");
$xoopsMailer->assign("SITENAME", $xoopsConfig['sitename']);
$xoopsMailer->assign("ADMINMAIL", $xoopsConfig['adminmail']);
$xoopsMailer->assign("SITEURL", XOOPS_URL . "/");
$xoopsMailer->assign("IP", $_SERVER['REMOTE_ADDR']);
$xoopsMailer->assign("NEWPWD_LINK", XOOPS_URL . "/lostpass.php?email=" . $email . "&code=" . $areyou);
$xoopsMailer->setToUsers($getuser[0]);
$xoopsMailer->setFromEmail($xoopsConfig['adminmail']);
$xoopsMailer->setFromName($xoopsConfig['sitename']);
$xoopsMailer->setSubject(sprintf(_US_NEWPWDREQ, $xoopsConfig['sitename']));
include $GLOBALS['xoops']->path('header.php');
if (! $xoopsMailer->send()) {
echo $xoopsMailer->getErrors();
}
echo "<br><br><br><div class='alert alert-warning'>Nous avons envoyé un e-mail à l'adresse <strong>" . $email . "</strong> <br> Merci de consulter votre boite de réception, vous y trouverez un lien confidentiel qui vous permettra de recevoir un nouveau mot de passe.</div>";
include $GLOBALS['xoops']->path('footer.php');
}
}
?>