lostPassword.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * SCRIPT PURPOSE :
  5. *
  6. * This script allows users to retrieve the password of their profile(s)
  7. * on the basis of their e-mail address. The password is send via email
  8. * to the user.
  9. *
  10. * Special case : If the password are encrypted in the database, we have
  11. * to generate a new one.
  12. *
  13. * @todo refactor, move relevant functions to code libraries
  14. *
  15. * @package chamilo.auth
  16. */
  17. /**
  18. * Code
  19. */
  20. // name of the language file that needs to be included
  21. $language_file = array('registration', 'index');
  22. require_once '../inc/global.inc.php';
  23. // Custom pages
  24. // Had to move the form handling in here, because otherwise there would
  25. // already be some display output.
  26. global $_configuration;
  27. if (CustomPages::enabled()) {
  28. // Reset Password when user goes to the link
  29. if (isset($_GET['reset']) && $_GET['reset'] &&
  30. isset($_GET['id']) && $_GET['id']
  31. ) {
  32. $mesg = Login::reset_password($_GET["reset"], $_GET["id"], true);
  33. CustomPages::display(CustomPages::INDEX_UNLOGGED, array('info' => $mesg));
  34. }
  35. // Check email/username and do the right thing
  36. if (isset($_POST['user'])) {
  37. $usersRelatedToUsername = Login::get_user_accounts_by_username($_POST['user']);
  38. if ($usersRelatedToUsername) {
  39. $by_username = true;
  40. foreach ($usersRelatedToUsername as $user) {
  41. if ($_configuration['password_encryption'] != 'none') {
  42. Login::handle_encrypted_password($user, $by_username);
  43. } else {
  44. Login::send_password_to_user($user, $by_username);
  45. }
  46. }
  47. } else {
  48. CustomPages::display(
  49. CustomPages::LOST_PASSWORD,
  50. array('error' => get_lang('NoUserAccountWithThisEmailAddress'))
  51. );
  52. }
  53. } else {
  54. CustomPages::display(CustomPages::LOST_PASSWORD);
  55. }
  56. CustomPages::display(
  57. CustomPages::INDEX_UNLOGGED,
  58. array('info' => get_lang('YourPasswordHasBeenEmailed'))
  59. );
  60. }
  61. $tool_name = get_lang('LostPassword');
  62. Display :: display_header($tool_name);
  63. $this_section = SECTION_CAMPUS;
  64. $tool_name = get_lang('LostPass');
  65. // Forbidden to retrieve the lost password
  66. if (api_get_setting('allow_lostpassword') == 'false') {
  67. api_not_allowed();
  68. }
  69. if (isset($_GET['reset']) && isset($_GET['id'])) {
  70. $message = Display::return_message(Login::reset_password($_GET["reset"], $_GET["id"], true), 'normal', false);
  71. $message .= '<a href="'.api_get_path(WEB_CODE_PATH).'auth/lostPassword.php" class="btn" >'.get_lang('Back').'</a>';
  72. echo $message;
  73. } else {
  74. $form = new FormValidator('lost_password');
  75. $form->addElement('header', $tool_name);
  76. $form->addElement('text', 'user', array(get_lang('LoginOrEmailAddress'), get_lang('EnterEmailUserAndWellSendYouPassword')), array('size'=>'40'));
  77. $form->addButtonSend(get_lang('Send'));
  78. // Setting the rules
  79. $form->addRule('user', get_lang('ThisFieldIsRequired'), 'required');
  80. if ($form->validate()) {
  81. $values = $form->exportValues();
  82. $users_related_to_username = Login::get_user_accounts_by_username(
  83. $values['user']
  84. );
  85. if ($users_related_to_username) {
  86. $by_username = true;
  87. foreach ($users_related_to_username as $user) {
  88. if ($_configuration['password_encryption'] != 'none') {
  89. Login::handle_encrypted_password($user, $by_username);
  90. } else {
  91. Login::send_password_to_user($user, $by_username);
  92. }
  93. }
  94. } else {
  95. Display::display_warning_message(get_lang('NoUserAccountWithThisEmailAddress'));
  96. }
  97. } else {
  98. $form->display();
  99. }
  100. }
  101. Display::display_footer();