| 1 |
<?php |
<?php |
| 2 |
// $Id: singlesignon.module,v 1.21.2.10 2008/05/02 03:51:38 wayland76 Exp $ |
// $Id: singlesignon.module,v 1.21.2.11 2008/05/03 11:35:50 wayland76 Exp $ |
| 3 |
|
|
| 4 |
|
|
| 5 |
/** |
/** |
| 49 |
* |
* |
| 50 |
* @link http://drupal.org/project/singlesignon |
* @link http://drupal.org/project/singlesignon |
| 51 |
* @author Daniel Convissor <danielc@analysisandsolutions.com> |
* @author Daniel Convissor <danielc@analysisandsolutions.com> |
| 52 |
* @version $Revision: 1.21.2.10 $ (HEAD) |
* @version $Revision: 1.21.2.11 $ (HEAD) |
| 53 |
*/ |
*/ |
| 54 |
|
|
| 55 |
// {{{ core functions |
// {{{ core functions |
| 99 |
return; |
return; |
| 100 |
} |
} |
| 101 |
|
|
|
// url() only available if bootstrap has reached FULL. |
|
|
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL); |
|
|
|
|
| 102 |
// This is the user's first hit to a slave site. Take note of their |
// This is the user's first hit to a slave site. Take note of their |
| 103 |
// session ID, since that's how we tell if they've been here or not. |
// session ID, since that's how we tell if they've been here or not. |
| 104 |
// Then go to the master site to see if they are logged in over there. |
// Then go to the master site to see if they are logged in over there. |
| 105 |
$_SESSION['singlesignon_prior_sid'] = session_id(); |
$_SESSION['singlesignon_prior_sid'] = session_id(); |
| 106 |
$query = 'slave_session='. session_id() .'&singlesignon_dest='. _singlesignon_get_dest(); |
|
| 107 |
_singlesignon_goto($master_url . url('singlesignon/initial_check', $query)); |
_singlesignon_goto_url('singlesignon/initial_check'); |
| 108 |
} |
} |
| 109 |
} |
} |
| 110 |
|
|
| 156 |
return; |
return; |
| 157 |
} |
} |
| 158 |
else if ($user->uid) { |
else if ($user->uid) { |
|
// url() only available if bootstrap has reached FULL. |
|
|
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL); |
|
|
|
|
| 159 |
// Tell the master site the user just logged in. |
// Tell the master site the user just logged in. |
| 160 |
$query = 'slave_session='. session_id() .'&singlesignon_dest='. _singlesignon_get_dest(); |
_singlesignon_goto_url('singlesignon/login'); |
|
_singlesignon_goto($master_url . url('singlesignon/login', $query)); |
|
| 161 |
} |
} |
| 162 |
} |
} |
| 163 |
} |
} |
| 208 |
// }}} |
// }}} |
| 209 |
// {{{ helper functions |
// {{{ helper functions |
| 210 |
|
|
| 211 |
|
/** |
| 212 |
|
* Sets up the URL and goes to it |
| 213 |
|
*/ |
| 214 |
|
function _singlesignon_goto_url($url) { |
| 215 |
|
// url() only available if bootstrap has reached FULL. |
| 216 |
|
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL); |
| 217 |
|
|
| 218 |
|
$query = 'slave_session='. session_id() .'&singlesignon_dest='. _singlesignon_get_dest(); |
| 219 |
|
_singlesignon_goto($master_url . url($url, $query)); |
| 220 |
|
} |
| 221 |
|
|
| 222 |
|
/** |
| 223 |
|
* Gets the SQL to update the sessions a bit -- can equivalent code be found somewhere else? |
| 224 |
|
*/ |
| 225 |
function _singlesignon_get_sql($user) { |
function _singlesignon_get_sql($user) { |
| 226 |
$in = substr(str_repeat("'%s',", count($_SESSION['singlesignon_slave_sessions'])), 0, -1); |
$in = substr(str_repeat("'%s',", count($_SESSION['singlesignon_slave_sessions'])), 0, -1); |
| 227 |
$sql = "UPDATE {sessions} SET uid = %d WHERE sid IN ($in)"; // I know the coder module complains about this, but it appears to be necessary in this case |
$sql = "UPDATE {sessions} SET uid = %d WHERE sid IN ($in)"; // I know the coder module complains about this, but it appears to be necessary in this case |