Changeset 801 for trunk/Modules/User/User.php
- Timestamp:
- Mar 31, 2014, 9:10:41 AM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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.