Ignore:
Timestamp:
Dec 26, 2013, 7:37:44 PM (11 years ago)
Author:
chronos
Message:
  • Přidáno: Volba pro trvalé přihlášení uživatele.
  • Opraveno: Ošetření chyb v SQL dotazech při povýšení verze databáze.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Modules/User/User.php

    r605 r619  
    4242  function GetSalt()
    4343  {
    44     mt_srand(microtime(true)*100000 + memory_get_usage(true));
     44    mt_srand(microtime(true) * 100000 + memory_get_usage(true));
    4545    return sha1(uniqid(mt_rand(), true));
    4646  }
     
    5353  var $Roles = array();
    5454  var $User = array();
    55   var $OnlineStateTimeout = 600; // in seconds
     55  var $OnlineStateTimeout;
    5656  var $PermissionCache = array();
    5757  var $PermissionGroupCache = array();
     
    6363  {
    6464    parent::__construct($System);
     65    $this->OnlineStateTimeout = 600; // in seconds
    6566    $this->PasswordHash = new PasswordHash();
    6667  }
     
    8182
    8283    // Check login
    83     $Query = $this->Database->select('UserOnline', '*', 'SessionId="'.$SID.'"');
     84    $Query = $this->Database->select('UserOnline', '*', '`SessionId`="'.$SID.'"');
    8485    $Row = $Query->fetch_assoc();
    8586    if($Row['User'] != '')
    8687    {
    87       $Query = $this->Database->query('SELECT User.*, UserCustomerRel.Customer AS Member FROM User LEFT JOIN UserCustomerRel ON UserCustomerRel.User=User.Id WHERE User.Id='.$Row['User']);     
     88      $Query = $this->Database->query('SELECT `User`.*, `UserCustomerRel`.`Customer` AS `Member` FROM `User` '.
     89        ' LEFT JOIN `UserCustomerRel` ON `UserCustomerRel`.`User`=`User`.`Id` WHERE `User`.`Id`='.$Row['User']);     
    8890      $this->User = $Query->fetch_assoc();
    8991      $Result = USER_LOGGED;
     
    9698
    9799    // Remove nonactive users
    98     $DbResult = $this->Database->select('UserOnline', 'Id, User', 'ActivityTime < DATE_SUB(NOW(), INTERVAL '.$this->OnlineStateTimeout.' SECOND)');
     100    $DbResult = $this->Database->select('UserOnline', '`Id`, `User`', '(`ActivityTime` < DATE_SUB(NOW(), INTERVAL '.$this->OnlineStateTimeout.' SECOND)) AND (`StayLogged` = 0)');
    99101    while($DbRow = $DbResult->fetch_array())
    100102    {
     
    181183  }
    182184
    183   function Login($Login, $Password)
     185  function Login($Login, $Password, $StayLogged = false)
    184186  {
    185187    $SID = session_id();
     
    194196      {
    195197        $this->Database->update('User', 'Id='.$Row['Id'], array('LastLoginTime' => 'NOW()', 'LastIpAddress' => GetRemoteAddress()));           
    196         $this->Database->update('UserOnline', 'SessionId="'.$SID.'"', array('User' => $Row['Id']));
     198        $this->Database->update('UserOnline', 'SessionId="'.$SID.'"', array('User' => $Row['Id'], 'StayLogged' => $StayLogged));
    197199       
    198200        $Result = USER_LOGGED_IN;
Note: See TracChangeset for help on using the changeset viewer.