/[drupal]/contributions/modules/singlesignon/singlesignon.module
ViewVC logotype

Diff of /contributions/modules/singlesignon/singlesignon.module

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph | View Patch Patch

revision 1.29, Mon May 5 11:02:29 2008 UTC revision 1.30, Mon May 5 12:44:00 2008 UTC
# Line 1  Line 1 
1  <?php  <?php
2  // $Id: singlesignon.module,v 1.28 2008/05/05 04:15:43 wayland76 Exp $  // $Id: singlesignon.module,v 1.29 2008/05/05 11:02:29 wayland76 Exp $
3    
4    
5  /**  /**
# Line 48  Line 48 
48   * @endverbatim   * @endverbatim
49   *   *
50   * @link     http://drupal.org/project/singlesignon   * @link     http://drupal.org/project/singlesignon
51   * @author   Daniel Convissor <danielc@analysisandsolutions.com>   * @author   Primary Author: Daniel Convissor <danielc@analysisandsolutions.com>
52   * @version  $Revision: 1.28 $  (HEAD)   * @author   Maintainer: Tim Nelson <wayland@wayland.id.au>
53     * @version  $Revision: 1.29 $
54   */   */
55    
56  // {{{ core functions  // {{{ core functions
57    
58    include_once('sessions_extra.inc');
59    
60  /**  /**
61   * Implementation of hook_boot().   * Implementation of hook_boot().
62   *   *
# Line 115  function singlesignon_boot() { Line 118  function singlesignon_boot() {
118    
119    switch ($arg0) {    switch ($arg0) {
120      case 'logout':      case 'logout':
       // User is in the middle of logging out.  Delete all other session  
       // records belonging to the current user.  
       // Don't delete the user's session on the present website because this  
       // session is needed for Drupal's regular logout process which takes  
       // place after the singlesignon module is executed.  
121        if ($user->uid) {        if ($user->uid) {
122          db_query("DELETE FROM {sessions} WHERE uid = %d AND sid <> '%s'", $user->uid, session_id());          _singlesignon_session_logout($user->uid);
123        }        }
124        return;        return;
125    
# Line 152  function singlesignon_boot() { Line 150  function singlesignon_boot() {
150        }        }
151        // User just logged into the master server.  Update the slave sessions'        // User just logged into the master server.  Update the slave sessions'
152        // user ID's to be the user ID they have on the master server.        // user ID's to be the user ID they have on the master server.
153        _singlesignon_get_sql($user);        _singlesignon_session_update_all_uids($user->uid);
154        return;        return;
155      }      }
156      else if ($user->uid) {      else if ($user->uid) {
# Line 186  function _singlesignon_master($master_ur Line 184  function _singlesignon_master($master_ur
184        if ($user->uid) {        if ($user->uid) {
185          // User is already logged into the master server.  Update the slave          // User is already logged into the master server.  Update the slave
186          // session's user ID to be the user ID they have on the master server.          // session's user ID to be the user ID they have on the master server.
187          db_query("UPDATE {sessions} AS sess_slave LEFT JOIN {sessions} AS sess_master ON (sess_master.sid = '%s' AND sess_slave.sid = '%s') SET sess_slave.uid = sess_master.uid WHERE sess_slave.sid = '%s'", session_id(), $_GET['slave_session'], $_GET['slave_session']);          _singlesignon_session_update_user();
188        }        }
189        _singlesignon_goto($_GET['singlesignon_dest']);        _singlesignon_goto($_GET['singlesignon_dest']);
190        break;        break;
# Line 194  function _singlesignon_master($master_ur Line 192  function _singlesignon_master($master_ur
192      case 'login':      case 'login':
193        // User is coming to the master site to say they just logged on to a        // User is coming to the master site to say they just logged on to a
194        // slave.  Set master site's user ID to be their one from the slave.        // slave.  Set master site's user ID to be their one from the slave.
195        $result    = db_query("SELECT uid FROM {sessions} WHERE sid = '%s'", $_GET['slave_session']);        _singlesignon_session_login($user);
       $row       = db_fetch_array($result);  
       $user->uid = $row['uid'];  
   
       // Update all sessions' user IDs to the current one.  
       _singlesignon_get_sql($user);  
196        _singlesignon_goto($_GET['singlesignon_dest']);        _singlesignon_goto($_GET['singlesignon_dest']);
197    }    }
198  }  }
# Line 220  function _singlesignon_goto_url($url) { Line 213  function _singlesignon_goto_url($url) {
213  }  }
214    
215  /**  /**
  * Gets the SQL to update the sessions a bit -- can equivalent code be found somewhere else?  
  */  
 function _singlesignon_get_sql($user) {  
   $in   = substr(str_repeat("'%s',", count($_SESSION['singlesignon_slave_sessions'])), 0, -1);  
   $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  
   $args = array_merge(array($sql), array($user->uid), $_SESSION['singlesignon_slave_sessions']);  
   call_user_func_array('db_query', $args);  
 }  
   
 /**  
216   * Gets the base url and fixess it up a bit   * Gets the base url and fixess it up a bit
217   */   */
218  function _singlesignon_base_url() {  function _singlesignon_base_url() {

Legend:
Removed from v.1.29  
changed lines
  Added in v.1.30

  ViewVC Help
Powered by ViewVC 1.1.2