lostPassword.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <?php
  2. // $Id: lostPassword.php 9246 2006-09-25 13:24:53Z bmol $
  3. /*
  4. ==============================================================================
  5. Dokeos - elearning and course management software
  6. Copyright (c) 2004 Dokeos S.A.
  7. Copyright (c) 2003 Ghent University (UGent)
  8. Copyright (c) 2001 Universite catholique de Louvain (UCL)
  9. Copyright (c) various contributors
  10. For a full list of contributors, see "credits.txt".
  11. The full license can be read in "license.txt".
  12. This program is free software; you can redistribute it and/or
  13. modify it under the terms of the GNU General Public License
  14. as published by the Free Software Foundation; either version 2
  15. of the License, or (at your option) any later version.
  16. See the GNU General Public License for more details.
  17. Contact: Dokeos, 181 rue Royale, B-1000 Brussels, Belgium, info@dokeos.com
  18. ==============================================================================
  19. */
  20. /**
  21. ==============================================================================
  22. * SCRIPT PURPOSE :
  23. *
  24. * This script allows users to retrieve the password of their profile(s)
  25. * on the basis of their e-mail address. The password is send via email
  26. * to the user.
  27. *
  28. * Special case : If the password are encrypted in the database, we have
  29. * to generate a new one.
  30. *
  31. * @todo refactor, move relevant functions to code libraries
  32. *
  33. * @package dokeos.auth
  34. ==============================================================================
  35. */
  36. $langFile = "registration";
  37. require ('../inc/global.inc.php');
  38. require_once ('lost_password.lib.php');
  39. require_once (api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php');
  40. $tool_name = get_lang('_lost_password');
  41. Display :: display_header($tool_name);
  42. // Forbidden to retrieve the lost password
  43. if (get_setting('allow_lostpassword') == "false")
  44. {
  45. api_not_allowed();
  46. }
  47. api_display_tool_title($tool_name);
  48. $tbl_user = Database :: get_main_table(MAIN_USER_TABLE);
  49. if (isset ($_GET["reset"]) && isset ($_GET["id"]))
  50. {
  51. $msg = reset_password($_GET["reset"], $_GET["id"]);
  52. $msg .= '. <br/>'.get_lang('_your_password_has_been_emailed_to_you');
  53. $msg .= '<br/><br/><a href="'.api_get_path(WEB_PATH).'main/auth/lostPassword.php">&lt;&lt; '.get_lang('Back').'</a>';
  54. echo $msg;
  55. }
  56. else
  57. {
  58. $form = new FormValidator('lost_password');
  59. $form->add_textfield('email', get_lang('Email'), false, 'size="40"');
  60. $form->applyFilter('email','strtolower');
  61. $form->addElement('submit', 'submit', get_lang('Ok'));
  62. if ($form->validate())
  63. {
  64. $values = $form->exportValues();
  65. $email = $values['email'];
  66. $result = api_sql_query("SELECT user_id AS uid, lastname AS lastName, firstname AS firstName,
  67. username AS loginName, password, email, status AS status,
  68. official_code, phone, picture_uri, creator_id
  69. FROM ".$tbl_user."
  70. WHERE LOWER(email) = '".mysql_real_escape_string($email)."'
  71. AND email != '' ", __FILE__, __LINE__);
  72. if ($result && mysql_num_rows($result))
  73. {
  74. while ($data = mysql_fetch_array($result))
  75. $user[] = $data;
  76. if ($userPasswordCrypted)
  77. $msg = handle_encrypted_password($user);
  78. else
  79. $msg = send_password_to_user($user, get_lang('_your_password_has_been_emailed_to_you'));
  80. }
  81. else
  82. {
  83. $msg = get_lang('_no_user_account_with_this_email_address');
  84. }
  85. $msg .= '<br/><br/><a href="'.api_get_path(WEB_PATH).'main/auth/lostPassword.php">&lt;&lt; '.get_lang('Back').'</a>';
  86. echo '<p>'.$msg.'</p>';
  87. }
  88. else
  89. {
  90. echo '<p>';
  91. echo get_lang('_enter_email_and_well_send_you_password');
  92. echo '</p>';
  93. $form->display();
  94. ?>
  95. <a href="<?php echo api_get_path(WEB_PATH); ?>">&lt;&lt; <?php echo get_lang('Back'); ?></a>
  96. <?php
  97. }
  98. }
  99. Display :: display_footer();
  100. //////////////////////////////////////////////////////////////////////////////
  101. ?>