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
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);
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
57 $mform = new login_change_password_form();
58 $mform->set_data(array('id'=>$course->id
));
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
.'&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&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&course=$course->id",
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&course=$id";
91 $returnto = $SESSION->wantsurl
;
94 notice($strpasswordchanged, $returnto);
101 $strchangepassword = get_string('changepassword');
103 $fullname = fullname($USER, true);
105 $navlinks[] = array('name' => $fullname, 'link' => "$CFG->wwwroot/user/view.php?id=$USER->id&course=$course->id", 'type' => 'misc');
106 $navlinks[] = array('name' => $strchangepassword, 'link' => null, 'type' => 'misc');
107 $navigation = build_navigation($navlinks);
109 print_header($strchangepassword, $strchangepassword, $navigation);
110 if (get_user_preferences('auth_forcepasswordchange')) {
111 notify(get_string('forcepasswordchangenotice'));