Changeset 801 for trunk/Modules/User
- Timestamp:
- Mar 31, 2014, 9:10:41 AM (11 years ago)
- Location:
- trunk/Modules/User
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Modules/User/Registration.php
r787 r801 5 5 function ShowForm() 6 6 { 7 global $System;8 9 7 if(array_key_exists('sc', $_POST)) $Human = true; 10 8 else $Human = false; 11 9 if(array_key_exists('user', $_POST)) $UserName = $_POST['user']; 12 10 else $UserName = ''; … … 17 15 if(array_key_exists('Language', $_POST)) $Language = $_POST['Language']; 18 16 else $Language = 1; 19 17 20 18 $Output = '<form action="?" method="post"> 21 19 <fieldset><legend>'.T('New user registration').'</legend> … … 64 62 </tr>'; 65 63 $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 68 66 $Output .= '<tr><td>'; 69 67 $Query = 'SELECT * FROM UserTagType'; 70 68 $DbResult = $this->Database->query($Query); 71 69 $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'); 76 74 $Output .= ''.$UserTag['Text'].'<br />'; 77 75 } 78 76 $Output .= '</td></tr>'; 79 77 80 78 $Output .= '<tr> 81 79 <th><input type="submit" value="Registrovat" /></th> … … 84 82 return($Output); 85 83 } 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 87 159 function Show() 88 160 { 89 global $Config;90 91 161 $this->Title = T('User registration'); 92 162 $Output = ''; 93 163 if(array_key_exists('user', $_POST)) 94 164 { 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(); 157 166 } else $Output .= $this->ShowForm(); 158 167 return($Output); 159 } 160 } 168 } 169 } -
trunk/Modules/User/User.php
r791 r801 18 18 $this->Dependencies = array(); 19 19 } 20 20 21 21 function Start() 22 22 { … … 38 38 T('Translators'), array('Name'), '`User`', $this->System->Link('/userlist.php?search=')); 39 39 } 40 40 41 41 function ShowOnlineList() 42 42 { 43 43 $Output = T('Online translators').':<br />'; 44 $DbResult = $this->System->Database->query('SELECT * FROM ('. 44 $DbResult = $this->System->Database->query('SELECT * FROM ('. 45 45 'SELECT `User`.`Name`, `User`.`ID` FROM `UserOnline` '. 46 46 'JOIN `User` ON `User`.`ID` = `UserOnline`.`User` '. … … 53 53 } 54 54 return($Output); 55 } 55 } 56 56 } 57 57 … … 61 61 { 62 62 $Output = '<form action="'.$this->System->Link('/?action=login').'" method="post">'. 63 '<fieldset><legend>'.T('Login').'</legend> 63 '<fieldset><legend>'.T('Login').'</legend> 64 64 <table> 65 65 <tr> … … 99 99 var $OnlineStateTimeout; 100 100 var $PreferredVersion = 0; 101 101 102 102 function __construct($System) 103 103 { … … 105 105 $this->Database = &$System->Database; 106 106 $this->OnlineStateTimeout = 600; // in seconds 107 if(isset($_SESSION)) $this->Check(); 108 } 109 107 if(isset($_SESSION)) $this->Check(); 108 } 109 110 110 function __destroy() 111 111 { 112 112 } 113 113 114 114 function Login($Name, $Password, $StayLogged = false) 115 115 { … … 120 120 { 121 121 $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 125 125 $StayLoggedSalt = $this->GetPasswordSalt(); 126 126 $this->Database->update('UserOnline', 'SessionId="'.$SID.'"', array( 127 127 'User' => $User['ID'], 'StayLogged' => $StayLogged, 'StayLoggedHash' => $StayLoggedSalt)); 128 if($StayLogged) 128 if($StayLogged) 129 129 { 130 130 setcookie('LoginUserId', $User['ID'], time()+365*24*60*60); … … 133 133 setcookie('LoginUserId', '', time() - 3600); 134 134 setcookie('LoginHash', '', time() - 3600); 135 } 136 135 } 136 137 137 $this->Database->query('UPDATE `UserTrace` SET '. 138 138 '`LastLogin` = NOW(), '. … … 144 144 }; 145 145 } 146 146 147 147 function Logout() 148 148 { … … 157 157 } 158 158 } 159 159 160 160 function Load() 161 161 { … … 180 180 } else $this->SetAnonymous(); 181 181 } 182 182 183 183 function SetAnonymous() 184 184 { … … 187 187 $this->Role = LICENCE_ANONYMOUS; 188 188 $this->Language = NULL; 189 $this->Redirecting = 1; 189 $this->Redirecting = 1; 190 190 $this->Team = ''; 191 191 $this->Email = ''; 192 192 } 193 193 194 194 function Licence($Licence) 195 195 { 196 196 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 200 200 function CheckToken($Licence, $Token) 201 201 { … … 207 207 $DbRow2 = $DbResult2->fetch_assoc(); 208 208 return($DbRow2['GM'] >= $Licence); 209 } else return(false); 209 } else return(false); 210 210 } 211 211 … … 214 214 return(substr(sha1(mt_rand()), 0, 8)); 215 215 } 216 216 217 217 function CryptPasswordSQL($Password, $Salt) 218 218 { 219 219 return('SHA1(CONCAT(SHA1('.$Password.'), '.$Salt.'))'); 220 } 221 220 } 221 222 222 function Check() 223 223 { … … 229 229 // Refresh time of last access 230 230 $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()), 234 234 '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 252 252 // Check login 253 253 $Query = $this->Database->select('UserOnline', '*', '`SessionId`="'.$SID.'"'); 254 254 $Row = $Query->fetch_assoc(); 255 if($Row['User'] != '') 255 if($Row['User'] != '') 256 256 { 257 257 $this->Id = $Row['User']; 258 258 $this->Load(); 259 } else 259 } else 260 260 { 261 261 $this->SetAnonymous(); 262 262 } 263 263 264 264 // Remove nonactive users 265 265 $DbResult = $this->Database->select('UserOnline', '`Id`, `User`', '(`ActivityTime` < DATE_SUB(NOW(), INTERVAL '.$this->OnlineStateTimeout.' SECOND)) AND (`StayLogged` = 0)'); … … 269 269 } 270 270 } 271 271 272 272 function Register($UserName, $Password, $Email, $Language, $Team, $PreferredVersion) 273 273 { 274 274 $Salt = $this->GetPasswordSalt(); 275 if($Team == null) $Team = 'NULL'; 276 if($PreferredVersion == null) $PreferredVersion = 'NULL'; 275 277 $this->Database->query('INSERT INTO `User` '. 276 278 '(`Name` , `Pass` , `Salt`, `Email` , `Language` , `Team` , `NeedUpdate`, `RegistrationTime`, `PreferredVersion` ) '.
Note:
See TracChangeset
for help on using the changeset viewer.