XOOPS 2.5.6  Final
 All Classes Namespaces Files Functions Variables Pages
lostpass.php
Go to the documentation of this file.
1 <?php
19 include dirname(__FILE__) . DIRECTORY_SEPARATOR . 'mainfile.php';
20 
22 $xoopsPreload->triggerEvent('core.lostpass.start');
23 
24 xoops_loadLanguage('user');
25 
26 $email = isset($_GET['email']) ? trim($_GET['email']) : '';
27 $email = isset($_POST['email']) ? trim($_POST['email']) : $email;
28 
29 if ($email == '') {
30  redirect_header("user.php", 2, _US_SORRYNOTFOUND);
31  exit();
32 }
33 
36 $getuser =& $member_handler->getUsers(new Criteria('email', $myts->addSlashes($email)));
37 
38 if (empty($getuser)) {
40  redirect_header("user.php", 2, $msg);
41  exit();
42 } else {
43  $code = isset($_GET['code']) ? trim($_GET['code']) : '';
44  $areyou = substr($getuser[0]->getVar("pass"), 0, 5);
45  if ($code != '' && $areyou == $code) {
46  $newpass = xoops_makepass();
47  $xoopsMailer =& xoops_getMailer();
48  $xoopsMailer->useMail();
49  $xoopsMailer->setTemplate("lostpass2.tpl");
50  $xoopsMailer->assign("SITENAME", $xoopsConfig['sitename']);
51  $xoopsMailer->assign("ADMINMAIL", $xoopsConfig['adminmail']);
52  $xoopsMailer->assign("SITEURL", XOOPS_URL . "/");
53  $xoopsMailer->assign("IP", $_SERVER['REMOTE_ADDR']);
54  $xoopsMailer->assign("NEWPWD", $newpass);
55  $xoopsMailer->setToUsers($getuser[0]);
56  $xoopsMailer->setFromEmail($xoopsConfig['adminmail']);
57  $xoopsMailer->setFromName($xoopsConfig['sitename']);
58  $xoopsMailer->setSubject(sprintf(_US_NEWPWDREQ, XOOPS_URL));
59  if (! $xoopsMailer->send()) {
60  echo $xoopsMailer->getErrors();
61  }
62  // Next step: add the new password to the database
63  $sql = sprintf("UPDATE %s SET pass = '%s' WHERE uid = %u", $xoopsDB->prefix("users"), md5($newpass), $getuser[0]->getVar('uid'));
64  if (!$xoopsDB->queryF($sql)) {
65  include $GLOBALS['xoops']->path('header.php');
66  echo _US_MAILPWDNG;
67  include $GLOBALS['xoops']->path('footer.php');
68  exit();
69  }
70  redirect_header("user.php", 3, sprintf(_US_PWDMAILED, $getuser[0]->getVar("uname")), false);
71  exit();
72  // If no Code, send it
73  } else {
74  $xoopsMailer =& xoops_getMailer();
75  $xoopsMailer->useMail();
76  $xoopsMailer->setTemplate("lostpass1.tpl");
77  $xoopsMailer->assign("SITENAME", $xoopsConfig['sitename']);
78  $xoopsMailer->assign("ADMINMAIL", $xoopsConfig['adminmail']);
79  $xoopsMailer->assign("SITEURL", XOOPS_URL . "/");
80  $xoopsMailer->assign("IP", $_SERVER['REMOTE_ADDR']);
81  $xoopsMailer->assign("NEWPWD_LINK", XOOPS_URL . "/lostpass.php?email=" . $email . "&code=" . $areyou);
82  $xoopsMailer->setToUsers($getuser[0]);
83  $xoopsMailer->setFromEmail($xoopsConfig['adminmail']);
84  $xoopsMailer->setFromName($xoopsConfig['sitename']);
85  $xoopsMailer->setSubject(sprintf(_US_NEWPWDREQ, $xoopsConfig['sitename']));
86  include $GLOBALS['xoops']->path('header.php');
87  if (! $xoopsMailer->send()) {
88  echo $xoopsMailer->getErrors();
89  }
90  echo "<h4>";
91  printf(_US_CONFMAIL, $getuser[0]->getVar("uname"));
92  echo "</h4>";
93  include $GLOBALS['xoops']->path('footer.php');
94  }
95 }
96 
97 ?>