2 // Designed to be redirected from moodle/login/index.php
4 require('../../config.php');
7 if (isloggedin() && $USER->username
!= 'guest') { // Nothing to do
8 if (isset($SESSION->wantsurl
) and (strpos($SESSION->wantsurl
, $CFG->wwwroot
) === 0)) {
9 $urltogo = $SESSION->wantsurl
; /// Because it's an address in this site
10 unset($SESSION->wantsurl
);
13 $urltogo = $CFG->wwwroot
.'/'; /// Go to the standard home page
14 unset($SESSION->wantsurl
); /// Just in case
20 $pluginconfig = get_config('auth/shibboleth');
22 // Check whether Shibboleth is configured properly
23 if (empty($pluginconfig->user_attribute
)) {
24 error(get_string( 'shib_not_set_up_error', 'auth'));
27 /// If we can find the Shibboleth attribute, save it in session and return to main login page
28 if (!empty($_SERVER[$pluginconfig->user_attribute
])) { // Shibboleth auto-login
29 $frm->username
= $_SERVER[$pluginconfig->user_attribute
];
30 $frm->password
= substr(base64_encode($_SERVER[$pluginconfig->user_attribute
]),0,8);
31 // The random password consists of the first 8 letters of the base 64 encoded user ID
32 // This password is never used unless the user account is converted to manual
34 /// Check if the user has actually submitted login data to us
36 if ($user = authenticate_user_login($frm->username
, $frm->password
)) {
38 // Let's get them all set up.
41 add_to_log(SITEID
, 'user', 'login', "view.php?id=$USER->id&course=".SITEID
, $USER->id
, 0, $USER->id
);
43 update_user_login_times();
44 set_moodle_cookie($USER->username
);
45 set_login_session_preferences();
47 if (user_not_fully_set_up($USER)) {
48 $urltogo = $CFG->wwwroot
.'/user/edit.php?id='.$USER->id
.'&course='.SITEID
;
49 // We don't delete $SESSION->wantsurl yet, so we get there later
51 } else if (isset($SESSION->wantsurl
) and (strpos($SESSION->wantsurl
, $CFG->wwwroot
) === 0)) {
52 $urltogo = $SESSION->wantsurl
; /// Because it's an address in this site
53 unset($SESSION->wantsurl
);
56 $urltogo = $CFG->wwwroot
.'/'; /// Go to the standard home page
57 unset($SESSION->wantsurl
); /// Just in case
60 /// Go to my-moodle page instead of homepage if mymoodleredirect enabled
61 if (!has_capability('moodle/site:config',get_context_instance(CONTEXT_SYSTEM
, SITEID
)) and !empty($CFG->mymoodleredirect
) and !isguest()) {
62 if ($urltogo == $CFG->wwwroot
or $urltogo == $CFG->wwwroot
.'/' or $urltogo == $CFG->wwwroot
.'/index.php') {
63 $urltogo = $CFG->wwwroot
.'/my/';
67 load_all_capabilities(); /// This is what lets the user do anything on the site :-)
73 // If we can find any (user independent) Shibboleth attributes but no user
74 // attributes we probably didn't receive any user attributes
75 elseif (!empty($_SERVER['HTTP_SHIB_APPLICATION_ID'])) {
76 error(get_string( 'shib_no_attributes_error', 'auth' , '\''.$pluginconfig->user_attribute
.'\', \''.$pluginconfig->field_map_firstname
.'\', \''.$pluginconfig->field_map_lastname
.'\' and \''.$pluginconfig->field_map_email
.'\''));
78 error(get_string( 'shib_not_set_up_error', 'auth'));