Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [php]+[MySql] Automatyczna zmiana hasła po każdym wylogowaniu
Forum PHP.pl > Forum > Przedszkole
BoomBox20
Witam,
jestem tutaj nowy i początkujący więc proszę o wyrozumiałość.Mam problem ponieważ mam skrypty php które pochodzą z moodli wer.1.9.12 i chciałbym zrobić coś takiego żeby przy każdym wylogowaniu zostało automatycznie generowane nowe hasło dla wszystkich użytkowników(z wyjątkiem admina) i wysyłane na maila.Czy może mi ktoś pomóc bo zupełnie nie mogę ogarnąć tego kodu-moodle jest potężną platformą.
Czy to w pliku logout.php trzebaby dopisać taką funkcę i w którym miejscu?Jak ta funkcja miałaby wyglądać?Może jakieś linki ktoś mógłby podać jako przykład?!Bardzo serdecznie proszę o pomoc.pozdrawiam

logout.php

  1. <?php // $Id: logout.php,v 1.25 2007/05/15 21:13:23 skodak Exp $
  2. // Logs the user out and sends them to the home page
  3.  
  4. require_once("../config.php");
  5.  
  6. // can be overriden by auth plugins
  7. $redirect = $CFG->wwwroot.'/';
  8.  
  9. $sesskey = optional_param('sesskey', '__notpresent__', PARAM_RAW); // we want not null default to prevent required sesskey warning
  10.  
  11. if (!isloggedin()) {
  12. // no confirmation, user has already logged out
  13. require_logout();
  14. redirect($redirect);
  15.  
  16. } else if (!confirm_sesskey($sesskey)) {
  17. print_header($SITE->fullname, $SITE->fullname, 'home');
  18. notice_yesno(get_string('logoutconfirm'), 'logout.php', $CFG->wwwroot.'/', array('sesskey'=>sesskey()), null, 'post', 'get');
  19. print_footer();
  20. die;
  21. }
  22.  
  23. $authsequence = get_enabled_auth_plugins(); // auths, in sequence
  24. foreach($authsequence as $authname) {
  25. $authplugin = get_auth_plugin($authname);
  26. $authplugin->logoutpage_hook();
  27. }
  28.  
  29. require_logout();
  30.  
  31. redirect($redirect);
  32.  
  33. ?>
  34.  


