| [ Index ] |
PHP Cross Reference of Moodle 1.9.3 [Build 15-Oct-2008] |
[Summary view] [Print] [Text view]
1 <?PHP // $Id: change_password.php,v 1.62.2.2 2008/07/06 17:55:57 skodak Exp $ 2 3 require_once ('../config.php'); 4 require_once ('change_password_form.php'); 5 6 $id = optional_param('id', SITEID, PARAM_INT); // current course 7 8 $strparticipants = get_string('participants'); 9 10 //HTTPS is potentially required in this page 11 httpsrequired(); 12 13 $systemcontext = get_context_instance(CONTEXT_SYSTEM); 14 15 if (!$course = get_record('course', 'id', $id)) { 16 error('No such course!'); 17 } 18 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'; 23 } 24 redirect($CFG->httpswwwroot.'/login/index.php'); 25 } 26 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); 30 } 31 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"!'); 35 } 36 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); 41 } 42 error($message); 43 } 44 45 // load the appropriate auth plugin 46 $userauth = get_auth_plugin($USER->auth); 47 48 if (!$userauth->can_change_password()) { 49 print_error('nopasswordchange', 'auth'); 50 } 51 52 if ($changeurl = $userauth->change_password_url()) { 53 // this internal scrip not used 54 redirect($changeurl); 55 } 56 57 $mform = new login_change_password_form(); 58 $mform->set_data(array('id'=>$course->id)); 59 60 $navlinks = array(); 61 $navlinks[] = array('name' => $strparticipants, 'link' => "$CFG->wwwroot/user/index.php?id=$course->id", 'type' => 'misc'); 62 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()) { 66 67 if (!$userauth->user_update_password(addslashes_recursive($USER), $data->newpassword1)) { 68 print_error('errorpasswordupdate', 'auth'); 69 } 70 71 // register success changing password 72 unset_user_preference('auth_forcepasswordchange', $USER->id); 73 74 $strpasswordchanged = get_string('passwordchanged'); 75 76 add_to_log($course->id, 'user', 'change password', "view.php?id=$USER->id&course=$course->id", "$USER->id"); 77 78 $fullname = fullname($USER, true); 79 80 $navlinks[] = array('name' => $fullname, 81 'link' => "$CFG->wwwroot/user/view.php?id=$USER->id&course=$course->id", 82 'type' => 'misc'); 83 $navlinks[] = array('name' => $strpasswordchanged, 'link' => null, 'type' => 'misc'); 84 $navigation = build_navigation($navlinks); 85 86 print_header($strpasswordchanged, $strpasswordchanged, $navigation); 87 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"; 90 } else { 91 $returnto = $SESSION->wantsurl; 92 } 93 94 notice($strpasswordchanged, $returnto); 95 96 print_footer(); 97 exit; 98 } 99 100 101 $strchangepassword = get_string('changepassword'); 102 103 $fullname = fullname($USER, true); 104 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); 108 109 print_header($strchangepassword, $strchangepassword, $navigation); 110 if (get_user_preferences('auth_forcepasswordchange')) { 111 notify(get_string('forcepasswordchangenotice')); 112 } 113 $mform->display(); 114 print_footer(); 115 116 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Wed Jan 14 11:33:29 2009 | Cross-referenced by PHPXref 0.7 |