writeDevLog = TRUE; return parent::init(); } /** * Mandatory function. Normally getUser should only fetch the userdata, but due to the fact that * our webservice already authenticates the user before he is even able to get his data, * this step could be skipped by always setting it to true. This is possible because TYPO3 * will not call this method when getUser failed. * * @param object * @return boolean or 100 or 200 */ function authUser($user) { return true; } /** * Mandatory function * * @return array with userdata or false */ function getUser() { $user = false; if ($this->login['status']=='login' AND $this->login['uident']) { $user = $this->getUserFromWebservice($this->login['uname'], $this->login['uident']); //write userdata to internal db $resCount = $GLOBALS['TYPO3_DB']->exec_SELECTquery('uid', 'fe_users', 'uid = '.$user['uid']); //leave out password and other critical data! $userForDb = array( 'uid' => $user['uid'], 'username' => $user['username'] ); if($GLOBALS['TYPO3_DB']->sql_num_rows($resCount) == 1) { //update $res = $GLOBALS['TYPO3_DB']->exec_UPDATEquery('fe_users', 'uid = '.$userForDb['uid'], $userForDb); } else { //insert $res = $GLOBALS['TYPO3_DB']->exec_INSERTquery('fe_users', $userForDb); } //if internal db operation failed, login also does if(!$res) { return false; } } return $user; } /** * Requests user object from webservice. * * @param string $username * @param string $password * @return array with userdata or false if not valid */ function getUserFromWebservice($username, $password) { try { //connect $soapclient = new SoapClient($this->WsdlPath, array('trace' => 1)); //construct data $data = new sdtClass(); $data->username = utf8_encode($username); $data->password = utf8_encode($password); //login! $response = $soapclient->loginUser($data); } catch(SoapFault $e) { trigger_error("SOAP Fault: (faultcode: {$e->faultcode}, faultstring: {$e->faultstring})", E_USER_ERROR); } //handle response return $this->handleWebserviceResponse($response); } /** * Handles the service response, deals errors and returns the user array if everything was fine. * * @param object $responseObject * @return array or false if no user was found */ function handleWebserviceResponse($responseObject) { if($responseObject->success) { //TODO: utf8_decode all members before returning return $responseObject->user; } else { //TODO: some error handling... return false; } } /** * Mandatory function. Should return an array of possible usergroups. * * @return unknown */ function getGroups() { $group = array( 'uid' => array(1), 'title' => array('nogroup'), 'pid' => array(0) ); return $group; } } ?>