Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/login/change_password.php
Go to the documentation of this file.
00001 <?php
00002 
00003 // This file is part of Moodle - http://moodle.org/
00004 //
00005 // Moodle is free software: you can redistribute it and/or modify
00006 // it under the terms of the GNU General Public License as published by
00007 // the Free Software Foundation, either version 3 of the License, or
00008 // (at your option) any later version.
00009 //
00010 // Moodle is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 // GNU General Public License for more details.
00014 //
00015 // You should have received a copy of the GNU General Public License
00016 // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
00017 
00027 require('../config.php');
00028 require_once('change_password_form.php');
00029 
00030 $id     = optional_param('id', SITEID, PARAM_INT); // current course
00031 $return = optional_param('return', 0, PARAM_BOOL); // redirect after password change
00032 
00033 //HTTPS is required in this page when $CFG->loginhttps enabled
00034 $PAGE->https_required();
00035 
00036 $PAGE->set_url('/login/change_password.php', array('id'=>$id));
00037 
00038 $PAGE->set_context(get_context_instance(CONTEXT_SYSTEM));
00039 
00040 if ($return) {
00041     // this redirect prevents security warning because https can not POST to http pages
00042     if (empty($SESSION->wantsurl)
00043             or stripos(str_replace('https://', 'http://', $SESSION->wantsurl), str_replace('https://', 'http://', $CFG->wwwroot.'/login/change_password.php') === 0)) {
00044         $returnto = "$CFG->wwwroot/user/view.php?id=$USER->id&course=$id";
00045     } else {
00046         $returnto = $SESSION->wantsurl;
00047     }
00048     unset($SESSION->wantsurl);
00049 
00050     redirect($returnto);
00051 }
00052 
00053 $strparticipants = get_string('participants');
00054 
00055 $systemcontext = get_context_instance(CONTEXT_SYSTEM);
00056 
00057 if (!$course = $DB->get_record('course', array('id'=>$id))) {
00058     print_error('invalidcourseid');
00059 }
00060 
00061 // require proper login; guest user can not change password
00062 if (!isloggedin() or isguestuser()) {
00063     if (empty($SESSION->wantsurl)) {
00064         $SESSION->wantsurl = $CFG->httpswwwroot.'/login/change_password.php';
00065     }
00066     redirect(get_login_url());
00067 }
00068 
00069 // do not require change own password cap if change forced
00070 if (!get_user_preferences('auth_forcepasswordchange', false)) {
00071     require_capability('moodle/user:changeownpassword', $systemcontext);
00072 }
00073 
00074 // do not allow "Logged in as" users to change any passwords
00075 if (session_is_loggedinas()) {
00076     print_error('cannotcallscript');
00077 }
00078 
00079 if (is_mnet_remote_user($USER)) {
00080     $message = get_string('usercannotchangepassword', 'mnet');
00081     if ($idprovider = $DB->get_record('mnet_host', array('id'=>$USER->mnethostid))) {
00082         $message .= get_string('userchangepasswordlink', 'mnet', $idprovider);
00083     }
00084     print_error('userchangepasswordlink', 'mnet', '', $message);
00085 }
00086 
00087 // load the appropriate auth plugin
00088 $userauth = get_auth_plugin($USER->auth);
00089 
00090 if (!$userauth->can_change_password()) {
00091     print_error('nopasswordchange', 'auth');
00092 }
00093 
00094 if ($changeurl = $userauth->change_password_url()) {
00095     // this internal scrip not used
00096     redirect($changeurl);
00097 }
00098 
00099 $mform = new login_change_password_form();
00100 $mform->set_data(array('id'=>$course->id));
00101 
00102 $navlinks = array();
00103 $navlinks[] = array('name' => $strparticipants, 'link' => "$CFG->wwwroot/user/index.php?id=$course->id", 'type' => 'misc');
00104 
00105 if ($mform->is_cancelled()) {
00106     redirect($CFG->wwwroot.'/user/view.php?id='.$USER->id.'&amp;course='.$course->id);
00107 } else if ($data = $mform->get_data()) {
00108 
00109     if (!$userauth->user_update_password($USER, $data->newpassword1)) {
00110         print_error('errorpasswordupdate', 'auth');
00111     }
00112 
00113     // register success changing password
00114     unset_user_preference('auth_forcepasswordchange', $USER);
00115     unset_user_preference('create_password', $USER);
00116 
00117     $strpasswordchanged = get_string('passwordchanged');
00118 
00119     add_to_log($course->id, 'user', 'change password', "view.php?id=$USER->id&amp;course=$course->id", "$USER->id");
00120 
00121     $fullname = fullname($USER, true);
00122 
00123     $PAGE->navbar->add($fullname, new moodle_url('/user/view.php', array('id'=>$USER->id, 'course'=>$course->id)));
00124     $PAGE->navbar->add($strpasswordchanged);
00125     $PAGE->set_title($strpasswordchanged);
00126     $PAGE->set_heading($COURSE->fullname);
00127     echo $OUTPUT->header();
00128 
00129     notice($strpasswordchanged, new moodle_url($PAGE->url, array('return'=>1)));
00130 
00131     echo $OUTPUT->footer();
00132     exit;
00133 }
00134 
00135 // make sure we really are on the https page when https login required
00136 $PAGE->verify_https_required();
00137 
00138 $strchangepassword = get_string('changepassword');
00139 
00140 $fullname = fullname($USER, true);
00141 
00142 $PAGE->navbar->add($fullname, new moodle_url('/user/view.php', array('id'=>$USER->id, 'course'=>$course->id)));
00143 $PAGE->navbar->add($strchangepassword);
00144 $PAGE->set_title($strchangepassword);
00145 $PAGE->set_heading($COURSE->fullname);
00146 echo $OUTPUT->header();
00147 
00148 if (get_user_preferences('auth_forcepasswordchange')) {
00149     echo $OUTPUT->notification(get_string('forcepasswordchangenotice'));
00150 }
00151 $mform->display();
00152 echo $OUTPUT->footer();
 All Data Structures Namespaces Files Functions Variables Enumerations