[TASK] CGL FunctionCallArgumentSpacingTooMuchSpaceAfterComma
[Packages/TYPO3.CMS.git] / typo3 / sysext / sv / class.tx_sv_authbase.php
index 4517c6e..9cd0b98 100644 (file)
@@ -2,7 +2,7 @@
 /***************************************************************
 *  Copyright notice
 *
-*  (c) 1999-2005 Kasper Skaarhoj (kasperYYYY@typo3.com)
+*  (c) 2004-2011 René Fritz <r.fritz@colorcube.de>
 *  All rights reserved
 *
 *  This script is part of the TYPO3 project. The TYPO3 project is
 /**
  * Service base class for 'User authentication'.
  *
- * @author     René Fritz <r.fritz@colorcube.de>
+ * @author     René Fritz <r.fritz@colorcube.de>
  */
 
-require_once(PATH_t3lib.'class.t3lib_svbase.php');
+require_once(PATH_t3lib . 'class.t3lib_svbase.php');
 
-class tx_sv_authbase extends t3lib_svbase      {
 
-       var $pObj;                                              // Parent object
+/**
+ * Authentication services class
+ *
+ * @author     René Fritz <r.fritz@colorcube.de>
+ * @package TYPO3
+ * @subpackage tx_sv
+ */
+class tx_sv_authbase extends t3lib_svbase {
 
-       var $mode;                                              // Subtype of the service which is used to call the service.
+       /**
+        * User object
+        *
+        * @var t3lib_userAuth
+        */
+       var $pObj;
+
+       var $mode;                      // Subtype of the service which is used to call the service.
 
-       var $login=array();                             // Submitted login form data
-       var $info=array();                              // Various data
+       var $login = array();           // Submitted login form data
+       var $authInfo = array();        // Various data
 
-       var $db_user=array();                   // User db table definition
-       var $db_groups=array();                 // Usergroups db table definition
+       var $db_user = array();         // User db table definition
+       var $db_groups = array();       // Usergroups db table definition
+
+       var $writeAttemptLog = FALSE;   // If the writelog() functions is called if a login-attempt has be tried without success
+       var $writeDevLog = FALSE;       // If the t3lib_div::devLog() function should be used
 
-       var $writeAttemptLog = 0;               // If the writelog() functions is called if a login-attempt has be tried without success
 
        /**
-        * init service
+        * Initialize authentication service
         *
-        * @param       string          Subtype of the service which is used to call the service.
-        * @param       array           Submitted login form data
-        * @param       array           Information array. Holds submitted form data etc.
-        * @param       object          Parent object
+        * @param       string          Subtype of the service which is used to call the service.
+        * @param       array           Submitted login form data
+        * @param       array           Information array. Holds submitted form data etc.
+        * @param       object          Parent object
         * @return      void
         */
-       function initAuth($mode, $loginData, $info, &$pObj)     {
+       function initAuth($mode, $loginData, $authInfo, $pObj) {
 
-               $this->pObj = &$pObj;
+               $this->pObj = $pObj;
 
-               $this->mode = $mode;
+               $this->mode = $mode;    // sub type
                $this->login = $loginData;
-               $this->info = $info;
+               $this->authInfo = $authInfo;
 
-               $this->db_user = $this->getServiceOption('db_user', $info['db_user'], FALSE);
-               $this->db_groups = $this->getServiceOption('db_groups', $info['db_groups'], FALSE);
+               $this->db_user = $this->getServiceOption('db_user', $authInfo['db_user'], FALSE);
+               $this->db_groups = $this->getServiceOption('db_groups', $authInfo['db_groups'], FALSE);
 
                $this->writeAttemptLog = $this->pObj->writeAttemptLog;
                $this->writeDevLog       = $this->pObj->writeDevLog;
        }
 
        /**
+        * Check the login data with the user record data for builtin login methods
+        *
+        * @param array $user user data array
+        * @param array $loginData login data array
+        * @param string $passwordCompareStrategy password compare strategy
+        * @return boolean TRUE if login data matched
+        */
+       function compareUident(array $user, array $loginData, $passwordCompareStrategy = '') {
+               if ($this->authInfo['loginType'] === 'BE') {
+                               // Challenge is only stored in session during BE login with the superchallenged login type.
+                               // In the frontend context the challenge is never stored in the session.
+                       if ($passwordCompareStrategy !== 'superchallenged') {
+                               $this->pObj->challengeStoredInCookie = FALSE;
+                       }
+                               // The TYPO3 standard login service relies on $passwordCompareStrategy being set
+                               // to 'superchallenged' because of the password in the database is stored as md5 hash
+                       $passwordCompareStrategy = 'superchallenged';
+               }
+
+               return $this->pObj->compareUident($user, $loginData, $passwordCompareStrategy);
+       }
+
+       /**
         * Writes to log database table in pObj
         *
         * @param       integer         $type: denotes which module that has submitted the entry. This is the current list:  1=tce_db; 2=tce_file; 3=system (eg. sys_history save); 4=modules; 254=Personal settings changed; 255=login / out action: 1=login, 2=logout, 3=failed login (+ errorcode 3), 4=failure_warning_email sent
@@ -85,13 +123,42 @@ class tx_sv_authbase extends t3lib_svbase  {
         * @return      void
         * @see t3lib_userauthgroup::writelog()
         */
-       function writelog($type,$action,$error,$details_nr,$details,$data,$tablename='',$recuid='',$recpid='')  {
-               if($this->pObj->writeAttemptLog) {
-                       $this->pObj->writelog($type,$action,$error,$details_nr,$details,$data,$tablename,$recuid,$recpid);
+       function writelog($type, $action, $error, $details_nr, $details, $data, $tablename='', $recuid='', $recpid='') {
+               if($this->writeAttemptLog) {
+                       $this->pObj->writelog($type, $action, $error, $details_nr, $details, $data, $tablename, $recuid, $recpid);
                }
        }
 
-}
 
 
+
+
+
+
+
+
+
+       /*************************
+        *
+        * create/update user - EXPERIMENTAL
+        *
+        *************************/
+
+       /**
+        * Get a user from DB by username
+        *
+        * @param       string          user name
+        * @param       string          additional WHERE clause: " AND ...
+        * @param       array           User db table definition: $this->db_user
+        * @return      mixed           user array or FALSE
+        */
+       function fetchUserRecord($username, $extraWhere='', $dbUserSetup='') {
+
+               $dbUser = is_array($dbUserSetup) ? $dbUserSetup : $this->db_user;
+               $user = $this->pObj->fetchUserRecord($dbUser, $username, $extraWhere);
+
+               return $user;
+       }
+}
+
 ?>
\ No newline at end of file