Changeset 801


Ignore:
Timestamp:
Mar 31, 2014, 9:10:41 AM (10 years ago)
Author:
chronos
Message:
  • Fixed: Better registration form values validation.
Location:
trunk
Files:
4 edited

Legend:

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

    r796 r801  
    136136        if(isset($_GET['Action']))
    137137        {
    138                 if($_GET['Action'] == 'HideWelcome') $_COOKIE['HideWelcome'] = 1;
    139                 if($_GET['Action'] == 'UnHideWelcome') $_COOKIE['HideWelcome'] = 0;
     138                if($_GET['Action'] == 'HideWelcome')
     139      {
     140        $_COOKIE['HideWelcome'] = 1;
     141        setcookie('HideWelcome', $_COOKIE['HideWelcome'], time() + 3600 * 24 * 365);
     142      }
     143                if($_GET['Action'] == 'UnHideWelcome')
     144      {
     145                        $_COOKIE['HideWelcome'] = 0;
     146        setcookie('HideWelcome', $_COOKIE['HideWelcome'], time() + 3600 * 24 * 365);
     147                }
    140148        }
    141         setcookie('HideWelcome', $_COOKIE['HideWelcome'], time() + 3600 * 24 * 365);
    142149
    143150        if(isset($_COOKIE['HideWelcome']) and ($_COOKIE['HideWelcome'] == 1))
  • trunk/Modules/User/Registration.php

    r787 r801  
    55        function ShowForm()
    66        {
    7                 global $System;
    8        
    97                if(array_key_exists('sc', $_POST)) $Human = true;
    10                 else $Human = false;
     8      else $Human = false;
    119                if(array_key_exists('user', $_POST)) $UserName = $_POST['user'];
    1210                else $UserName = '';
     
    1715                if(array_key_exists('Language', $_POST)) $Language = $_POST['Language'];
    1816                else $Language = 1;
    19        
     17
    2018                $Output = '<form action="?" method="post">
    2119                <fieldset><legend>'.T('New user registration').'</legend>
     
    6462                </tr>';
    6563                $Output .= '</td></tr>'.
    66                                 '<tr><td>Upřednostněná verze klienta: </td><td>'.ClientVersionSelection('').'</td></tr>'; 
    67                
     64                                '<tr><td>Upřednostněná verze klienta: </td><td>'.ClientVersionSelection('').'</td></tr>';
     65
    6866        $Output .= '<tr><td>';
    6967                $Query = 'SELECT * FROM UserTagType';
    7068                $DbResult = $this->Database->query($Query);
    7169    $Output .= 'Vyberte pravidla, kterými se při překladu chcete řídit:</td><td>';
    72     while ($UserTag = $DbResult->fetch_array()) { 
    73                   $checked = false; 
    74      
    75       $Output .= CheckBox('Tag'.$UserTag['ID'], $checked, 'CheckBox');   
     70    while ($UserTag = $DbResult->fetch_array()) {
     71                  $checked = false;
     72
     73      $Output .= CheckBox('Tag'.$UserTag['ID'], $checked, 'CheckBox');
    7674      $Output .= ''.$UserTag['Text'].'<br />';
    7775    }
    7876    $Output .= '</td></tr>';
    79    
     77
    8078    $Output .= '<tr>
    8179                <th><input type="submit" value="Registrovat" /></th>
     
    8482                return($Output);
    8583        }
    86        
     84
     85  function CheckRegistration()
     86  {
     87    global $Config;
     88
     89    $Output = '';
     90    $ShowForm = true;
     91
     92      if(array_key_exists('user', $_POST)) $UserName = $_POST['user'];
     93        else $UserName = '';
     94      if(array_key_exists('pass', $_POST)) $Pass = $_POST['pass'];
     95        else $Pass = '';
     96      if(array_key_exists('pass2', $_POST)) $Pass2 = $_POST['pass2'];
     97        else $Pass2 = '';
     98      if(array_key_exists('Email', $_POST)) $Email = $_POST['Email'];
     99        else $Email = '';
     100      if(array_key_exists('Team', $_POST)) $Team = $_POST['Team'] * 1;
     101        else $Team = '';
     102      if(array_key_exists('Language', $_POST)) $Language = $_POST['Language'] * 1;
     103        else $Language = '';
     104      if(array_key_exists('ClientVersion', $_POST)) $PreferredVersion = $_POST['ClientVersion'] * 1;
     105        else $PreferredVersion = '';
     106      if($PreferredVersion == '') $PreferredVersion = 'NULL';
     107      if(array_key_exists('sc', $_POST)) $SpamCheck = $_POST['sc'];
     108        else $SpamCheck = '';
     109
     110      if($SpamCheck != '')
     111      {
     112        if(($UserName != '') and ($Pass != '') and ($Pass2 != ''))
     113        {
     114          if(!in_array(strtolower($UserName), $Config['ForbiddedUserNames']))
     115          {
     116            if($Pass == $Pass2)
     117            {
     118              $DbResult = $this->Database->query('SELECT * FROM `User` WHERE LOWER(`Name`) = LOWER("'.$UserName.'")');
     119              $Line = $DbResult->fetch_row();
     120              if(!$Line)
     121              {
     122                if($Team == 0) $Team = 'NULL';
     123                $this->System->User->Register($UserName, $Pass, $Email, $Language, $Team, $PreferredVersion);
     124                $Output .= ShowMessage('Registrace proběhla úspěšně.');
     125                $Output .= 'Přečtěte si pozorně <a href="'.$this->System->Link('/info.php').'">pokyny pro překladání</a> a můžete pak hned začít překládat.';
     126                $this->System->User->Login($UserName, $Pass);
     127                $this->System->ModuleManager->Modules['Log']->WriteLog('Uživatel se zaregistroval: '.$UserName, LOG_TYPE_USER);
     128                $ShowForm = false;
     129
     130                      //tag
     131                $Query = 'SELECT * FROM UserTagType';
     132                $DbResult = $this->Database->query($Query);
     133                while ($UserTag = $DbResult->fetch_array()) {
     134                if (array_key_exists('Tag'.$UserTag['ID'], $_POST)) {
     135                  $Query = 'SELECT * FROM `UserTag` '.
     136                  'WHERE `UserTagType` = '.$UserTag['ID'].' AND `User` = '.($this->System->User->Id * 1);
     137                  $DbResult2 = $this->Database->query($Query);
     138                  if ($DbResult2->num_rows == 0) {
     139                    $Query = 'INSERT INTO `UserTag` (`ID` ,`UserTagType`,`User` ) '.
     140                    'VALUES (NULL, '.$UserTag['ID'].' , '.($this->System->User->Id * 1).')';
     141                    $DbResult2 = $this->Database->query($Query);
     142                  }
     143                } else {
     144                  $Query = 'DELETE FROM `UserTag` '.
     145                  'WHERE `UserTagType` = '.$UserTag['ID'].' AND `User` = '.($this->System->User->Id * 1);
     146                  $DbResult2 = $this->Database->query($Query);
     147                }
     148                }
     149              } else $Output = ShowMessage('Uživatel se zadanou přezdívkou již existuje.', MESSAGE_CRITICAL);
     150            } else $Output = ShowMessage('Hesla se neshodují.', MESSAGE_CRITICAL);
     151          } else $Output = ShowMessage('To jméno uživatele nemůžete použít.', MESSAGE_CRITICAL);
     152        } else $Output = ShowMessage('Nelze použít prázdné jméno nebo heslo.', MESSAGE_CRITICAL);
     153      } else $Output = ShowMessage('Nejsi člověk. Strojům není dovoleno se registrovat.', MESSAGE_CRITICAL);
     154
     155      if($ShowForm) $Output .= $this->ShowForm();
     156      return($Output);
     157  }
     158
    87159        function Show()
    88160        {
    89                 global $Config;
    90        
    91161          $this->Title = T('User registration');
    92162                $Output = '';
    93163                if(array_key_exists('user', $_POST))
    94164                {
    95                         $ShowForm = true;
    96        
    97                         $UserName = $_POST['user'];
    98                         $Pass = $_POST['pass'];
    99                         $Pass2 = $_POST['pass2'];
    100                         $Email = $_POST['Email'];
    101                         $Team = $_POST['Team'];
    102                         $Language = $_POST['Language'];
    103                         $PreferredVersion = $_POST['ClientVersion'];
    104                         if($PreferredVersion == '') $PreferredVersion = 'NULL';
    105                         if(array_key_exists('sc', $_POST)) $SpamCheck = $_POST['sc'];
    106                         else $SpamCheck = '';
    107        
    108                         if($SpamCheck != '')
    109                         {
    110                                 if(($UserName != '') and ($Pass != '') and ($Pass2 != ''))
    111                                 {
    112                                         if(!in_array(strtolower($UserName), $Config['ForbiddedUserNames']))
    113                                         {
    114                                                 if($Pass == $Pass2)
    115                                                 {
    116                                                         $DbResult = $this->Database->query('SELECT * FROM `User` WHERE LOWER(`Name`) = LOWER("'.$UserName.'")');
    117                                                         $Line = $DbResult->fetch_row();
    118                                                         if(!$Line)
    119                                                         {
    120                                                                 if($Team == 0) $Team = 'NULL';
    121                                                                 $this->System->User->Register($UserName, $Pass, $Email, $Language, $Team, $PreferredVersion);
    122                                                                 $Output .= ShowMessage('Registrace proběhla úspěšně.');
    123                                                                 $Output .= 'Přečtěte si pozorně <a href="'.$this->System->Link('/info.php').'">pokyny pro překladání</a> a můžete pak hned začít překládat.';
    124                                                                 $this->System->User->Login($UserName, $Pass);
    125                                                                 $this->System->ModuleManager->Modules['Log']->WriteLog('Uživatel se zaregistroval: '.$UserName, LOG_TYPE_USER);
    126                                                                 $ShowForm = false;
    127                
    128                                                                       //tag
    129                                                         $Query = 'SELECT * FROM UserTagType';
    130                                                         $DbResult = $this->Database->query($Query);
    131                                         while ($UserTag = $DbResult->fetch_array()) {
    132                                         if (array_key_exists('Tag'.$UserTag['ID'], $_POST)) {
    133                                                         $Query = 'SELECT * FROM `UserTag` '.
    134                                                 'WHERE `UserTagType` = '.$UserTag['ID'].' AND `User` = '.($this->System->User->Id * 1);
    135                                                         $DbResult2 = $this->Database->query($Query);
    136                                                 if ($DbResult2->num_rows == 0) {
    137                                                         $Query = 'INSERT INTO `UserTag` (`ID` ,`UserTagType`,`User` ) '.
    138                                                 'VALUES (NULL, '.$UserTag['ID'].' , '.($this->System->User->Id * 1).')';
    139                                                         $DbResult2 = $this->Database->query($Query);
    140                                                 }
    141                                         } else {
    142                                                         $Query = 'DELETE FROM `UserTag` '.
    143                                                 'WHERE `UserTagType` = '.$UserTag['ID'].' AND `User` = '.($this->System->User->Id * 1);
    144                                                         $DbResult2 = $this->Database->query($Query);
    145                                         }
    146                                         }
    147                
    148                
    149                
    150                                                         } else $Output = ShowMessage('Uživatel se zadanou přezdívkou již existuje.', MESSAGE_CRITICAL);
    151                                                 } else $Output = ShowMessage('Hesla se neshodují.', MESSAGE_CRITICAL);
    152                                         } else $Output = ShowMessage('To jméno uživatele nemůžete použít.', MESSAGE_CRITICAL);
    153                                 } else $Output = ShowMessage('Nelze použít prázdné jméno nebo heslo.', MESSAGE_CRITICAL);
    154                         } else $Output = ShowMessage('Nejsi člověk. Strojům není dovoleno se registrovat.', MESSAGE_CRITICAL);
    155        
    156                         if($ShowForm) $Output .= $this->ShowForm();
     165      $Output .= $this->CheckRegistration();
    157166                } else $Output .= $this->ShowForm();
    158167                return($Output);
    159         }       
    160 } 
     168        }
     169}
  • trunk/Modules/User/User.php

    r791 r801  
    1818                $this->Dependencies = array();
    1919        }
    20        
     20
    2121        function Start()
    2222        {
     
    3838      T('Translators'), array('Name'), '`User`', $this->System->Link('/userlist.php?search='));
    3939        }
    40        
     40
    4141        function ShowOnlineList()
    4242        {
    4343                $Output = T('Online translators').':<br />';
    44                 $DbResult = $this->System->Database->query('SELECT * FROM ('. 
     44                $DbResult = $this->System->Database->query('SELECT * FROM ('.
    4545'SELECT `User`.`Name`, `User`.`ID` FROM `UserOnline` '.
    4646                                'JOIN `User` ON `User`.`ID` = `UserOnline`.`User` '.
     
    5353                }
    5454                return($Output);
    55         }       
     55        }
    5656}
    5757
     
    6161        {
    6262                $Output = '<form action="'.$this->System->Link('/?action=login').'" method="post">'.
    63                         '<fieldset><legend>'.T('Login').'</legend>                     
     63                        '<fieldset><legend>'.T('Login').'</legend>
    6464                        <table>
    6565                        <tr>
     
    9999  var $OnlineStateTimeout;
    100100  var $PreferredVersion = 0;
    101  
     101
    102102  function __construct($System)
    103103  {
     
    105105    $this->Database = &$System->Database;
    106106    $this->OnlineStateTimeout = 600; // in seconds
    107     if(isset($_SESSION)) $this->Check();   
    108   }
    109  
     107    if(isset($_SESSION)) $this->Check();
     108  }
     109
    110110  function __destroy()
    111111  {
    112112  }
    113  
     113
    114114  function Login($Name, $Password, $StayLogged = false)
    115115  {
     
    120120    {
    121121      $User = $DbResult->fetch_assoc();
    122       $this->Id = $User['ID']; 
    123      
    124       // Prepare cookies for permanent login     
     122      $this->Id = $User['ID'];
     123
     124      // Prepare cookies for permanent login
    125125      $StayLoggedSalt = $this->GetPasswordSalt();
    126126      $this->Database->update('UserOnline', 'SessionId="'.$SID.'"', array(
    127127        'User' => $User['ID'], 'StayLogged' => $StayLogged, 'StayLoggedHash' => $StayLoggedSalt));
    128       if($StayLogged) 
     128      if($StayLogged)
    129129      {
    130130        setcookie('LoginUserId', $User['ID'], time()+365*24*60*60);
     
    133133        setcookie('LoginUserId', '', time() - 3600);
    134134        setcookie('LoginHash', '', time() - 3600);
    135       }     
    136      
     135      }
     136
    137137      $this->Database->query('UPDATE `UserTrace` SET '.
    138138        '`LastLogin` = NOW(), '.
     
    144144    };
    145145  }
    146  
     146
    147147  function Logout()
    148148  {
     
    157157    }
    158158  }
    159  
     159
    160160  function Load()
    161161  {
     
    180180    } else $this->SetAnonymous();
    181181  }
    182  
     182
    183183  function SetAnonymous()
    184184  {
     
    187187    $this->Role = LICENCE_ANONYMOUS;
    188188    $this->Language = NULL;
    189     $this->Redirecting = 1; 
     189    $this->Redirecting = 1;
    190190    $this->Team = '';
    191191    $this->Email = '';
    192192  }
    193  
     193
    194194  function Licence($Licence)
    195195  {
    196196    if(!isset($_SERVER['REMOTE_ADDR'])) return(true); // Execution from command line
    197     else return($this->Role >= $Licence);   
    198   }
    199  
     197    else return($this->Role >= $Licence);
     198  }
     199
    200200  function CheckToken($Licence, $Token)
    201201  {
     
    207207      $DbRow2 = $DbResult2->fetch_assoc();
    208208      return($DbRow2['GM'] >= $Licence);
    209     } else return(false);   
     209    } else return(false);
    210210  }
    211211
     
    214214    return(substr(sha1(mt_rand()), 0, 8));
    215215  }
    216  
     216
    217217  function CryptPasswordSQL($Password, $Salt)
    218218  {
    219219    return('SHA1(CONCAT(SHA1('.$Password.'), '.$Salt.'))');
    220   } 
    221  
     220  }
     221
    222222  function Check()
    223223  {
     
    229229      // Refresh time of last access
    230230      $this->Database->update('UserOnline', 'SessionId="'.$SID.'"', array('ActivityTime' => 'NOW()'));
    231     } else $this->Database->insert('UserOnline', array('SessionId' => $SID, 
    232       'User' => null, 'LoginTime' => 'NOW()', 'ActivityTime' => 'NOW()', 
    233       'IpAddress' => GetRemoteAddress(), 'HostName' => gethostbyaddr(GetRemoteAddress()), 
     231    } else $this->Database->insert('UserOnline', array('SessionId' => $SID,
     232      'User' => null, 'LoginTime' => 'NOW()', 'ActivityTime' => 'NOW()',
     233      'IpAddress' => GetRemoteAddress(), 'HostName' => gethostbyaddr(GetRemoteAddress()),
    234234      'ScriptName' => $_SERVER['REQUEST_URI']));
    235      
    236     // Logged permanently? 
    237           if(array_key_exists('LoginHash', $_COOKIE)) 
    238           { 
    239             $DbResult = $this->Database->query('SELECT * FROM `UserOnline` WHERE `User`='.$_COOKIE['LoginUserId']. 
    240               ' AND `StayLogged`=1 AND SessionId!="'.$SID.'"'); 
    241             if($DbResult->num_rows > 0) 
    242             { 
    243               $DbRow = $DbResult->fetch_assoc(); 
    244               if(sha1($_COOKIE['LoginUserId'].$DbRow['StayLoggedHash']) == $_COOKIE['LoginHash']) 
    245               {               
    246                 $this->Database->query('DELETE FROM `UserOnline` WHERE `SessionId`="'.$SID.'"'); 
    247                 $this->Database->query('UPDATE `UserOnline` SET `SessionId`="'.$SID.'" WHERE `Id`='.$DbRow['Id']); 
    248               } 
    249             } 
    250     } 
    251        
     235
     236    // Logged permanently?
     237          if(array_key_exists('LoginHash', $_COOKIE))
     238          {
     239            $DbResult = $this->Database->query('SELECT * FROM `UserOnline` WHERE `User`='.$_COOKIE['LoginUserId'].
     240              ' AND `StayLogged`=1 AND SessionId!="'.$SID.'"');
     241            if($DbResult->num_rows > 0)
     242            {
     243              $DbRow = $DbResult->fetch_assoc();
     244              if(sha1($_COOKIE['LoginUserId'].$DbRow['StayLoggedHash']) == $_COOKIE['LoginHash'])
     245              {
     246                $this->Database->query('DELETE FROM `UserOnline` WHERE `SessionId`="'.$SID.'"');
     247                $this->Database->query('UPDATE `UserOnline` SET `SessionId`="'.$SID.'" WHERE `Id`='.$DbRow['Id']);
     248              }
     249            }
     250    }
     251
    252252          // Check login
    253253    $Query = $this->Database->select('UserOnline', '*', '`SessionId`="'.$SID.'"');
    254254    $Row = $Query->fetch_assoc();
    255     if($Row['User'] != '') 
     255    if($Row['User'] != '')
    256256    {
    257257        $this->Id = $Row['User'];
    258258      $this->Load();
    259     } else 
     259    } else
    260260    {
    261261      $this->SetAnonymous();
    262262    }
    263    
     263
    264264    // Remove nonactive users
    265265    $DbResult = $this->Database->select('UserOnline', '`Id`, `User`', '(`ActivityTime` < DATE_SUB(NOW(), INTERVAL '.$this->OnlineStateTimeout.' SECOND)) AND (`StayLogged` = 0)');
     
    269269    }
    270270  }
    271  
     271
    272272  function Register($UserName, $Password, $Email, $Language, $Team, $PreferredVersion)
    273273  {
    274274    $Salt = $this->GetPasswordSalt();
     275    if($Team == null) $Team = 'NULL';
     276    if($PreferredVersion == null) $PreferredVersion = 'NULL';
    275277    $this->Database->query('INSERT INTO `User` '.
    276278      '(`Name` , `Pass` , `Salt`, `Email` , `Language` , `Team` , `NeedUpdate`, `RegistrationTime`, `PreferredVersion` ) '.
  • trunk/includes/Version.php

    r800 r801  
    66// and system will need database update.
    77
    8 $Revision = 800; // Subversion revision
     8$Revision = 801; // Subversion revision
    99$DatabaseRevision = 787; // Database structure revision
    10 $ReleaseTime = '2014-03-16';
     10$ReleaseTime = '2014-03-31';
Note: See TracChangeset for help on using the changeset viewer.