Automatic installer.php lang files by installer_builder (20070726)
[moodle-linuxchix.git] / login / change_password.php
blobe9647f74c69eb74cb3fee41fb632b9f3004ad643
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 //HTTPS is potentially required in this page
9 httpsrequired();
11 $systemcontext = get_context_instance(CONTEXT_SYSTEM);
13 if (!$course = get_record('course', 'id', $id)) {
14 error('No such course!');
17 // require proper login; guest user can not change password
18 if (empty($USER->id) or isguestuser()) {
19 if (empty($SESSION->wantsurl)) {
20 $SESSION->wantsurl = $CFG->httpswwwroot.'/login/change_password.php';
22 redirect($CFG->httpswwwroot.'/login/index.php');
25 // do not require change own password cap if change forced
26 if (!get_user_preferences('auth_forcepasswordchange', false)) {
27 require_capability('moodle/user:changeownpassword', $systemcontext);
30 // do not allow "Logged in as" users to change any passwords
31 if (!empty($USER->realuser)) {
32 error('Can not use this script when "Logged in as"!');
35 if (is_mnet_remote_user($USER)) {
36 $message = get_string('usercannotchangepassword', 'mnet');
37 if ($idprovider = get_record('mnet_host', 'id', $USER->mnethostid)) {
38 $message .= get_string('userchangepasswordlink', 'mnet', $idprovider);
40 error($message);
43 // load the appropriate auth plugin
44 $userauth = get_auth_plugin($USER->auth);
46 if (!$userauth->can_change_password()) {
47 error(get_string('nopasswordchange', 'auth'));
50 if ($changeurl = $userauth->change_password_url()) {
51 // this internal scrip not used
52 redirect($changeurl);
55 $mform = new login_change_password_form();
56 $mform->set_data(array('id'=>$course->id));
58 if ($mform->is_cancelled()) {
59 redirect($CFG->wwwroot.'/user/view.php?id='.$USER->id.'&amp;course='.$course->id);
60 } else if ($data = $mform->get_data()) {
62 if (!$userauth->user_update_password(addslashes_recursive($USER), $data->newpassword1)) {
63 error(get_string('errorpasswordupdate', 'auth'));
66 // register success changing password
67 unset_user_preference('auth_forcepasswordchange', $USER->id);
69 $strpasswordchanged = get_string('passwordchanged');
71 // MDL-9983
72 $eventdata = new object();
73 $eventdata -> user = $USER;
74 $eventdata -> newpassword = $data -> newpassword1;
75 events_trigger('password_changed', $eventdata);
77 add_to_log($course->id, 'user', 'change password', "view.php?id=$USER->id&amp;course=$course->id", "$USER->id");
79 $fullname = fullname($USER, true);
81 if ($course->id != SITEID) {
82 $navstr = "<a href=\"$CFG->wwwroot/course/view.php?id=$course->id\">$course->shortname</a> -> ";
83 } else {
84 $navstr = '';
86 $navstr .= "<a href=\"$CFG->wwwroot/user/index.php?id=$course->id\">".get_string("participants")."</a> -> <a href=\"$CFG->wwwroot/user/view.php?id=$USER->id&amp;course=$course->id\">$fullname</a> -> $strpasswordchanged";
88 print_header($strpasswordchanged, $strpasswordchanged, $navstr);
90 if (empty($SESSION->wantsurl) or $SESSION->wantsurl == $CFG->httpswwwroot.'/login/change_password.php') {
91 $returnto = "$CFG->wwwroot/user/view.php?id=$USER->id&amp;course=$id";
92 } else {
93 $returnto = $SESSION->wantsurl;
96 notice($strpasswordchanged, $returnto);
98 print_footer();
99 exit;
103 $strchangepassword = get_string('changepassword');
105 $fullname = fullname($USER, true);
107 if ($course->id != SITEID) {
108 $navstr = "<a href=\"$CFG->wwwroot/course/view.php?id=$course->id\">$course->shortname</a> -> ";
109 } else {
110 $navstr = '';
112 $navstr .= "<a href=\"$CFG->wwwroot/user/index.php?id=$course->id\">".get_string('participants')."</a> -> <a href=\"$CFG->wwwroot/user/view.php?id=$USER->id&amp;course=$course->id\">$fullname</a> -> $strchangepassword";
115 print_header($strchangepassword, $strchangepassword, $navstr);
116 if (get_user_preferences('auth_forcepasswordchange')) {
117 notify(get_string('forcepasswordchangenotice'));
119 $mform->display();
120 print_footer();