lostPassword.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. <?php
  2. /* For licensing terms, see /dokeos_license.txt */
  3. /**
  4. ==============================================================================
  5. * SCRIPT PURPOSE :
  6. *
  7. * This script allows users to retrieve the password of their profile(s)
  8. * on the basis of their e-mail address. The password is send via email
  9. * to the user.
  10. *
  11. * Special case : If the password are encrypted in the database, we have
  12. * to generate a new one.
  13. *
  14. * @todo refactor, move relevant functions to code libraries
  15. *
  16. * @package dokeos.auth
  17. ==============================================================================
  18. */
  19. // name of the language file that needs to be included
  20. $language_file = 'registration';
  21. require '../inc/global.inc.php';
  22. require_once 'lost_password.lib.php';
  23. require_once api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php';
  24. require_once api_get_path(LIBRARY_PATH).'mail.lib.inc.php';
  25. $tool_name = get_lang('LostPassword');
  26. Display :: display_header($tool_name);
  27. $this_section = SECTION_CAMPUS;
  28. $tool_name = get_lang('LostPass');
  29. // Forbidden to retrieve the lost password
  30. if (api_get_setting('allow_lostpassword') == 'false') {
  31. api_not_allowed();
  32. }
  33. echo '<div class="actions-title">';
  34. echo $tool_name;
  35. echo '</div>';
  36. if (isset ($_GET['reset']) && isset ($_GET['id'])) {
  37. $msg = reset_password($_GET["reset"], $_GET["id"], true);
  38. $msg1= '<a href="'.api_get_path(WEB_CODE_PATH).'auth/lostPassword.php" class="fake_button_back" >'.get_lang('Back').'</a>';
  39. echo '<br /><br /><div class="actions" >'.$msg1.'</div>';
  40. } else {
  41. $form = new FormValidator('lost_password');
  42. $form->addElement('text', 'user', get_lang('User'), array('size'=>'40'));
  43. $form->addElement('text', 'email', get_lang('Email'), array('size'=>'40'));
  44. $form->applyFilter('email','strtolower');
  45. $form->addElement('style_submit_button', 'submit', get_lang('Send'),'class="save"');
  46. // setting the rules
  47. $form->addRule('user', '<div class="required">'.get_lang('ThisFieldIsRequired'), 'required');
  48. if ($form->validate()) {
  49. $values = $form->exportValues();
  50. $user = $values['user'];
  51. $email = $values['email'];
  52. $condition = '';
  53. if (!empty($email)) {
  54. $condition = " AND LOWER(email) = '".Database::escape_string($email)."' ";
  55. }
  56. $tbl_user = Database :: get_main_table(TABLE_MAIN_USER);
  57. $query = " SELECT user_id AS uid, lastname AS lastName, firstname AS firstName,
  58. username AS loginName, password, email, status AS status,
  59. official_code, phone, picture_uri, creator_id
  60. FROM ".$tbl_user."
  61. WHERE ( username = '".Database::escape_string($user)."' $condition ) ";
  62. $result = Database::query($query, __FILE__, __LINE__);
  63. $num_rows = Database::num_rows($result);
  64. if ($result && $num_rows > 0) {
  65. if ($num_rows > 1) {
  66. $by_username = false; // more than one user
  67. while ($data = Database::fetch_array($result)) {
  68. $user[] = $data;
  69. }
  70. } else {
  71. $by_username = true; // single user (valid user + email)
  72. $user = Database::fetch_array($result);
  73. }
  74. if ($userPasswordCrypted != 'none') {
  75. handle_encrypted_password($user, $by_username);
  76. } else {
  77. send_password_to_user($user, $by_username);
  78. }
  79. } else {
  80. Display::display_error_message(get_lang('NoUserAccountWithThisEmailAddress'));
  81. }
  82. $msg .= '<a href="'.api_get_path(WEB_CODE_PATH).'auth/lostPassword.php" class="fake_button_back" >'.get_lang('Back').'</a>';
  83. echo '<br /><br /><div class="actions" >'.$msg.'</div>';
  84. } else {
  85. echo '<p>';
  86. echo get_lang('EnterEmailUserAndWellSendYouPassword');
  87. echo '</p>';
  88. $form->display();
  89. }
  90. }
  91. Display :: display_footer();