forgot_password.php
  1. <?php
  2. // $Id: forgot_password.php,v 1.45.2.4 2008/12/01 22:37:12 skodak Exp $
  3. // forgot password routine.
  4. // find the user and call the appropriate routine for their authentication
  5. // type.
  6.  
  7. require_once('../config.php');
  8. require_once('forgot_password_form.php');
  9.  
  10. $p_secret = optional_param('p', false, PARAM_RAW);
  11. $p_username = optional_param('s', false, PARAM_RAW);
  12.  
  13. httpsrequired();
  14.  
  15. $systemcontext = get_context_instance(CONTEXT_SYSTEM);
  16.  
  17. // setup text strings
  18. $strforgotten = get_string('passwordforgotten');
  19. $strlogin = get_string('login');
  20.  
  21. $navigation = build_navigation(array(array('name' => $strlogin, 'link' => "$CFG->wwwroot/login/index.php", 'type' => 'misc'),
  22. array('name' => $strforgotten, 'link' => null, 'type' => 'misc')));
  23.  
  24. // if alternatepasswordurl is defined, then we'll just head there
  25. if (!empty($CFG->forgottenpasswordurl)) {
  26. redirect($CFG->forgottenpasswordurl);
  27. }
  28.  
  29. // if you are logged in then you shouldn't be here!
  30. if (isloggedin() and !isguestuser()) {
  31. redirect($CFG->wwwroot.'/index.php', get_string('loginalready'), 5);
  32. }
  33.  
  34. if ($p_secret !== false) {
  35. ///=====================
  36. /// user clicked on link in email message
  37. ///=====================
  38.  
  39. update_login_count();
  40.  
  41. $user = get_complete_user_data('username', $p_username);
  42. if (!empty($user) and $user->secret === '') {
  43. print_header($strforgotten, $strforgotten, $navigation);
  44. print_error('secretalreadyused');
  45.  
  46. } else if (!empty($user) and $user->secret == stripslashes($p_secret)) {
  47. // make sure that url relates to a valid user
  48.  
  49. // check this isn't guest user
  50. if (isguestuser($user)) {
  51. error('You cannot reset the guest password');
  52. }
  53.  
  54. // make sure user is allowed to change password
  55. require_capability('moodle/user:changeownpassword', $systemcontext, $user->id);
  56.  
  57. // override email stop and mail new password
  58. $user->emailstop = 0;
  59. if (!reset_password_and_mail($user)) {
  60. error('Error resetting password and mailing you');
  61. }
  62.  
  63. // Clear secret so that it can not be used again
  64. $user->secret = '';
  65. if (!set_field('user', 'secret', $user->secret, 'id', $user->id)) {
  66. error('Error resetting user secret string');
  67. }
  68.  
  69. reset_login_count();
  70.  
  71. $changepasswordurl = "{$CFG->httpswwwroot}/login/change_password.php";
  72. $a = new object();
  73. $a->email = $user->email;
  74. $a->link = $changepasswordurl;
  75.  
  76. print_header($strforgotten, $strforgotten, $navigation);
  77. notice(get_string('emailpasswordsent', '', $a), $changepasswordurl);
  78.  
  79. } else {
  80. if (!empty($user) and strlen($p_secret) === 15) {
  81. // somebody probably tries to hack in by guessing secret - stop them!
  82. set_field('user', 'secret', '', 'id', $user->id);
  83. }
  84. print_header($strforgotten, $strforgotten, $navigation);
  85. print_error('forgotteninvalidurl');
  86. }
  87.  
  88. die; //never reached
  89. }
  90.  
  91. $mform = new login_forgot_password_form();
  92.  
  93. if ($mform->is_cancelled()) {
  94. redirect($CFG->httpswwwroot.'/login/index.php');
  95.  
  96. } else if ($data = $mform->get_data()) {
  97. /// find the user in the database and mail info
  98.  
  99. // first try the username
  100. if (!empty($data->username)) {
  101. $user = get_complete_user_data('username', $data->username);
  102. } else {
  103.  
  104. $user = get_complete_user_data('email', $data->email);
  105. }
  106.  
  107. if ($user and !empty($user->confirmed)) {
  108.  
  109. $userauth = get_auth_plugin($user->auth);
  110. if (has_capability('moodle/user:changeownpassword', $systemcontext, $user->id)) {
  111. // send email (make sure mail block is off)
  112. $user->emailstop = 0;
  113. }
  114.  
  115. if ($userauth->can_reset_password() and is_enabled_auth($user->auth)
  116. and has_capability('moodle/user:changeownpassword', $systemcontext, $user->id)) {
  117. // send reset password confirmation
  118.  
  119. // set 'secret' string
  120. $user->secret = random_string(15);
  121. if (!set_field('user', 'secret', $user->secret, 'id', $user->id)) {
  122. error('error setting user secret string');
  123. }
  124.  
  125. if (!send_password_change_confirmation_email($user)) {
  126. error('error sending password change confirmation email');
  127. }
  128.  
  129. } else {
  130. if (!send_password_change_info($user)) {
  131. error('error sending password change confirmation email');
  132. }
  133. }
  134. }
  135.  
  136. print_header($strforgotten, $strforgotten, $navigation);
  137.  
  138. if (empty($user->email) or !empty($CFG->protectusernames)) {
  139. // Print general confirmation message
  140. notice(get_string('emailpasswordconfirmmaybesent'), $CFG->wwwroot.'/index.php');
  141.  
  142. } else {
  143. // Confirm email sent
  144. $protectedemail = preg_replace('/([^@]*)@(.*)/', '******@$2', $user->email); // obfuscate the email address to protect privacy
  145. $stremailpasswordconfirmsent = get_string('emailpasswordconfirmsent', '', $protectedemail);
  146. notice($stremailpasswordconfirmsent, $CFG->wwwroot.'/index.php');
  147. }
  148.  
  149. die; // never reached
  150. }
  151.  
  152.  
  153. /// DISPLAY FORM
  154. print_header($strforgotten, $strforgotten, $navigation, 'id_email');
  155.  
  156. print_box(get_string('passwordforgotteninstructions'), 'generalbox boxwidthnormal boxaligncenter');
  157. $mform->display();
  158.  
  159. print_footer();
  160.  
  161. ?>
  162.  


