Witam,
mam problem ponieważ mam dwa skrypty php które pochodzą z moodli i chciałbym zrobić coś takiego żeby przy każdym wylogowaniu zostało automatycznie generowane nowe hasło i wysyłane na maila.Czy może mi ktoś pomóc bo zupełnie nie mogę ogarnąć tego kodu.Mam takie pliki:
[URL=http://imageshack.us/photo/my-images/593/76325210.jpg/][ img ]http://img593.imageshack.us/img593/4217/76325210.jpg[ /img ][/URL]
Uploaded with [URL=http://imageshack.us]ImageShack.us[/URL]
Nie wiem w których by trzeba było dopisać jakąś taką funkcje i jak.Zamieszczę dwa pliki:
change_password.php
[code]
<?PHP // $Id: change_password.php,v 1.62.2.3 2009/11/26 07:25:31 samhemelryk Exp $
require_once('../config.php');
require_once('change_password_form.php');
$id = optional_param('id', SITEID, PARAM_INT); // current course
$strparticipants = get_string('participants');
//HTTPS is potentially required in this page
httpsrequired();
$systemcontext = get_context_instance(CONTEXT_SYSTEM);
if (!$course = get_record('course', 'id', $id)) {
error('No such course!');
}
// require proper login; guest user can not change password
if (empty($USER->id) or isguestuser()) {
if (empty($SESSION->wantsurl)) {
$SESSION->wantsurl = $CFG->httpswwwroot.'/login/change_password.php';
}
redirect($CFG->httpswwwroot.'/login/index.php');
}
// do not require change own password cap if change forced
if (!get_user_preferences('auth_forcepasswordchange', false)) {
require_capability('moodle/user:changeownpassword', $systemcontext);
}
// do not allow "Logged in as" users to change any passwords
if (!empty($USER->realuser)) {
error('Can not use this script when "Logged in as"!');
}
if (is_mnet_remote_user($USER)) {
$message = get_string('usercannotchangepassword', 'mnet');
if ($idprovider = get_record('mnet_host', 'id', $USER->mnethostid)) {
$message .= get_string('userchangepasswordlink', 'mnet', $idprovider);
}
error($message);
}
// load the appropriate auth plugin
$userauth = get_auth_plugin($USER->auth);
if (!$userauth->can_change_password()) {
print_error('nopasswordchange', 'auth');
}
if ($changeurl = $userauth->change_password_url()) {
// this internal scrip not used
redirect($changeurl);
}
$mform = new login_change_password_form();
$mform->set_data(array('id'=>$course->id));
$navlinks = array();
$navlinks[] = array('name' => $strparticipants, 'link' => "$CFG->wwwroot/user/index.php?id=$course->id", 'type' => 'misc');
if ($mform->is_cancelled()) {
redirect($CFG->wwwroot.'/user/view.php?id='.$USER->id.'&course='.$course->id);
} else if ($data = $mform->get_data()) {
if (!$userauth->user_update_password(addslashes_recursive($USER), $data->newpassword1)) {
print_error('errorpasswordupdate', 'auth');
}
// register success changing password
unset_user_preference('auth_forcepasswordchange', $USER->id);
$strpasswordchanged = get_string('passwordchanged');
add_to_log($course->id, 'user', 'change password', "view.php?id=$USER->id&course=$course->id", "$USER->id");
$fullname = fullname($USER, true);
$navlinks[] = array('name' => $fullname,
'link' => "$CFG->wwwroot/user/view.php?id=$USER->id&course=$course->id",
'type' => 'misc');
$navlinks[] = array('name' => $strpasswordchanged, 'link' => null, 'type' => 'misc');
$navigation = build_navigation($navlinks);
print_header($strpasswordchanged, $strpasswordchanged, $navigation);
if (empty($SESSION->wantsurl) or $SESSION->wantsurl == $CFG->httpswwwroot.'/login/change_password.php') {
$returnto = "$CFG->wwwroot/user/view.php?id=$USER->id&course=$id";
} else {
$returnto = $SESSION->wantsurl;
}
notice($strpasswordchanged, $returnto);
print_footer();
exit;
}
$strchangepassword = get_string('changepassword');
$fullname = fullname($USER, true);
$navlinks[] = array('name' => $fullname, 'link' => "$CFG->wwwroot/user/view.php?id=$USER->id&course=$course->id", 'type' => 'misc');
$navlinks[] = array('name' => $strchangepassword, 'link' => null, 'type' => 'misc');
$navigation = build_navigation($navlinks);
// Turn off pop-up messaging window for this page
$CFG->messaging = 0;
print_header($strchangepassword, $strchangepassword, $navigation);
if (get_user_preferences('auth_forcepasswordchange')) {
notify(get_string('forcepasswordchangenotice'));
}
$mform->display();
print_footer();
?>
[/code]
change_password_form.php
[code]
<?php //$Id: change_password_form.php,v 1.11.2.5 2010/05/13 01:40:38 moodler Exp $
if (!defined('MOODLE_INTERNAL')) {
die('Direct access to this script is forbidden.'); /// It must be included from a Moodle page
}
require_once $CFG->libdir.'/formslib.php';
class login_change_password_form extends moodleform {
function definition() {
global $USER, $CFG;
$mform =& $this->_form;
$mform->addElement('header', `, get_string('changepassword'), `);
// visible elements
$mform->addElement('static', 'username', get_string('username'), $USER->username);
if (!empty($CFG->passwordpolicy)){
$mform->addElement('static', 'passwordpolicyinfo', '', print_password_policy());
}
$mform->addElement('password', 'password', get_string('oldpassword'));
$mform->addRule('password', get_string('required'), 'required', null, 'client');
$mform->setType('password', PARAM_RAW);
$mform->addElement('password', 'newpassword1', get_string('newpassword'));
$mform->addRule('newpassword1', get_string('required'), 'required', null, 'client');
$mform->setType('newpassword1', PARAM_RAW);
$mform->addElement('password', 'newpassword2', get_string('newpassword').' ('.get_String('again').')');
$mform->addRule('newpassword2', get_string('required'), 'required', null, 'client');
$mform->setType('newpassword2', PARAM_RAW);
// hidden optional params
$mform->addElement('hidden', 'id', 0);
$mform->setType('id', PARAM_INT);
// buttons
if (get_user_preferences('auth_forcepasswordchange')) {
$this->add_action_buttons(false);
} else {
$this->add_action_buttons(true);
}
}
/// perform extra password change validation
function validation($data, $files) {
global $USER;
$errors = parent::validation($data, $files);
update_login_count();
// ignore submitted username
if (!$user = authenticate_user_login(addslashes($USER->username), $data['password'])) {
$errors['password'] = get_string('invalidlogin');
return $errors;
}
reset_login_count();
if ($data['newpassword1'] < $data['newpassword2']) {
$errors['newpassword1'] = get_string('passwordsdiffer');
$errors['newpassword2'] = get_string('passwordsdiffer');
return $errors;
}
if ($data['password'] == $data['newpassword1']){
$errors['newpassword1'] = get_string('mustchangepassword');
$errors['newpassword2'] = get_string('mustchangepassword');
return $errors;
}
$errmsg = '';//prevents eclipse warnings
if (!check_password_policy($data['newpassword1'], $errmsg)) {
$errors['newpassword1'] = $errmsg;
$errors['newpassword2'] = $errmsg;
return $errors;
}
return $errors;
}
}
?>
[/code]
Bardzo serdecznie proszę o pomoc i zrozumienie bo jestem początkujący.pozdrawiam[code][/code]