lostPassword.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. <?php
  2. // $Id: lostPassword.php 11873 2007-04-04 19:46:04Z pcool $
  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. // name of the language file that needs to be included
  37. $language_file = "registration";
  38. require ('../inc/global.inc.php');
  39. require_once ('lost_password.lib.php');
  40. require_once (api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php');
  41. $tool_name = get_lang('LostPassword');
  42. Display :: display_header($tool_name);
  43. // Forbidden to retrieve the lost password
  44. if (get_setting('allow_lostpassword') == "false")
  45. {
  46. api_not_allowed();
  47. }
  48. api_display_tool_title($tool_name);
  49. $tbl_user = Database :: get_main_table(TABLE_MAIN_USER);
  50. if (isset ($_GET["reset"]) && isset ($_GET["id"]))
  51. {
  52. $msg = reset_password($_GET["reset"], $_GET["id"]);
  53. $msg .= '. <br/>'.get_lang('YourPasswordHasBeenEmailed');
  54. $msg .= '<br/><br/><a href="'.api_get_path(WEB_PATH).'main/auth/lostPassword.php">&lt;&lt; '.get_lang('Back').'</a>';
  55. echo $msg;
  56. }
  57. else
  58. {
  59. $form = new FormValidator('lost_password');
  60. $form->add_textfield('email', get_lang('Email'), false, 'size="40"');
  61. $form->applyFilter('email','strtolower');
  62. $form->addElement('submit', 'submit', get_lang('Ok'));
  63. if ($form->validate())
  64. {
  65. $values = $form->exportValues();
  66. $email = $values['email'];
  67. $result = api_sql_query("SELECT user_id AS uid, lastname AS lastName, firstname AS firstName,
  68. username AS loginName, password, email, status AS status,
  69. official_code, phone, picture_uri, creator_id
  70. FROM ".$tbl_user."
  71. WHERE LOWER(email) = '".mysql_real_escape_string($email)."'
  72. AND email != '' ", __FILE__, __LINE__);
  73. if ($result && mysql_num_rows($result))
  74. {
  75. while ($data = mysql_fetch_array($result))
  76. {
  77. $user[] = $data;
  78. }
  79. if ($userPasswordCrypted)
  80. {
  81. $msg = handle_encrypted_password($user);
  82. }
  83. else
  84. {
  85. send_password_to_user($user);
  86. }
  87. }
  88. else
  89. {
  90. Display::display_error_message(get_lang('_no_user_account_with_this_email_address'));
  91. }
  92. $msg .= '<br/><br/><a href="'.api_get_path(WEB_PATH).'main/auth/lostPassword.php">&lt;&lt; '.get_lang('Back').'</a>';
  93. echo '<p>'.$msg.'</p>';
  94. }
  95. else
  96. {
  97. echo '<p>';
  98. echo get_lang('_enter_email_and_well_send_you_password');
  99. echo '</p>';
  100. $form->display();
  101. ?>
  102. <a href="<?php echo api_get_path(WEB_PATH); ?>">&lt;&lt; <?php echo get_lang('Back'); ?></a>
  103. <?php
  104. }
  105. }
  106. Display :: display_footer();
  107. //////////////////////////////////////////////////////////////////////////////
  108. ?>