forgot_password_form.php
  1. <?php //$Id: forgot_password_form.php,v 1.7.2.1 2007/11/23 22:12:35 skodak Exp $
  2.  
  3. require_once $CFG->libdir.'/formslib.php';
  4.  
  5. class login_forgot_password_form extends moodleform {
  6.  
  7. function definition() {
  8. $mform =& $this->_form;
  9. $renderer =& $mform->defaultRenderer();
  10.  
  11. $mform->addElement('header', '', get_string('passwordforgotten'), '');
  12.  
  13. $mform->addElement('text', 'username', get_string('username'));
  14. $mform->setType('username', PARAM_RAW);
  15.  
  16. $mform->addElement('text', 'email', get_string('email'));
  17. $mform->setType('email', PARAM_RAW);
  18.  
  19. $this->add_action_buttons(true, get_string('ok'));
  20. }
  21.  
  22. function validation($data, $files) {
  23. global $CFG;
  24.  
  25. $errors = parent::validation($data, $files);
  26.  
  27. if ((!empty($data['username']) and !empty($data['email'])) or (empty($data['username']) and empty($data['email']))) {
  28. $errors['username'] = get_string('usernameoremail');
  29. $errors['email'] = get_string('usernameoremail');
  30.  
  31. } else if (!empty($data['email'])) {
  32. if (!validate_email($data['email'])) {
  33. $errors['email'] = get_string('invalidemail');
  34.  
  35. } else if (count_records('user', 'email', $data['email']) > 1) {
  36. $errors['email'] = get_string('forgottenduplicate');
  37.  
  38. } else {
  39. if ($user = get_complete_user_data('email', $data['email'])) {
  40. if (empty($user->confirmed)) {
  41. $errors['email'] = get_string('confirmednot');
  42. }
  43. }
  44. if (!$user and empty($CFG->protectusernames)) {
  45. $errors['email'] = get_string('emailnotfound');
  46. }
  47. }
  48.  
  49. } else {
  50. if ($user = get_complete_user_data('username', $data['username'])) {
  51. if (empty($user->confirmed)) {
  52. $errors['email'] = get_string('confirmednot');
  53. }
  54. }
  55. if (!$user and empty($CFG->protectusernames)) {
  56. $errors['username'] = get_string('usernamenotfound');
  57. }
  58. }
  59.  
  60. return $errors;
  61. }
  62.  
  63. }
  64.  
  65. ?>
Hpsi
nie znam tego systemu, ale jesli chcesz zrobic po wylogowywaniu niepotrzebnie wrzuciles tutaj polowe plikow, wystarczylo logout.php
linia: 11-16 jesli dobrze rozumiem tam masz funkcje wylogowujaca.
Jak stworzyc zapytania w tym systemie nie wiem - przeczytaj dokumentacje, my za Ciebie tego nie zrobimy. Ogolnie potrzebujesz komendy update w mysql . jak ma wygladac nie powiem Ci bo nie znam struktury bazy danych tego systemu

do wyslania maila podejrzewam, ze ma to wbudowana jakas funkcje ale ogolnie mail


I pytanie - czy ty nie rzuciłeś się z motyką na słońce ? Sam mówisz ze jesteś zielony w php a chcesz zedytować skrypt, dam sobie ręke uciąć ze nawet do jakiegoś FAQ'u nie spojrzałeś....
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.