2 // Designed to be redirected from moodle/login/index.php
4 require('../../config.php');
6 if (isloggedin() && $USER->username
!= 'guest') { // Nothing to do
7 if (isset($SESSION->wantsurl
) and (strpos($SESSION->wantsurl
, $CFG->wwwroot
) === 0)) {
8 $urltogo = $SESSION->wantsurl
; /// Because it's an address in this site
9 unset($SESSION->wantsurl
);
12 $urltogo = $CFG->wwwroot
.'/'; /// Go to the standard home page
13 unset($SESSION->wantsurl
); /// Just in case
20 $pluginconfig = get_config('auth/shibboleth');
21 $shibbolethauth = get_auth_plugin('shibboleth');
23 // Check whether Shibboleth is configured properly
24 if (empty($pluginconfig->user_attribute
)) {
25 print_error('shib_not_set_up_error', 'auth');
28 /// If we can find the Shibboleth attribute, save it in session and return to main login page
29 if (!empty($_SERVER[$pluginconfig->user_attribute
])) { // Shibboleth auto-login
30 $frm->username
= strtolower($_SERVER[$pluginconfig->user_attribute
]);
31 $frm->password
= substr(base64_encode($_SERVER[$pluginconfig->user_attribute
]),0,8);
32 // The random password consists of the first 8 letters of the base 64 encoded user ID
33 // This password is never used unless the user account is converted to manual
35 /// Check if the user has actually submitted login data to us
37 if ($shibbolethauth->user_login($frm->username
, $frm->password
)) {
39 $USER = authenticate_user_login($frm->username
, $frm->password
);
41 $USER->loggedin
= true;
42 $USER->site
= $CFG->wwwroot
; // for added security, store the site in the
44 update_user_login_times();
46 // Don't show username on login page
47 set_moodle_cookie('nobody');
49 set_login_session_preferences();
51 unset($SESSION->lang
);
52 $SESSION->justloggedin
= true;
54 add_to_log(SITEID
, 'user', 'login', "view.php?id=$USER->id&course=".SITEID
, $USER->id
, 0, $USER->id
);
56 if (user_not_fully_set_up($USER)) {
57 $urltogo = $CFG->wwwroot
.'/user/edit.php?id='.$USER->id
.'&course='.SITEID
;
58 // We don't delete $SESSION->wantsurl yet, so we get there later
60 } else if (isset($SESSION->wantsurl
) and (strpos($SESSION->wantsurl
, $CFG->wwwroot
) === 0)) {
61 $urltogo = $SESSION->wantsurl
; /// Because it's an address in this site
62 unset($SESSION->wantsurl
);
65 $urltogo = $CFG->wwwroot
.'/'; /// Go to the standard home page
66 unset($SESSION->wantsurl
); /// Just in case
69 /// Go to my-moodle page instead of homepage if mymoodleredirect enabled
70 if (!has_capability('moodle/site:config',get_context_instance(CONTEXT_SYSTEM
)) and !empty($CFG->mymoodleredirect
) and !isguest()) {
71 if ($urltogo == $CFG->wwwroot
or $urltogo == $CFG->wwwroot
.'/' or $urltogo == $CFG->wwwroot
.'/index.php') {
72 $urltogo = $CFG->wwwroot
.'/my/';
76 check_enrolment_plugins($USER);
77 load_all_capabilities(); /// This is what lets the user do anything on the site :-)
85 // For some weird reason the Shibboleth user couldn't be authenticated
89 // If we can find any (user independent) Shibboleth attributes but no user
90 // attributes we probably didn't receive any user attributes
91 elseif (!empty($_SERVER['HTTP_SHIB_APPLICATION_ID']) ||
!empty($_SERVER['Shib-Application-ID'])) {
92 print_error('shib_no_attributes_error', 'auth' , '', '\''.$pluginconfig->user_attribute
.'\', \''.$pluginconfig->field_map_firstname
.'\', \''.$pluginconfig->field_map_lastname
.'\' and \''.$pluginconfig->field_map_email
.'\'');
94 print_error('shib_not_set_up_error', 'auth');