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