Updated the 19 build version to 20100906
[moodle.git] / login / change_password.php
blobd80d59050a5b762aa64035c813a4892c3446519c
1 <?PHP // $Id$
3 require_once('../config.php');
4 require_once('change_password_form.php');
6 $id = optional_param('id', SITEID, PARAM_INT); // current course
8 $strparticipants = get_string('participants');
10 //HTTPS is potentially required in this page
11 httpsrequired();
13 $systemcontext = get_context_instance(CONTEXT_SYSTEM);
15 if (!$course = get_record('course', 'id', $id)) {
16 error('No such course!');
19 // require proper login; guest user can not change password
20 if (empty($USER->id) or isguestuser()) {
21 if (empty($SESSION->wantsurl)) {
22 $SESSION->wantsurl = $CFG->httpswwwroot.'/login/change_password.php';
24 redirect($CFG->httpswwwroot.'/login/index.php');
27 // do not require change own password cap if change forced
28 if (!get_user_preferences('auth_forcepasswordchange', false)) {
29 require_capability('moodle/user:changeownpassword', $systemcontext);
32 // do not allow "Logged in as" users to change any passwords
33 if (!empty($USER->realuser)) {
34 error('Can not use this script when "Logged in as"!');
37 if (is_mnet_remote_user($USER)) {
38 $message = get_string('usercannotchangepassword', 'mnet');
39 if ($idprovider = get_record('mnet_host', 'id', $USER->mnethostid)) {
40 $message .= get_string('userchangepasswordlink', 'mnet', $idprovider);
42 error($message);
45 // load the appropriate auth plugin
46 $userauth = get_auth_plugin($USER->auth);
48 if (!$userauth->can_change_password()) {
49 print_error('nopasswordchange', 'auth');
52 if ($changeurl = $userauth->change_password_url()) {
53 // this internal scrip not used
54 redirect($changeurl);
57 $mform = new login_change_password_form();
58 $mform->set_data(array('id'=>$course->id));
60 $navlinks = array();
61 $navlinks[] = array('name' => $strparticipants, 'link' => "$CFG->wwwroot/user/index.php?id=$course->id", 'type' => 'misc');
63 if ($mform->is_cancelled()) {
64 redirect($CFG->wwwroot.'/user/view.php?id='.$USER->id.'&amp;course='.$course->id);
65 } else if ($data = $mform->get_data()) {
67 if (!$userauth->user_update_password(addslashes_recursive($USER), $data->newpassword1)) {
68 print_error('errorpasswordupdate', 'auth');
71 // register success changing password
72 unset_user_preference('auth_forcepasswordchange', $USER->id);
74 $strpasswordchanged = get_string('passwordchanged');
76 add_to_log($course->id, 'user', 'change password', "view.php?id=$USER->id&amp;course=$course->id", "$USER->id");
78 $fullname = fullname($USER, true);
80 $navlinks[] = array('name' => $fullname,
81 'link' => "$CFG->wwwroot/user/view.php?id=$USER->id&amp;course=$course->id",
82 'type' => 'misc');
83 $navlinks[] = array('name' => $strpasswordchanged, 'link' => null, 'type' => 'misc');
84 $navigation = build_navigation($navlinks);
86 print_header($strpasswordchanged, $strpasswordchanged, $navigation);
88 if (empty($SESSION->wantsurl) or $SESSION->wantsurl == $CFG->httpswwwroot.'/login/change_password.php') {
89 $returnto = "$CFG->wwwroot/user/view.php?id=$USER->id&amp;course=$id";
90 } else {
91 $returnto = $SESSION->wantsurl;
94 notice($strpasswordchanged, $returnto);
96 print_footer();
97 exit;
101 $strchangepassword = get_string('changepassword');
103 $fullname = fullname($USER, true);
105 $navlinks[] = array('name' => $fullname, 'link' => "$CFG->wwwroot/user/view.php?id=$USER->id&amp;course=$course->id", 'type' => 'misc');
106 $navlinks[] = array('name' => $strchangepassword, 'link' => null, 'type' => 'misc');
107 $navigation = build_navigation($navlinks);
108 // Turn off pop-up messaging window for this page
109 $CFG->messaging = 0;
110 print_header($strchangepassword, $strchangepassword, $navigation);
111 if (get_user_preferences('auth_forcepasswordchange')) {
112 notify(get_string('forcepasswordchangenotice'));
114 $mform->display();
115 print_footer();