/scp/pwreset.php

https://github.com/c1sc0guy/osTicket-1.8 · PHP · 81 lines · 56 code · 2 blank · 23 comment · 10 complexity · 0913b5731a68fbb9075f361a748d70b3 MD5 · raw file

  1. <?php
  2. /*********************************************************************
  3. pwreset.php
  4. Handles step 2, 3 and 5 of password resetting
  5. 1. Fail to login (2+ fail login attempts)
  6. 2. Visit password reset form and enter username or email
  7. 3. Receive an email with a link and follow it
  8. 4. Visit password reset form again, with the link
  9. 5. Enter the username or email address again and login
  10. 6. Password change is now required, user changes password and
  11. continues on with the session
  12. Peter Rotich <peter@osticket.com>
  13. Jared Hancock <jared@osticket.com>
  14. Copyright (c) 2006-2013 osTicket
  15. http://www.osticket.com
  16. Released under the GNU General Public License WITHOUT ANY WARRANTY.
  17. See LICENSE.TXT for details.
  18. vim: expandtab sw=4 ts=4 sts=4:
  19. **********************************************************************/
  20. require_once('../main.inc.php');
  21. if(!defined('INCLUDE_DIR')) die('Fatal Error. Kwaheri!');
  22. require_once(INCLUDE_DIR.'class.staff.php');
  23. require_once(INCLUDE_DIR.'class.csrf.php');
  24. $tpl = 'pwreset.php';
  25. if($_POST) {
  26. if (!$ost->checkCSRFToken()) {
  27. Http::response(400, 'Valid CSRF Token Required');
  28. exit;
  29. }
  30. switch ($_POST['do']) {
  31. case 'sendmail':
  32. if (($staff=Staff::lookup($_POST['userid']))) {
  33. if (!$staff->hasPassword()) {
  34. $msg = 'Unable to reset password. Contact your administrator';
  35. }
  36. elseif (!$staff->sendResetEmail()) {
  37. $tpl = 'pwreset.sent.php';
  38. }
  39. }
  40. else
  41. $msg = 'Unable to verify username '
  42. .Format::htmlchars($_POST['userid']);
  43. break;
  44. case 'newpasswd':
  45. // TODO: Compare passwords
  46. $tpl = 'pwreset.login.php';
  47. $errors = array();
  48. if ($staff = StaffAuthenticationBackend::processSignOn($errors)) {
  49. $info = array('page' => 'index.php');
  50. Http::redirect($info['page']);
  51. }
  52. elseif (isset($errors['msg'])) {
  53. $msg = $errors['msg'];
  54. }
  55. break;
  56. }
  57. }
  58. elseif ($_GET['token']) {
  59. $msg = 'Re-enter your username or email';
  60. $_config = new Config('pwreset');
  61. if (($id = $_config->get($_GET['token']))
  62. && ($staff = Staff::lookup($id)))
  63. $tpl = 'pwreset.login.php';
  64. else
  65. header('Location: index.php');
  66. }
  67. elseif ($cfg->allowPasswordReset()) {
  68. $msg = 'Enter your username or email address below';
  69. }
  70. else {
  71. $_SESSION['_staff']['auth']['msg']='Password resets are disabled';
  72. return header('Location: index.php');
  73. }
  74. define("OSTSCPINC",TRUE); //Make includes happy!
  75. include_once(INCLUDE_DIR.'staff/'. $tpl);