Changeset 722 for trunk/wifidog-auth/wifidog/classes/Authenticator.php
- Timestamp:
- 09/07/05 23:52:27 (8 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
trunk/wifidog-auth/wifidog/classes/Authenticator.php
r717 r722 1 1 <?php 2 2 3 /********************************************************************\ 3 4 * This program is free software; you can redistribute it and/or * … … 33 34 $this->mAccountOrigin = $account_orgin; 34 35 } 35 36 36 37 public function getAccountOrigin() 37 38 { 38 return $this->mAccountOrigin; 39 return $this->mAccountOrigin; 39 40 } 40 41 … … 44 45 } 45 46 46 /** Logs out the user */ 47 function logout() 47 /** Logs out the user 48 * $conn_id: The connection id for the connection to work on. Optionnal. 49 * If it is not present, the behaviour depends if the network supports 50 * multiple logins. If it does not, all connections associated with the 51 * current user will be destroyed. If it does, only the connections 52 * tied to the current node will be destroyed */ 53 function logout($conn_id = null) 48 54 { 55 global $db; 56 $conn_id = $db->escapeString($conn_id); 57 if (!empty ($conn_id)) 58 { 59 $db->ExecSqlUniqueRes("SELECT NOW(), *, CASE WHEN ((NOW() - reg_date) > networks.validation_grace_time) THEN true ELSE false END AS validation_grace_time_expired FROM connections JOIN users ON (users.user_id=connections.user_id) JOIN networks ON (users.account_origin = networks.network_id) WHERE connections.conn_id='$conn_id'", $info, false); 60 61 $user = User :: getObject($info['user_id']); 62 $network = $user->getNetwork(); 63 $splash_user_id = $network->getSplashOnlyUser()->getId(); 64 $this->acctStop($conn_id); 65 } 66 else 67 { 68 $user = User :: getCurrentUser(); 69 $network = $user->getNetwork(); 70 $splash_user_id = $network->getSplashOnlyUser()->getId(); 71 if ($splash_user_id != $user->getId() && $node = Node :: getCurrentNode()) 72 { 73 //Try to destroy all connections tied to the current node 74 $sql = "SELECT conn_id FROM connections WHERE user_id = '{$user->getId()}' AND node_id={$node->getId()} AND token_status='".TOKEN_INUSE."';\n"; 75 $conn_rows = null; 76 $db->ExecSql($sql, $conn_rows, false); 77 if($conn_rows) 78 { 79 foreach ($conn_rows as $conn_row) 80 { 81 $this->acctStop($conn_row['conn_id']); 82 } 83 } 84 } 85 } 86 87 if ($splash_user_id != $user->getId() && $network->getMultipleLoginAllowed() == false) 88 { 89 /* The user isn't the splash_only user and the network config does not allow multiple logins. 90 * Logging in with a new token implies that all other active tokens should expire */ 91 $sql = "SELECT conn_id FROM connections WHERE user_id = '{$user->getId()}' AND token_status='".TOKEN_INUSE."';\n"; 92 $conn_rows = null; 93 $db->ExecSql($sql, $conn_rows, false); 94 if($conn_rows) 95 { 96 foreach ($conn_rows as $conn_row) 97 { 98 $this->acctStop($conn_row['conn_id']); 99 } 100 } 101 } 102 global $session; 103 $session->destroy(); 104 49 105 } 50 106 … … 52 108 * $conn_id: The connection id for the connection to work on */ 53 109 function acctStart($conn_id) 54 {//$info['conn_id'] 110 { 111 //$info['conn_id'] 55 112 global $db; 56 113 $conn_id = $db->escapeString($conn_id); 57 114 $db->ExecSqlUniqueRes("SELECT NOW(), *, CASE WHEN ((NOW() - reg_date) > networks.validation_grace_time) THEN true ELSE false END AS validation_grace_time_expired FROM connections JOIN users ON (users.user_id=connections.user_id) JOIN networks ON (users.account_origin = networks.network_id) WHERE connections.conn_id='$conn_id'", $info, false); 58 $network = Network::getObject($info['network_id']);115 $network = Network :: getObject($info['network_id']); 59 116 $splash_user_id = $network->getSplashOnlyUser()->getId(); 60 117 $auth_response = $info['account_status']; … … 64 121 $sql = "UPDATE connections SET "."token_status='".TOKEN_INUSE."',"."user_mac='$mac',"."user_ip='$ip',"."last_updated=NOW()"."WHERE conn_id='{$conn_id}';\n"; 65 122 $db->ExecSqlUpdate($sql, false); 66 if ($splash_user_id != $info['user_id'] && $network->getMultipleLoginAllowed()==false)123 if ($splash_user_id != $info['user_id'] && $network->getMultipleLoginAllowed() == false) 67 124 { 68 125 /* The user isn't the splash_only user and the network config does not allow multiple logins. 69 126 * Logging in with a new token implies that all other active tokens should expire */ 70 127 $token = $db->EscapeString($_REQUEST['token']); 71 $sql = "UPDATE connections SET "."timestamp_out=NOW(), token_status='".TOKEN_USED."' "."WHERE user_id = '{$info['user_id']}' AND token_status='".TOKEN_INUSE."' AND token!='$token';\n"; 72 $db->ExecSqlUpdate($sql, false); 128 $sql = "SELECT * FROM connections WHERE user_id = '{$info['user_id']}' AND token_status='".TOKEN_INUSE."' AND token!='$token';\n"; 129 $conn_rows = array (); 130 $db->ExecSql($sql, $conn_rows, true); 131 foreach ($conn_rows as $conn_row) 132 { 133 $this->acctStop($conn_row['conn_id']); 134 } 73 135 } 74 136 75 137 /* Delete all unused tokens for this user, so we don't fill the database with them */ 76 138 $sql = "DELETE FROM connections "."WHERE token_status='".TOKEN_UNUSED."' AND user_id = '{$info['user_id']}';\n"; … … 91 153 * $conn_id: The connection id (the token id) for the connection to work on 92 154 * */ 93 function acctStop($conn_id)155 function acctStop($conn_id) 94 156 { 95 157 // Stop traffic counters update … … 98 160 $db->ExecSqlUpdate("UPDATE connections SET "."timestamp_out=NOW(),"."token_status='".TOKEN_USED."' "."WHERE conn_id='{$conn_id}';\n", false); 99 161 } 100 162 101 163 /** 102 164 * Property method that tells if the class allows registration
