Changeset 1453 for trunk/wifidog-auth/wifidog/ws/classes/WifidogWS/V1.php
- Timestamp:
- 02/25/10 15:56:33 (2 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
trunk/wifidog-auth/wifidog/ws/classes/WifidogWS/V1.php
r1439 r1453 103 103 'NumOnlineUsers' => 'NumOnlineUsers', 104 104 'CreationDate' => 'CreationDate', 105 'Status' => ' Status',105 'Status' => 'DeploymentStatus', 106 106 'OpeningDate' => 'CreationDate', 107 107 'Connected_users' => 'OnlineUsers'), … … 150 150 foreach($infields as $field) { 151 151 if (isset(self::$_allowedFields[$objectClass][$field])) 152 $fields[ ] = self::$_allowedFields[$objectClass][$field];152 $fields[$field] = self::$_allowedFields[$objectClass][$field]; 153 153 else 154 $fields[ ] = "$field.forbidden";154 $fields[$field] = "$field.forbidden"; 155 155 } 156 156 return $fields; … … 189 189 $username = (isset($this->_params['username']) ? $this->_params['username']:''); 190 190 $password = (isset($this->_params['password']) ? $this->_params['password']:''); 191 $this->executeAuth($username, $password, $gw_id, $gw_address, $mac, $gw_port, $from); 191 $logout = (isset($this->_params['logout']) ? $this->_params['logout']:false); 192 $this->executeAuth($username, $password, $gw_id, $gw_address, $mac, $gw_port, $from, $logout); 192 193 break; 193 194 default: … … 204 205 * @param $gw_id The gateway id 205 206 * @param $gw_ip The gateway's ip addresss 207 * @param $mac The mac address of the user 208 * @param $gw_port The port of the gateway's http server 209 * @param $from The ip address of the user on the node 210 * @param $logout Whether the user wants to logout 206 211 * @return unknown_type 207 212 */ 208 protected function executeAuth($username = null, $password = null, $gw_id = null, $gw_ip = null, $mac = null, $gw_port = null, $from = null ) {213 protected function executeAuth($username = null, $password = null, $gw_id = null, $gw_ip = null, $mac = null, $gw_port = null, $from = null, $logout = false) { 209 214 $this->_outputArr['auth'] = 0; 210 215 … … 240 245 if (!$token) throw new WSException("User authenticated but cannot generate connection token.", WSException::PROCESS_ERROR); 241 246 } else { 242 // Authenticate the user on the requested network 243 $user = $network->getAuthenticator()->login($username, $password, $errMsg); 244 if (!$user) { 245 $this->_outputArr['auth'] = 0; 246 $this->_outputArr['explanation'] = $errMsg; 247 if (!$logout) { 248 // Authenticate the user on the requested network 249 $user = $network->getAuthenticator()->login($username, $password, $errMsg, $errNo); 250 if (!$user) { 251 $this->_outputArr['auth'] = 0; 252 $this->_outputArr['explanation'] = $errMsg; 253 $this->_outputArr['errorcode'] = $errNo; 254 } else { 255 $this->_outputArr['auth'] = 1; 256 if (!is_null($node)) { 257 $token = $user->generateConnectionTokenNoSession($node, $from, $mac); 258 259 if (!$token) throw new WSException("User authenticated but cannot generate connection token.", WSException::PROCESS_ERROR); 260 } 261 } 247 262 } else { 263 $user = User::getUserByUsernameOrEmail($username); 264 User::setCurrentUser($user); 265 $network->getAuthenticator()->logout(); 248 266 $this->_outputArr['auth'] = 1; 249 if (!is_null($node)) {250 $token = $user->generateConnectionTokenNoSession($node, $from, $mac);251 252 if (!$token) throw new WSException("User authenticated but cannot generate connection token.", WSException::PROCESS_ERROR);253 }254 267 } 255 268 } … … 298 311 $fields = $this->mapFields($objectClass, $fields); 299 312 if (empty($fields)) { 300 $fields = array_keys(self::$_allowedFields[$objectClass]);313 $fields = self::$_allowedFields[$objectClass]; 301 314 } 302 315 $allowedFields = self::$_allowedFields[$objectClass]; … … 362 375 } 363 376 377 if (!isset($objectList)) { 378 throw new WSException("Object list for '{$objectClass}' is not supported.", WSException::GENERIC_EXCEPTION); 379 } 364 380 $this->_outputArr = self::filterRet($objectList, $fields); 365 381 } … … 389 405 } 390 406 $retFields = array(); 391 foreach ($fields as $f ield) {407 foreach ($fields as $fkey => $field) { 392 408 $forbiddenfield = explode(".", $field); 393 409 if (! (count($forbiddenfield) == 2)) { 394 410 $methodName = 'get'.$field; 395 411 if (method_exists($value, $methodName)) { 396 397 $retFields[$field] = self::filterRet($value->$methodName()); 412 $retFields[is_string($fkey)?$fkey:$field] = self::filterRet($value->$methodName()); 398 413 } else { 399 $retFields[ $field] = 'unknown';414 $retFields[is_string($fkey)?$fkey:$field] = 'unknown'; 400 415 } 401 416 } else
