Changeset 100 for devel/www/user.php
- Timestamp:
- Aug 1, 2008, 2:47:59 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
devel/www/user.php
r96 r100 1 1 <?php 2 2 3 define('NICK_USED', 'Přezdívka použita!'); 3 define('NICK_USED', 'Přihlašovací jméno již použito.'); 4 define('EMAIL_USED', 'Email je již použitý.'); 4 5 define('USER_REGISTRATED', 'Uživatel zaregistrován.'); 5 define('DATA_MISSING', 'Chybí emailová adresa, přezdívka, nebo některé z hesel!'); 6 define('PASSWORDS_UNMATCHED', 'Hesla si neodpovídají!'); 6 define('USER_REGISTRATION_CONFIRMED', 'Vaše registrace byla potvrzena.'); 7 define('DATA_MISSING', 'Chybí emailová adresa, přezdívka, nebo některé z hesel.'); 8 define('PASSWORDS_UNMATCHED', 'Hesla si neodpovídají.'); 9 define('ACCOUNT_LOCKED', 'Účet uzamčen. Po registraci je nutné provést aktivaci účtu podle zaslaného aktivačního emailu.'); 7 10 define('USER_NOT_LOGGED', 'Nejste přihlášen.'); 8 11 define('USER_LOGGED', 'Uživatel přihlášen.'); … … 12 15 define('USER_LOGGED_OUT', 'Byl jste odhlášen.'); 13 16 define('BAD_PASSWORD', 'Špatné heslo.'); 14 define('USER_NOT_FOUND', 'Uživatel enenalezen.');17 define('USER_NOT_FOUND', 'Uživatel nenalezen.'); 15 18 define('USER_TIMEOUT', 300); // in seconds 16 19 define('USER_PASSWORD_RECOVERY_SUCCESS', 'Přihlašovací údaje byly odeslány na zadanou emailovou adresu.'); … … 39 42 { 40 43 // Refresh time of last access 41 $this->Database->update('UserOnline', 'SessionId="'.$SID.'"', array(' Time' => 'NOW()'));42 } else $this->Database->insert('UserOnline', array('SessionId' => $SID, 'User' => $this->AnonymousUserId, ' Time' => 'NOW()', 'IpAddress' => GetRemoteAddress(), 'HostName' => gethostbyaddr(GetRemoteAddress())));44 $this->Database->update('UserOnline', 'SessionId="'.$SID.'"', array('ActivityTime' => 'NOW()')); 45 } else $this->Database->insert('UserOnline', array('SessionId' => $SID, 'User' => $this->AnonymousUserId, 'LoginTime' => 'NOW()', 'ActivityTime' => 'NOW()', 'IpAddress' => GetRemoteAddress(), 'HostName' => gethostbyaddr(GetRemoteAddress()))); 43 46 //echo($this->Database->LastQuery); 44 45 // Odeber neaktivní uživatele46 $this->Database->delete('UserOnline', 'Time < DATE_SUB(NOW(), INTERVAL '.USER_TIMEOUT.' SECOND)');47 47 48 48 // Zkontroluj přihlášení … … 60 60 $Result = USER_NOT_LOGGED; 61 61 } 62 63 // Odeber neaktivní uživatele 64 $DbResult = $this->Database->select('UserOnline', 'User', 'ActivityTime < DATE_SUB(NOW(), INTERVAL '.USER_TIMEOUT.' SECOND)'); 65 while($DbRow = $DbResult->fetch_array()) 66 { 67 $this->Database->delete('UserOnline', 'Id='.$DbRow['User']); 68 $this->System->Modules['Log']->NewRecord('User', 'Logout'); 69 } 62 70 //$this->LoadPermission($this->User['Role']); 63 71 64 72 // Role and permission 65 73 //$this->LoadRoles(); 66 67 74 } 68 75 69 76 function Register($Nick, $Password, $Password2, $Email, $FirstName, $SecondName) 70 77 { 71 global $Options; 78 global $Options, $Config; 79 72 80 if(($Email == '') || ($Nick == '') || ($Password == '') || ($Password2 == '')) $Result = DATA_MISSING; 73 81 else if($Password != $Password2) $Result = PASSWORDS_UNMATCHED; 74 else 82 else 75 83 { 76 84 // Je uživatel registrován? 77 85 $Query = $this->Database->select('User', '*', 'Name = "'.$Nick.'"'); 78 86 if($Query->num_rows > 0) $Result = NICK_USED; 79 else 80 { 81 $this->Database->insert('User', array('Name' => $Nick, 'FirstName' => $FirstName, 'SecondName' => $SecondName, 'Password' => sha1($Password), 'Email' => $Email, 'RegistrationTime' => 'NOW()')); 82 $Result = USER_REGISTRATED; 83 $this->System->Modules['Log']->NewRecord('User', 'Uživatel registrován', $Nick); 87 else 88 { 89 $Query = $this->Database->select('User', '*', 'Email = "'.$Email.'"'); 90 if($Query->num_rows > 0) $Result = EMAIL_USED; 91 else 92 { 93 $this->Database->insert('User', array('Name' => $Nick, 'FirstName' => $FirstName, 'SecondName' => $SecondName, 'Password' => sha1($Password), 'Email' => $Email, 'RegistrationTime' => 'NOW()')); 94 $UserId = $this->Database->insert_id; 95 96 $Subject = from_utf8('Registrace nového účtu', 'iso2'); 97 $Message = 'Provedli jste registraci nového účtu na serveru <a href="http://'.$Config['Web']['Host'].$Config['Web']['RootFolder'].'">http://'.$Config['Web']['Host'].$Config['Web']['RootFolder']."</a>.<br>\nPokud jste tak neučinili, měli by jste tento email ignorovat.<br><br>\n\nVáš účet je: ".$Nick."\n<br>Pro dokončení registrace klikněte na ".'<a href="http://'.$Config['Web']['Host'].$Config['Web']['RootFolder'].'/?Action=UserRegisterConfirm&User='.$UserId.'&H='.sha1($Password).'">tento odkaz</a>.'."\n<br> \n\n<br><br>Na tento email neodpovídejte."; 98 $AdditionalHeaders = "To: ".$Nick." <".$Email.">\n"."From: ".from_utf8($Config['Web']['Title'], 'iso2')." <noreplay@zdechov.net>\n"."MIME-Version: 1.0\n"."Content-type: text/html; charset=utf-8"; 99 mail($Email, $Subject, $Message, $AdditionalHeaders); 100 $Result = USER_REGISTRATED; 101 $this->System->Modules['Log']->NewRecord('User', 'NewRegistration', $Nick); 102 } 84 103 } 85 104 } 86 105 return($Result); 106 } 107 108 function RegisterConfirm($Id, $Hash) 109 { 110 $DbResult = $this->Database->select('User', 'Id, Name, Password', 'Id = '.$Id); 111 if($DbResult->num_rows > 0) 112 { 113 $Row = $DbResult->fetch_array(); 114 if($Hash == $Row['Password']) 115 { 116 $this->Database->update('User', 'Id='.$Row['Id'], array('Locked' => 0)); 117 $Output = USER_REGISTRATION_CONFIRMED; 118 $this->System->Modules['Log']->NewRecord('User', 'RegisterConfirm', 'Username='.$Row['Name']); 119 } else $Output = PASSWORDS_UNMATCHED; 120 } else $Output = USER_NOT_FOUND; 121 return($Output); 87 122 } 88 123 … … 96 131 $Row = $Query->fetch_array(); 97 132 if($Row['Password'] != sha1($Password)) $Result = BAD_PASSWORD; 133 else if($Row['Locked'] == 1) $Result = ACCOUNT_LOCKED; 98 134 else 99 135 { 100 $this->Database->update('User', 'Id='.$Row['Id'], array('LastLoginTime' => 'NOW()')); 136 $this->Database->update('User', 'Id='.$Row['Id'], array('LastLoginTime' => 'NOW()')); 101 137 $this->Database->update('UserOnline', 'SessionId="'.$SID.'"', array('User' => $Row['Id'])); 102 138 // načtení stavu stromu 103 $Result = USER_LOGGED_IN; 104 $this->System->Modules['Log']->NewRecord('User', ' Uživatel přihlášen', $Nick);139 $Result = USER_LOGGED_IN; 140 $this->System->Modules['Log']->NewRecord('User', 'Login', 'Nick='.$Nick.',Host='.gethostbyaddr(GetRemoteAddress())); 105 141 } 106 142 } else $Result = USER_NOT_REGISTRED; … … 113 149 $SID = session_id(); 114 150 $this->Database->update('UserOnline', 'SessionId="'.$SID.'"', array('User' => $this->AnonymousUserId)); 115 $this->System->Modules['Log']->NewRecord('User', ' Uživatel odhlášen', $this->User['Name']);151 $this->System->Modules['Log']->NewRecord('User', 'Logout', $this->User['Name']); 116 152 $this->Check(); 117 153 return(USER_LOGGED_OUT); … … 145 181 if($DbRow['Write']) $Value .= 'W'; 146 182 $Result[$DbRow['Description']][$DbRow['Title']] = $Value; 147 } 183 } 148 184 return($Result); 149 185 } … … 201 237 mail($Row['Email'], $Subject, $Message, $AdditionalHeaders); 202 238 $Output = USER_PASSWORD_RECOVERY_SUCCESS; 239 $this->System->Modules['Log']->NewRecord('User', 'PasswordRecoveryRequest', 'Username='.$Name.',Email='.$Email); 203 240 } else $Output = USER_PASSWORD_RECOVERY_FAIL; 204 241 return($Output); … … 216 253 $this->Database->update('User', 'Id='.$Row['Id'], array('Password' => sha1($NewPassword))); 217 254 $Output = USER_PASSWORD_RECOVERY_CONFIRMED; 255 $this->System->Modules['Log']->NewRecord('User', 'PasswordRecoveryConfirm', 'Username='.$Row['Name']); 218 256 } else $Output = PASSWORDS_UNMATCHED; 219 257 } else $Output = USER_NOT_FOUND;
Note:
See TracChangeset
for help on using the changeset viewer.