Ignore:
Timestamp:
Feb 22, 2015, 11:20:50 PM (9 years ago)
Author:
chronos
Message:
  • Modified: Tabs converted to spaces.
  • Modified: Remove spaces from end of lines.
  • Added: Code format script.
File:
1 edited

Legend:

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

    r805 r816  
    88class ModuleUser extends AppModule
    99{
    10         function __construct($System)
    11         {
    12                 parent::__construct($System);
    13                 $this->Name = 'User';
    14                 $this->Version = '1.1';
    15                 $this->Creator = 'Chronos';
    16                 $this->License = 'GNU/GPL';
    17                 $this->Description = 'User and permission management';
    18                 $this->Dependencies = array();
    19         }
    20 
    21         function Start()
    22         {
    23                 $this->System->User = new User($this->System);
     10  function __construct($System)
     11  {
     12    parent::__construct($System);
     13    $this->Name = 'User';
     14    $this->Version = '1.1';
     15    $this->Creator = 'Chronos';
     16    $this->License = 'GNU/GPL';
     17    $this->Description = 'User and permission management';
     18    $this->Dependencies = array();
     19  }
     20
     21  function Start()
     22  {
     23    $this->System->User = new User($this->System);
    2424    $this->System->RegisterPage('userlist.php', 'PageUserList');
    25                 $this->System->RegisterPage('Options.php', 'PageUserOptions');
    26                 $this->System->RegisterPage('registrace.php', 'PageUserRegistration');
    27                 $this->System->RegisterPage('user.php', 'PageUserProfile');
    28                 $this->System->RegisterPage('login', 'PageUserLogin');
    29                 $this->System->RegisterMenuItem(array(
    30         'Title' => T('Translators'),
    31         'Hint' => 'Seznam registrovaných uživatelů',
    32         'Link' => $this->System->Link('/userlist.php'),
    33         'Permission' => LICENCE_ANONYMOUS,
    34         'Icon' => '',
     25    $this->System->RegisterPage('Options.php', 'PageUserOptions');
     26    $this->System->RegisterPage('registrace.php', 'PageUserRegistration');
     27    $this->System->RegisterPage('user.php', 'PageUserProfile');
     28    $this->System->RegisterPage('login', 'PageUserLogin');
     29    $this->System->RegisterMenuItem(array(
     30      'Title' => T('Translators'),
     31      'Hint' => 'Seznam registrovaných uživatelů',
     32      'Link' => $this->System->Link('/userlist.php'),
     33      'Permission' => LICENCE_ANONYMOUS,
     34      'Icon' => '',
    3535    ), 0);
    3636    if(array_key_exists('Search', $this->System->ModuleManager->Modules))
    3737      $this->System->ModuleManager->Modules['Search']->RegisterSearch('user',
    3838      T('Translators'), array('Name'), '`User`', $this->System->Link('/userlist.php?search='));
    39         }
    40 
    41         function ShowOnlineList()
    42         {
    43                 $Output = T('Online translators').':<br />';
    44                 $DbResult = $this->System->Database->query('SELECT * FROM ('.
     39  }
     40
     41  function ShowOnlineList()
     42  {
     43    $Output = T('Online translators').':<br />';
     44    $DbResult = $this->System->Database->query('SELECT * FROM ('.
    4545'SELECT `User`.`Name`, `User`.`ID` FROM `UserOnline` '.
    46                                 'JOIN `User` ON `User`.`ID` = `UserOnline`.`User` '.
    47                                 'WHERE (`ActivityTime` >= NOW() - 300) '.
    48                                 'ORDER BY `ActivityTime` DESC ) AS `T` GROUP BY `Name`');
    49                 while($DbUser = $DbResult->fetch_assoc())
    50                 {
    51                         $Name = '<a href="'.$this->System->Link('/user.php?user='.$DbUser['ID']).'">'.$DbUser['Name'].'</a>';
    52                         $Output .= $Name.'<br />';
    53                 }
    54                 return($Output);
    55         }
     46        'JOIN `User` ON `User`.`ID` = `UserOnline`.`User` '.
     47        'WHERE (`ActivityTime` >= NOW() - 300) '.
     48        'ORDER BY `ActivityTime` DESC ) AS `T` GROUP BY `Name`');
     49    while($DbUser = $DbResult->fetch_assoc())
     50    {
     51      $Name = '<a href="'.$this->System->Link('/user.php?user='.$DbUser['ID']).'">'.$DbUser['Name'].'</a>';
     52      $Output .= $Name.'<br />';
     53    }
     54    return($Output);
     55  }
    5656}
    5757
    5858class PageUserLogin extends Page
    5959{
    60         function Show()
    61         {
    62                 $Output = '<form action="'.$this->System->Link('/?action=login').'" method="post">'.
    63                         '<fieldset><legend>'.T('Login').'</legend>
    64                         <table>
    65                         <tr>
    66                         <td>'.T('Name').':</td><td><input type="text" name="LoginUser" size="13" /></td>
    67                         </tr>
    68                         <tr>
    69                         <td>'.T('Password').':</td><td><input type="password" name="LoginPass" size="13" /></td>
    70                         </tr>
    71                         <tr>
    72                         <td>'.T('Stay logged').':</td><td><input type="checkbox" name="StayLogged" /></td>
    73                         </tr>
    74                         <tr>
    75                         <th><input type="submit" value="'.T('Do login').'" /></th>
    76                         </tr>
    77                         </table>
    78                         </fieldset></form>';
    79                         return($Output);
    80         }
     60  function Show()
     61  {
     62    $Output = '<form action="'.$this->System->Link('/?action=login').'" method="post">'.
     63      '<fieldset><legend>'.T('Login').'</legend>
     64      <table>
     65      <tr>
     66      <td>'.T('Name').':</td><td><input type="text" name="LoginUser" size="13" /></td>
     67      </tr>
     68      <tr>
     69      <td>'.T('Password').':</td><td><input type="password" name="LoginPass" size="13" /></td>
     70      </tr>
     71      <tr>
     72      <td>'.T('Stay logged').':</td><td><input type="checkbox" name="StayLogged" /></td>
     73      </tr>
     74      <tr>
     75      <th><input type="submit" value="'.T('Do login').'" /></th>
     76      </tr>
     77      </table>
     78      </fieldset></form>';
     79      return($Output);
     80  }
    8181}
    8282
     
    114114  function Login($Name, $Password, $StayLogged = false)
    115115  {
    116         $SID = session_id();
     116    $SID = session_id();
    117117    $DbResult = $this->Database->query('SELECT `ID` FROM `User` WHERE '.
    118118      'LOWER(`Name`) = LOWER("'.$Name.'") AND `Pass` = '.$this->CryptPasswordSQL('"'.$Password.'"', '`Salt`'));
     
    147147  function Logout()
    148148  {
    149         $SID = session_id();
     149    $SID = session_id();
    150150    if($this->Role != LICENCE_ANONYMOUS)
    151151    {
     
    162162    $DbResult = $this->Database->query('SELECT `User`.`PreferredVersion`,`User`.`ID`,`User`.`Team`,`User`.`Redirecting`,`User`.`Email`,`User`.`Info`,'.
    163163    '`User`.`Language`,`User`.`Name`,`User`.`GM`,`ClientVersion`.`Version` AS `PreferredVersionGame` FROM `User` '.
    164                 'LEFT JOIN `ClientVersion` ON `ClientVersion`.`Id` = `User`.`PreferredVersion` '.
     164    'LEFT JOIN `ClientVersion` ON `ClientVersion`.`Id` = `User`.`PreferredVersion` '.
    165165    'WHERE `User`.`ID` = '.$this->Id);
    166166    if($DbResult->num_rows > 0)
     
    230230      $this->Database->update('UserOnline', 'SessionId="'.$SID.'"', array('ActivityTime' => 'NOW()'));
    231231    } else {
    232         if(GetRemoteAddress() != '') $HostName = gethostbyaddr(GetRemoteAddress());
    233           else $HostName = '';
    234         $this->Database->insert('UserOnline', array('SessionId' => $SID,
     232      if(GetRemoteAddress() != '') $HostName = gethostbyaddr(GetRemoteAddress());
     233        else $HostName = '';
     234      $this->Database->insert('UserOnline', array('SessionId' => $SID,
    235235      'User' => null, 'LoginTime' => 'NOW()', 'ActivityTime' => 'NOW()',
    236236      'IpAddress' => GetRemoteAddress(), 'HostName' => $HostName,
    237237      'ScriptName' => GetRequestURI()));
    238238    }
    239        
     239
    240240    // Logged permanently?
    241           if(array_key_exists('LoginHash', $_COOKIE))
    242           {
    243             $DbResult = $this->Database->query('SELECT * FROM `UserOnline` WHERE `User`='.$_COOKIE['LoginUserId'].
    244               ' AND `StayLogged`=1 AND SessionId!="'.$SID.'"');
    245             if($DbResult->num_rows > 0)
    246             {
    247               $DbRow = $DbResult->fetch_assoc();
    248               if(sha1($_COOKIE['LoginUserId'].$DbRow['StayLoggedHash']) == $_COOKIE['LoginHash'])
    249               {
    250                 $this->Database->query('DELETE FROM `UserOnline` WHERE `SessionId`="'.$SID.'"');
    251                 $this->Database->query('UPDATE `UserOnline` SET `SessionId`="'.$SID.'" WHERE `Id`='.$DbRow['Id']);
    252               }
    253             }
    254     }
    255 
    256           // Check login
     241    if(array_key_exists('LoginHash', $_COOKIE))
     242    {
     243      $DbResult = $this->Database->query('SELECT * FROM `UserOnline` WHERE `User`='.$_COOKIE['LoginUserId'].
     244        ' AND `StayLogged`=1 AND SessionId!="'.$SID.'"');
     245      if($DbResult->num_rows > 0)
     246      {
     247        $DbRow = $DbResult->fetch_assoc();
     248        if(sha1($_COOKIE['LoginUserId'].$DbRow['StayLoggedHash']) == $_COOKIE['LoginHash'])
     249        {
     250          $this->Database->query('DELETE FROM `UserOnline` WHERE `SessionId`="'.$SID.'"');
     251          $this->Database->query('UPDATE `UserOnline` SET `SessionId`="'.$SID.'" WHERE `Id`='.$DbRow['Id']);
     252        }
     253      }
     254    }
     255
     256    // Check login
    257257    $Query = $this->Database->select('UserOnline', '*', '`SessionId`="'.$SID.'"');
    258258    $Row = $Query->fetch_assoc();
    259259    if($Row['User'] != '')
    260260    {
    261         $this->Id = $Row['User'];
     261      $this->Id = $Row['User'];
    262262      $this->Load();
    263263    } else
Note: See TracChangeset for help on using the changeset viewer.