TYPO3 API  SVNRelease
class.tx_sv_authbase.php
Go to the documentation of this file.
00001 <?php
00002 /***************************************************************
00003 *  Copyright notice
00004 *
00005 *  (c) 2004-2011 René Fritz <r.fritz@colorcube.de>
00006 *  All rights reserved
00007 *
00008 *  This script is part of the TYPO3 project. The TYPO3 project is
00009 *  free software; you can redistribute it and/or modify
00010 *  it under the terms of the GNU General Public License as published by
00011 *  the Free Software Foundation; either version 2 of the License, or
00012 *  (at your option) any later version.
00013 *
00014 *  The GNU General Public License can be found at
00015 *  http://www.gnu.org/copyleft/gpl.html.
00016 *  A copy is found in the textfile GPL.txt and important notices to the license
00017 *  from the author is found in LICENSE.txt distributed with these scripts.
00018 *
00019 *
00020 *  This script is distributed in the hope that it will be useful,
00021 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00022 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00023 *  GNU General Public License for more details.
00024 *
00025 *  This copyright notice MUST APPEAR in all copies of the script!
00026 ***************************************************************/
00027 /**
00028  * Service base class for 'User authentication'.
00029  *
00030  * @author  René Fritz <r.fritz@colorcube.de>
00031  */
00032 /**
00033  * [CLASS/FUNCTION INDEX of SCRIPT]
00034  *
00035  *
00036  *
00037  *   62: class tx_sv_authbase extends t3lib_svbase
00038  *   87:     function initAuth($mode, $loginData, $authInfo, &$pObj)
00039  *  110:     function compareUident($user, $loginData, $security_level='')
00040  *  129:     function writelog($type,$action,$error,$details_nr,$details,$data,$tablename='',$recuid='',$recpid='')
00041  *
00042  *              SECTION: create/update user - EXPERIMENTAL
00043  *  158:     function fetchUserRecord($username, $extraWhere='', $dbUserSetup='')
00044  *
00045  * TOTAL FUNCTIONS: 4
00046  * (This index is automatically created/updated by the extension "extdeveval")
00047  *
00048  */
00049 
00050 require_once(PATH_t3lib . 'class.t3lib_svbase.php');
00051 
00052 
00053 /**
00054  * Authentication services class
00055  *
00056  * @author  René Fritz <r.fritz@colorcube.de>
00057  * @package TYPO3
00058  * @subpackage tx_sv
00059  */
00060 class tx_sv_authbase extends t3lib_svbase   {
00061 
00062     var $pObj;          // Parent object
00063 
00064     var $mode;          // Subtype of the service which is used to call the service.
00065 
00066     var $login = array();       // Submitted login form data
00067     var $authInfo = array();    // Various data
00068 
00069     var $db_user = array();     // User db table definition
00070     var $db_groups = array();   // Usergroups db table definition
00071 
00072     var $writeAttemptLog = false;   // If the writelog() functions is called if a login-attempt has be tried without success
00073     var $writeDevLog = false;   // If the t3lib_div::devLog() function should be used
00074 
00075 
00076     /**
00077      * Initialize authentication service
00078      *
00079      * @param   string      Subtype of the service which is used to call the service.
00080      * @param   array       Submitted login form data
00081      * @param   array       Information array. Holds submitted form data etc.
00082      * @param   object      Parent object
00083      * @return  void
00084      */
00085     function initAuth($mode, $loginData, $authInfo, $pObj) {
00086 
00087         $this->pObj = $pObj;
00088 
00089         $this->mode = $mode;    // sub type
00090         $this->login = $loginData;
00091         $this->authInfo = $authInfo;
00092 
00093         $this->db_user = $this->getServiceOption('db_user', $authInfo['db_user'], FALSE);
00094         $this->db_groups = $this->getServiceOption('db_groups', $authInfo['db_groups'], FALSE);
00095 
00096         $this->writeAttemptLog = $this->pObj->writeAttemptLog;
00097         $this->writeDevLog   = $this->pObj->writeDevLog;
00098     }
00099 
00100     /**
00101      * Check the login data with the user record data for builtin login methods
00102      *
00103      * @param   array       user data array
00104      * @param   array       login data array
00105      * @param   string      security_level
00106      * @return  boolean     true if login data matched
00107      */
00108     function compareUident($user, $loginData, $security_level='') {
00109         return $this->pObj->compareUident($user, $loginData, $security_level);
00110     }
00111 
00112     /**
00113      * Writes to log database table in pObj
00114      *
00115      * @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
00116      * @param   integer     $action: denotes which specific operation that wrote the entry (eg. 'delete', 'upload', 'update' and so on...). Specific for each $type. Also used to trigger update of the interface. (see the log-module for the meaning of each number !!)
00117      * @param   integer     $error: flag. 0 = message, 1 = error (user problem), 2 = System Error (which should not happen), 3 = security notice (admin)
00118      * @param   integer     $details_nr: The message number. Specific for each $type and $action. in the future this will make it possible to translate errormessages to other languages
00119      * @param   string      $details: Default text that follows the message
00120      * @param   array       $data: Data that follows the log. Might be used to carry special information. If an array the first 5 entries (0-4) will be sprintf'ed the details-text...
00121      * @param   string      $tablename: Special field used by tce_main.php. These ($tablename, $recuid, $recpid) holds the reference to the record which the log-entry is about. (Was used in attic status.php to update the interface.)
00122      * @param   integer     $recuid: Special field used by tce_main.php. These ($tablename, $recuid, $recpid) holds the reference to the record which the log-entry is about. (Was used in attic status.php to update the interface.)
00123      * @param   integer     $recpid: Special field used by tce_main.php. These ($tablename, $recuid, $recpid) holds the reference to the record which the log-entry is about. (Was used in attic status.php to update the interface.)
00124      * @return  void
00125      * @see t3lib_userauthgroup::writelog()
00126      */
00127     function writelog($type,$action,$error,$details_nr,$details,$data,$tablename='',$recuid='',$recpid='')  {
00128         if($this->writeAttemptLog) {
00129             $this->pObj->writelog($type,$action,$error,$details_nr,$details,$data,$tablename,$recuid,$recpid);
00130         }
00131     }
00132 
00133 
00134 
00135 
00136 
00137 
00138 
00139 
00140 
00141 
00142     /*************************
00143      *
00144      * create/update user - EXPERIMENTAL
00145      *
00146      *************************/
00147 
00148     /**
00149      * Get a user from DB by username
00150      *
00151      * @param   string      user name
00152      * @param   string      additional WHERE clause: " AND ...
00153      * @param   array       User db table definition: $this->db_user
00154      * @return  mixed       user array or false
00155      */
00156     function fetchUserRecord($username, $extraWhere='', $dbUserSetup='')    {
00157 
00158         $dbUser = is_array($dbUserSetup) ? $dbUserSetup : $this->db_user;
00159         $user = $this->pObj->fetchUserRecord($dbUser, $username, $extraWhere);
00160 
00161         return $user;
00162     }
00163 }
00164 
00165 ?>