Changeset 816 for trunk/Modules/User/User.php
- Timestamp:
- Feb 22, 2015, 11:20:50 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Modules/User/User.php
r805 r816 8 8 class ModuleUser extends AppModule 9 9 { 10 11 12 13 14 15 16 17 18 19 20 21 22 23 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); 24 24 $this->System->RegisterPage('userlist.php', 'PageUserList'); 25 26 27 28 29 30 31 32 33 34 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' => '', 35 35 ), 0); 36 36 if(array_key_exists('Search', $this->System->ModuleManager->Modules)) 37 37 $this->System->ModuleManager->Modules['Search']->RegisterSearch('user', 38 38 T('Translators'), array('Name'), '`User`', $this->System->Link('/userlist.php?search=')); 39 40 41 42 43 44 39 } 40 41 function ShowOnlineList() 42 { 43 $Output = T('Online translators').':<br />'; 44 $DbResult = $this->System->Database->query('SELECT * FROM ('. 45 45 'SELECT `User`.`Name`, `User`.`ID` FROM `UserOnline` '. 46 47 48 49 50 51 52 53 54 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 } 56 56 } 57 57 58 58 class PageUserLogin extends Page 59 59 { 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 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 } 81 81 } 82 82 … … 114 114 function Login($Name, $Password, $StayLogged = false) 115 115 { 116 116 $SID = session_id(); 117 117 $DbResult = $this->Database->query('SELECT `ID` FROM `User` WHERE '. 118 118 'LOWER(`Name`) = LOWER("'.$Name.'") AND `Pass` = '.$this->CryptPasswordSQL('"'.$Password.'"', '`Salt`')); … … 147 147 function Logout() 148 148 { 149 149 $SID = session_id(); 150 150 if($this->Role != LICENCE_ANONYMOUS) 151 151 { … … 162 162 $DbResult = $this->Database->query('SELECT `User`.`PreferredVersion`,`User`.`ID`,`User`.`Team`,`User`.`Redirecting`,`User`.`Email`,`User`.`Info`,'. 163 163 '`User`.`Language`,`User`.`Name`,`User`.`GM`,`ClientVersion`.`Version` AS `PreferredVersionGame` FROM `User` '. 164 164 'LEFT JOIN `ClientVersion` ON `ClientVersion`.`Id` = `User`.`PreferredVersion` '. 165 165 'WHERE `User`.`ID` = '.$this->Id); 166 166 if($DbResult->num_rows > 0) … … 230 230 $this->Database->update('UserOnline', 'SessionId="'.$SID.'"', array('ActivityTime' => 'NOW()')); 231 231 } else { 232 233 234 232 if(GetRemoteAddress() != '') $HostName = gethostbyaddr(GetRemoteAddress()); 233 else $HostName = ''; 234 $this->Database->insert('UserOnline', array('SessionId' => $SID, 235 235 'User' => null, 'LoginTime' => 'NOW()', 'ActivityTime' => 'NOW()', 236 236 'IpAddress' => GetRemoteAddress(), 'HostName' => $HostName, 237 237 'ScriptName' => GetRequestURI())); 238 238 } 239 239 240 240 // Logged permanently? 241 242 243 244 245 246 247 248 249 250 251 252 253 254 } 255 256 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 257 257 $Query = $this->Database->select('UserOnline', '*', '`SessionId`="'.$SID.'"'); 258 258 $Row = $Query->fetch_assoc(); 259 259 if($Row['User'] != '') 260 260 { 261 261 $this->Id = $Row['User']; 262 262 $this->Load(); 263 263 } else
Note:
See TracChangeset
for help on using the changeset viewer.