lostPassword.php 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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(INCLUDE_PATH).'lib/mail.lib.inc.php');
  25. $tool_name = get_lang('LostPassword');
  26. Display :: display_header($tool_name);
  27. // Forbidden to retrieve the lost password
  28. if (api_get_setting('allow_lostpassword') == "false")
  29. {
  30. api_not_allowed();
  31. }
  32. echo '<div class="actions-title">';
  33. echo $tool_name;
  34. echo '</div>';
  35. $tbl_user = Database :: get_main_table(TABLE_MAIN_USER);
  36. if (isset ($_GET["reset"]) && isset ($_GET["id"])) {
  37. $msg = reset_password($_GET["reset"], $_GET["id"]);
  38. $msg1= '<a href="'.api_get_path(WEB_PATH).'main/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->add_textfield('email', get_lang('Email'), false, 'size="40"');
  43. $form->applyFilter('email','strtolower');
  44. $form->addElement('style_submit_button', 'submit', get_lang('Send'),'class="save"');
  45. if ($form->validate())
  46. {
  47. $values = $form->exportValues();
  48. $email = $values['email'];
  49. $result = api_sql_query("SELECT user_id AS uid, lastname AS lastName, firstname AS firstName,
  50. username AS loginName, password, email, status AS status,
  51. official_code, phone, picture_uri, creator_id
  52. FROM ".$tbl_user."
  53. WHERE LOWER(email) = '".mysql_real_escape_string($email)."'
  54. AND email != '' ", __FILE__, __LINE__);
  55. if ($result && Database::num_rows($result))
  56. {
  57. while ($data = Database::fetch_array($result))
  58. {
  59. $user[] = $data;
  60. }
  61. if ($userPasswordCrypted!='none')
  62. {
  63. $msg = handle_encrypted_password($user);
  64. }
  65. else
  66. {
  67. send_password_to_user($user);
  68. }
  69. }
  70. else
  71. {
  72. Display::display_error_message(get_lang('_no_user_account_with_this_email_address'));
  73. }
  74. $msg .= '<a href="'.api_get_path(WEB_PATH).'main/auth/lostPassword.php" class="fake_button_back" >'.get_lang('Back').'</a>';
  75. echo '<br/><br/><div class="actions" >'.$msg.'</div>';
  76. }
  77. else
  78. {
  79. echo '<p>';
  80. echo get_lang('_enter_email_and_well_send_you_password');
  81. echo '</p>';
  82. $form->display();
  83. ?>
  84. <br/>
  85. <div class="actions">
  86. <a href="<?php echo api_get_path(WEB_PATH); ?>" class="fake_button_back" ><?php echo get_lang('Back'); ?></a>
  87. </div>
  88. <?php
  89. }
  90. }
  91. Display :: display_footer();
  92. //////////////////////////////////////////////////////////////////////////////
  93. ?>