2009-10-15 02:34:31 +00:00
< ? php
// Designed to be redirected from moodle/login/index.php
2005-04-17 13:06:25 +00:00
require ( '../../config.php' );
2010-01-16 15:39:56 +00:00
$PAGE -> set_url ( '/auth/shibboleth/index.php' );
2009-10-15 02:34:31 +00:00
2010-08-25 08:43:42 +00:00
if ( isloggedin () && ! isguestuser ()) { // Nothing to do
2007-01-04 04:52:42 +00:00
if ( isset ( $SESSION -> wantsurl ) and ( strpos ( $SESSION -> wantsurl , $CFG -> wwwroot ) === 0 )) {
2006-02-16 08:59:59 +00:00
$urltogo = $SESSION -> wantsurl ; /// Because it's an address in this site
unset ( $SESSION -> wantsurl );
2005-04-17 13:06:25 +00:00
2006-02-16 08:59:59 +00:00
} else {
$urltogo = $CFG -> wwwroot . '/' ; /// Go to the standard home page
unset ( $SESSION -> wantsurl ); /// Just in case
}
2007-02-20 17:03:36 +00:00
2006-02-16 08:59:59 +00:00
redirect ( $urltogo );
2009-11-01 11:55:14 +00:00
2006-02-16 08:59:59 +00:00
}
2006-06-02 16:42:40 +00:00
2005-06-13 07:54:44 +00:00
$pluginconfig = get_config ( 'auth/shibboleth' );
2007-03-09 13:20:55 +00:00
$shibbolethauth = get_auth_plugin ( 'shibboleth' );
2009-11-01 11:55:14 +00:00
2005-05-13 15:10:40 +00:00
// Check whether Shibboleth is configured properly
2007-01-04 04:52:42 +00:00
if ( empty ( $pluginconfig -> user_attribute )) {
2008-05-02 04:37:02 +00:00
print_error ( 'shib_not_set_up_error' , 'auth' );
2005-10-31 15:51:17 +00:00
}
2005-04-17 13:06:25 +00:00
2005-05-06 06:35:24 +00:00
/// If we can find the Shibboleth attribute, save it in session and return to main login page
2007-01-04 04:52:42 +00:00
if ( ! empty ( $_SERVER [ $pluginconfig -> user_attribute ])) { // Shibboleth auto-login
2007-07-11 08:04:12 +00:00
$frm -> username = strtolower ( $_SERVER [ $pluginconfig -> user_attribute ]);
2007-01-04 04:52:42 +00:00
$frm -> password = substr ( base64_encode ( $_SERVER [ $pluginconfig -> user_attribute ]), 0 , 8 );
2005-04-17 13:06:25 +00:00
// The random password consists of the first 8 letters of the base 64 encoded user ID
2007-02-20 17:03:36 +00:00
// This password is never used unless the user account is converted to manual
2005-04-17 13:06:25 +00:00
/// Check if the user has actually submitted login data to us
2007-02-20 17:03:36 +00:00
2007-03-09 13:20:55 +00:00
if ( $shibbolethauth -> user_login ( $frm -> username , $frm -> password )) {
2009-11-01 11:55:14 +00:00
2007-03-09 13:20:55 +00:00
$USER = authenticate_user_login ( $frm -> username , $frm -> password );
2009-11-01 11:55:14 +00:00
2007-03-09 13:20:55 +00:00
$USER -> loggedin = true ;
2009-11-01 11:55:14 +00:00
$USER -> site = $CFG -> wwwroot ; // for added security, store the site in the
2005-04-17 13:06:25 +00:00
update_user_login_times ();
2009-11-01 11:55:14 +00:00
2010-10-10 17:30:28 +00:00
// Don't show previous shibboleth username on login page
2007-05-08 15:07:25 +00:00
2005-04-17 13:06:25 +00:00
set_login_session_preferences ();
2009-11-01 11:55:14 +00:00
2007-03-09 13:20:55 +00:00
unset ( $SESSION -> lang );
$SESSION -> justloggedin = true ;
2009-11-01 11:55:14 +00:00
2007-03-09 13:20:55 +00:00
add_to_log ( SITEID , 'user' , 'login' , " view.php?id= $USER->id &course= " . SITEID , $USER -> id , 0 , $USER -> id );
2009-11-01 11:55:14 +00:00
2005-04-17 13:06:25 +00:00
if ( user_not_fully_set_up ( $USER )) {
$urltogo = $CFG -> wwwroot . '/user/edit.php?id=' . $USER -> id . '&course=' . SITEID ;
// We don't delete $SESSION->wantsurl yet, so we get there later
} else if ( isset ( $SESSION -> wantsurl ) and ( strpos ( $SESSION -> wantsurl , $CFG -> wwwroot ) === 0 )) {
$urltogo = $SESSION -> wantsurl ; /// Because it's an address in this site
unset ( $SESSION -> wantsurl );
} else {
$urltogo = $CFG -> wwwroot . '/' ; /// Go to the standard home page
unset ( $SESSION -> wantsurl ); /// Just in case
}
2007-02-20 17:03:36 +00:00
2010-05-14 06:41:44 +00:00
/// Go to my-moodle page instead of homepage if defaulthomepage enabled
if ( ! has_capability ( 'moodle/site:config' , get_context_instance ( CONTEXT_SYSTEM )) and ! empty ( $CFG -> defaulthomepage ) && $CFG -> defaulthomepage == HOMEPAGE_MY and ! isguestuser ()) {
2006-11-13 11:54:07 +00:00
if ( $urltogo == $CFG -> wwwroot or $urltogo == $CFG -> wwwroot . '/' or $urltogo == $CFG -> wwwroot . '/index.php' ) {
$urltogo = $CFG -> wwwroot . '/my/' ;
}
}
2007-02-20 17:03:36 +00:00
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
enrol_check_plugins ( $USER );
2006-11-13 11:54:07 +00:00
load_all_capabilities (); /// This is what lets the user do anything on the site :-)
2005-04-17 13:06:25 +00:00
redirect ( $urltogo );
2009-11-01 11:55:14 +00:00
2007-03-09 13:20:55 +00:00
exit ;
2009-11-01 11:55:14 +00:00
}
2007-03-09 13:20:55 +00:00
else {
// For some weird reason the Shibboleth user couldn't be authenticated
2005-04-17 13:06:25 +00:00
}
2006-02-16 08:59:59 +00:00
}
2007-02-20 17:03:36 +00:00
// If we can find any (user independent) Shibboleth attributes but no user
2005-10-31 15:51:17 +00:00
// attributes we probably didn't receive any user attributes
2008-12-08 10:49:44 +00:00
elseif ( ! empty ( $_SERVER [ 'HTTP_SHIB_APPLICATION_ID' ]) || ! empty ( $_SERVER [ 'Shib-Application-ID' ])) {
2008-05-02 04:37:02 +00:00
print_error ( 'shib_no_attributes_error' , 'auth' , '' , '\'' . $pluginconfig -> user_attribute . '\', \'' . $pluginconfig -> field_map_firstname . '\', \'' . $pluginconfig -> field_map_lastname . '\' and \'' . $pluginconfig -> field_map_email . '\'' );
2006-02-16 08:59:59 +00:00
} else {
2008-05-02 04:37:02 +00:00
print_error ( 'shib_not_set_up_error' , 'auth' );
2005-04-17 13:06:25 +00:00
}
2009-11-01 11:55:14 +00:00