Documentation TYPO3 par Ameos

class.tslib_feuserauth.php

00001 <?php
00002 /***************************************************************
00003 *  Copyright notice
00004 *
00005 *  (c) 1999-2004 Kasper Skaarhoj (kasperYYYY@typo3.com)
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 ***************************************************************/
00077 class tslib_feUserAuth extends t3lib_userAuth {
00078         var $session_table = 'fe_sessions';             // Table to use for session data.
00079         var $name = 'fe_typo_user';                 // Session/Cookie name
00080         var $get_name = 'ftu';                                   // Session/GET-var name
00081 
00082         var $user_table = 'fe_users';                                   // Table in database with userdata
00083         var $username_column = 'username';                              // Column for login-name
00084         var $userident_column = 'password';                     // Column for password
00085         var $userid_column = 'uid';                                     // Column for user-id
00086         var $lastLogin_column = 'lastlogin';
00087 
00088         var $enablecolumns = Array (
00089                 'deleted' => 'deleted',
00090                 'disabled' => 'disable',
00091                 'starttime' => 'starttime',
00092                 'endtime' => 'endtime'
00093         );
00094         var $formfield_uname = 'user';                          // formfield with login-name
00095         var $formfield_uident = 'pass';                         // formfield with password
00096         var $formfield_chalvalue = 'challenge';         // formfield with a unique value which is used to encrypt the password and username
00097         var $formfield_status = 'logintype';            // formfield with status: *'login', 'logout'
00098         var $security_level = '';                                       // sets the level of security. *'normal' = clear-text. 'challenged' = hashed password/username from form in $formfield_uident. 'superchallenged' = hashed password hashed again with username.
00099 
00100         var $auth_include = '';                                         // this is the name of the include-file containing the login form. If not set, login CAN be anonymous. If set login IS needed.
00101 
00102         var $auth_timeout_field = 6000;                         // if > 0 : session-timeout in seconds. if false/<0 : no timeout. if string: The string is fieldname from the usertable where the timeout can be found.
00103 
00104         var $lifetime = 0;                              // 0 = Session-cookies. If session-cookies, the browser will stop session when the browser is closed. Else it keeps the session for $lifetime seconds.
00105         var $sendNoCacheHeaders = 0;
00106         var $getFallBack = 1;                                           // If this is set, authentication is also accepted by the _GET. Notice that the identification is NOT 128bit MD5 hash but reduced. This is done in order to minimize the size for mobile-devices, such as WAP-phones
00107         var $hash_length = 10;
00108         var $getMethodEnabled = 1;                                      // Login may be supplied by url.
00109 
00110         var $usergroup_column = 'usergroup';
00111         var $usergroup_table = 'fe_groups';
00112         var $groupData = Array(
00113                 'title' =>Array(),
00114                 'uid' =>Array(),
00115                 'pid' =>Array()
00116         );
00117         var $TSdataArray=array();               // Used to accumulate the TSconfig data of the user
00118         var $userTS = array();
00119         var $userTSUpdated=0;
00120         var $showHiddenRecords=0;
00121 
00122                 // Session and user data:
00123                 /*
00124                         There are two types of data that can be stored: UserData and Session-Data. Userdata is for the login-user, and session-data for anyone viewing the pages.
00125                         'Keys' are keys in the internal dataarray of the data. When you get or set a key in one of the data-spaces (user or session) you decide the type of the variable (not object though)
00126                         'Reserved' keys are:
00127                                 - 'recs': Array: Used to 'register' records, eg in a shopping basket. Structure: [recs][tablename][record_uid]=number
00128                                 - sys: Reserved for TypoScript standard code.
00129                 */
00130         var $sesData = Array();
00131         var $sesData_change = 0;
00132         var $userData_change = 0;
00133 
00134 
00141         function fetchGroupData()       {
00142                 $this->TSdataArray = array();
00143                 $this->userTS = array();
00144                 $this->userTSUpdated = 0;
00145 
00146                         // Setting default configuration:
00147                 $this->TSdataArray[]=$GLOBALS['TYPO3_CONF_VARS']['FE']['defaultUserTSconfig'];
00148 
00149                 if (is_array($this->user) && $this->user['usergroup'])  {
00150                         $groups = t3lib_div::intExplode(',',$this->user['usergroup']);
00151                         $list = implode(',',$groups);
00152                         $lockToDomain_SQL = ' AND (lockToDomain="" OR lockToDomain="'.t3lib_div::getIndpEnv('HTTP_HOST').'")';
00153                         if (!$this->showHiddenRecords)  $hiddenP = 'AND NOT hidden ';
00154 
00155                         $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', $this->usergroup_table, 'NOT deleted '.$hiddenP.'AND uid IN ('.$list.')'.$lockToDomain_SQL);
00156                         while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res))      {
00157                                 $this->groupData['title'][$row['uid']] = $row['title'];
00158                                 $this->groupData['uid'][$row['uid']] = $row['uid'];
00159                                 $this->groupData['pid'][$row['uid']] = $row['pid'];
00160                                 $this->groupData['TSconfig'][$row['uid']] = $row['TSconfig'];
00161                         }
00162 
00163                         if ($GLOBALS['TYPO3_DB']->sql_num_rows($res))   {
00164                                 $GLOBALS['TYPO3_DB']->sql_free_result($res);
00165                                 // TSconfig:
00166                                 reset($groups);
00167                                 while(list(,$TSuid)=each($groups))      {
00168                                         $this->TSdataArray[]=$this->groupData['TSconfig'][$TSuid];
00169                                 }
00170                                 $this->TSdataArray[]=$this->user['TSconfig'];
00171 
00172                                 // Sort information
00173                                 ksort($this->groupData['title']);
00174                                 ksort($this->groupData['uid']);
00175                                 ksort($this->groupData['pid']);
00176                                 return count($this->groupData['uid']);
00177                         } else {
00178                                 return 0;
00179                         }
00180                 }
00181         }
00182 
00189         function getUserTSconf()        {
00190                 if (!$this->userTSUpdated) {
00191                                 // Parsing the user TS (or getting from cache)
00192                         $this->TSdataArray = t3lib_TSparser::checkIncludeLines_array($this->TSdataArray);
00193                         $userTS = implode(chr(10).'[GLOBAL]'.chr(10),$this->TSdataArray);
00194                         $parseObj = t3lib_div::makeInstance('t3lib_TSparser');
00195                         $parseObj->parse($userTS);
00196                         $this->userTS = $parseObj->setup;
00197 
00198                         $this->userTSUpdated=1;
00199                 }
00200                 return $this->userTS;
00201         }
00202 
00203 
00204 
00205 
00206 
00207 
00208 
00209 
00210 
00211 
00212 
00213 
00214 
00215 
00216 
00217 
00218 
00219         /*****************************************
00220          *
00221          * Session data management functions
00222          *
00223          ****************************************/
00224 
00234         function fetchSessionData()     {
00235                 // Gets SesData if any
00236                 if ($this->id)  {
00237                         $dbres = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', 'fe_session_data', 'hash="'.$GLOBALS['TYPO3_DB']->quoteStr($this->id, 'fe_session_data').'"');
00238                         if ($sesDataRow = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($dbres))        {
00239                                 $this->sesData = unserialize($sesDataRow['content']);
00240                         }
00241                 }
00242                         // delete old data:
00243                 if ((rand()%100) <= 1) {                // a possibility of 1 % for garbage collection.
00244                         $GLOBALS['TYPO3_DB']->exec_DELETEquery('fe_session_data', 'tstamp < '.intval(time()-3600*24));          // all data older than 24 hours are deleted.
00245                 }
00246         }
00247 
00256         function storeSessionData()     {
00257                         // Saves UC and SesData if changed.
00258                 if ($this->userData_change)     {
00259                         $this->writeUC('');
00260                 }
00261                 if ($this->sesData_change)      {
00262                         if ($this->id)  {
00263                                 $insertFields = array (
00264                                         'hash' => $this->id,
00265                                         'content' => serialize($this->sesData),
00266                                         'tstamp' => time()
00267                                 );
00268                                 $GLOBALS['TYPO3_DB']->exec_DELETEquery('fe_session_data', 'hash="'.$GLOBALS['TYPO3_DB']->quoteStr($this->id, 'fe_session_data').'"');
00269                                 $GLOBALS['TYPO3_DB']->exec_INSERTquery('fe_session_data', $insertFields);
00270                         }
00271                 }
00272         }
00273 
00282         function getKey($type,$key) {
00283                 if ($key)       {
00284                         switch($type)   {
00285                                 case 'user':
00286                                         return $this->uc[$key];
00287                                 break;
00288                                 case 'ses':
00289                                         return $this->sesData[$key];
00290                                 break;
00291                         }
00292                 }
00293         }
00294 
00307         function setKey($type,$key,$data)       {
00308                 if ($key)       {
00309                         switch($type)   {
00310                                 case 'user':
00311                                         if ($this->user['uid']) {
00312                                                 $this->uc[$key]=$data;
00313                                                 $this->userData_change=1;
00314                                         }
00315                                 break;
00316                                 case 'ses':
00317                                         $this->sesData[$key]=$data;
00318                                         $this->sesData_change=1;
00319                                 break;
00320                         }
00321                 }
00322         }
00323 
00332         function record_registration($recs)     {
00333                 if ($recs['clear_all']) {
00334                         $this->setKey('ses','recs','');
00335                 }
00336                 $change=0;
00337                 $recs_array=$this->getKey('ses','recs');
00338                 reset($recs);
00339                 while(list($table,$data)=each($recs))   {
00340                         if (is_array($data))    {
00341                                 reset($data);
00342                                 while(list($rec_id,$value)=each($data)) {
00343                                         if ($value != $recs_array[$table][$rec_id])     {
00344                                                 $recs_array[$table][$rec_id] = $value;
00345                                                 $change=1;
00346                                         }
00347                                 }
00348                         }
00349                 }
00350                 if ($change)    {
00351                         $this->setKey('ses','recs',$recs_array);
00352                 }
00353         }
00354 }
00355 
00356 
00357 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['tslib/class.tslib_feuserauth.php'])        {
00358         include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['tslib/class.tslib_feuserauth.php']);
00359 }
00360 ?>


Généré par Les experts TYPO3 avec  doxygen 1.4.6