1 | <?php
|
---|
2 |
|
---|
3 | include_once(dirname(__FILE__).'/UserList.php');
|
---|
4 |
|
---|
5 | define('LOGIN_USED', 'Přihlašovací jméno již použito.');
|
---|
6 | define('NAME_USED', 'Jméno uživatele již použito');
|
---|
7 | define('EMAIL_USED', 'Email je již použitý. Použijte jiný email nebo si můžete nechat zaslat nové heslo na email.');
|
---|
8 | define('USER_REGISTRATED', 'Uživatel registrován. Na zadanou emailovou adresu byl poslán mail s odkazem pro aktivování účtu.');
|
---|
9 | define('USER_REGISTRATION_CONFIRMED', 'Vaše registrace byla potvrzena.');
|
---|
10 | define('DATA_MISSING', 'Chybí emailová adresa, přezdívka, nebo některé z hesel.');
|
---|
11 | define('PASSWORDS_UNMATCHED', 'Hesla si neodpovídají.');
|
---|
12 | define('ACCOUNT_LOCKED', 'Účet je uzamčen. Po registraci je nutné provést aktivaci účtu pomocí odkazu zaslaného v aktivačním emailu.');
|
---|
13 | define('USER_NOT_LOGGED', 'Nejste přihlášen.');
|
---|
14 | define('USER_LOGGED', 'Uživatel přihlášen.');
|
---|
15 | define('USER_NOT_REGISTRED', 'Uživatel neregistrován.');
|
---|
16 | define('USER_ALREADY_LOGGED', 'Uživatel již přihlášen.');
|
---|
17 | define('USER_LOGGED_IN', 'Byl jste přihlášen.');
|
---|
18 | define('USER_LOGGED_OUT', 'Byl jste odhlášen.');
|
---|
19 | define('BAD_PASSWORD', 'Špatné heslo.');
|
---|
20 | define('USER_NOT_FOUND', 'Uživatel nenalezen.');
|
---|
21 | define('USER_PASSWORD_RECOVERY_SUCCESS', 'Přihlašovací údaje byly odeslány na zadanou emailovou adresu.');
|
---|
22 | define('USER_PASSWORD_RECOVERY_FAIL', 'Podle zadaných údajů nebyl nalezen žádný uživatel.');
|
---|
23 | define('USER_PASSWORD_RECOVERY_CONFIRMED', 'Nové heslo bylo aktivováno.');
|
---|
24 |
|
---|
25 | define('USER_EVENT_REGISTER', 1);
|
---|
26 | define('USER_EVENT_LOGIN', 2);
|
---|
27 | define('USER_EVENT_LOGOUT', 3);
|
---|
28 | define('USER_EVENT_OPTIONS_CHANGED', 4);
|
---|
29 |
|
---|
30 | class PasswordHash
|
---|
31 | {
|
---|
32 | function Hash($Password, $Salt)
|
---|
33 | {
|
---|
34 | return(sha1(sha1($Password).$Salt));
|
---|
35 | }
|
---|
36 |
|
---|
37 | function Verify($Password, $Salt, $StoredHash)
|
---|
38 | {
|
---|
39 | return($this->Hash($Password, $Salt) == $StoredHash);
|
---|
40 | }
|
---|
41 |
|
---|
42 | function GetSalt()
|
---|
43 | {
|
---|
44 | mt_srand(microtime(true)*100000 + memory_get_usage(true));
|
---|
45 | return sha1(uniqid(mt_rand(), true));
|
---|
46 | }
|
---|
47 | }
|
---|
48 |
|
---|
49 | // TODO: Make User class more general without dependencies to System, Mail, Log
|
---|
50 |
|
---|
51 | class User extends Model
|
---|
52 | {
|
---|
53 | var $Roles = array();
|
---|
54 | var $User = array();
|
---|
55 | var $OnlineStateTimeout = 600; // in seconds
|
---|
56 | var $PermissionCache = array();
|
---|
57 | var $PermissionGroupCache = array();
|
---|
58 | var $PermissionGroupCacheOp = array();
|
---|
59 | /** @var Password */
|
---|
60 | var $PasswordHash;
|
---|
61 |
|
---|
62 | function __construct($System)
|
---|
63 | {
|
---|
64 | parent::__construct($System);
|
---|
65 | $this->PasswordHash = new PasswordHash();
|
---|
66 | }
|
---|
67 |
|
---|
68 | function Check()
|
---|
69 | {
|
---|
70 | $SID = session_id();
|
---|
71 | // Lookup user record
|
---|
72 | $Query = $this->Database->select('UserOnline', '*', 'SessionId="'.$SID.'"');
|
---|
73 | if($Query->num_rows > 0)
|
---|
74 | {
|
---|
75 | // Refresh time of last access
|
---|
76 | $this->Database->update('UserOnline', 'SessionId="'.$SID.'"', array('ActivityTime' => 'NOW()'));
|
---|
77 | } else $this->Database->insert('UserOnline', array('SessionId' => $SID,
|
---|
78 | 'User' => null, 'LoginTime' => 'NOW()', 'ActivityTime' => 'NOW()',
|
---|
79 | 'IpAddress' => GetRemoteAddress(), 'HostName' => gethostbyaddr(GetRemoteAddress()),
|
---|
80 | 'ScriptName' => $_SERVER['PHP_SELF']));
|
---|
81 |
|
---|
82 | // Check login
|
---|
83 | $Query = $this->Database->select('UserOnline', '*', 'SessionId="'.$SID.'"');
|
---|
84 | $Row = $Query->fetch_assoc();
|
---|
85 | if($Row['User'] != '')
|
---|
86 | {
|
---|
87 | $Query = $this->Database->query('SELECT User.*, UserCustomerRel.Customer AS Member FROM User LEFT JOIN UserCustomerRel ON UserCustomerRel.User=User.Id WHERE User.Id='.$Row['User']);
|
---|
88 | $this->User = $Query->fetch_assoc();
|
---|
89 | $Result = USER_LOGGED;
|
---|
90 | } else
|
---|
91 | {
|
---|
92 | $Query = $this->Database->select('User', '*', 'Id IS NULL');
|
---|
93 | $this->User = array('Id' => null, 'Member' => null);
|
---|
94 | $Result = USER_NOT_LOGGED;
|
---|
95 | }
|
---|
96 |
|
---|
97 | // Remove nonactive users
|
---|
98 | $DbResult = $this->Database->select('UserOnline', 'Id, User', 'ActivityTime < DATE_SUB(NOW(), INTERVAL '.$this->OnlineStateTimeout.' SECOND)');
|
---|
99 | while($DbRow = $DbResult->fetch_array())
|
---|
100 | {
|
---|
101 | $this->Database->delete('UserOnline', 'Id='.$DbRow['Id']);
|
---|
102 | if($DbRow['User'] != null) $this->System->ModuleManager->Modules['Log']->NewRecord('User', 'Logout');
|
---|
103 | }
|
---|
104 | //$this->LoadPermission($this->User['Role']);
|
---|
105 |
|
---|
106 | // Role and permission
|
---|
107 | //$this->LoadRoles();
|
---|
108 | }
|
---|
109 |
|
---|
110 | function Register($Login, $Password, $Password2, $Email, $Name, $PhoneNumber, $ICQ)
|
---|
111 | {
|
---|
112 | if(($Email == '') || ($Login == '') || ($Password == '') || ($Password2 == '') || ($Name == '')) $Result = DATA_MISSING;
|
---|
113 | else if($Password != $Password2) $Result = PASSWORDS_UNMATCHED;
|
---|
114 | else
|
---|
115 | {
|
---|
116 | // Is user registred yet?
|
---|
117 | $Query = $this->Database->select('User', '*', 'Login = "'.$Login.'"');
|
---|
118 | if($Query->num_rows > 0) $Result = LOGIN_USED;
|
---|
119 | else
|
---|
120 | {
|
---|
121 | $Query = $this->Database->select('User', '*', 'Name = "'.$Name.'"');
|
---|
122 | if($Query->num_rows > 0) $Result = NAME_USED;
|
---|
123 | else
|
---|
124 | {
|
---|
125 | $Query = $this->Database->select('User', '*', 'Email = "'.$Email.'"');
|
---|
126 | if($Query->num_rows > 0) $Result = EMAIL_USED;
|
---|
127 | else
|
---|
128 | {
|
---|
129 | $PasswordHash = new PasswordHash();
|
---|
130 | $Salt = $PasswordHash->GetSalt();
|
---|
131 | $this->Database->insert('User', array('Name' => $Name, 'Login' => $Login,
|
---|
132 | 'Password' => $PasswordHash->Hash($Password, $Salt), 'Salt' => $Salt,
|
---|
133 | 'Email' => $Email, 'RegistrationTime' => 'NOW()',
|
---|
134 | 'Locked' => 1, 'PhoneNumber' => $PhoneNumber, 'ICQ' => $ICQ));
|
---|
135 | $UserId = $this->Database->insert_id;
|
---|
136 | $this->Database->insert('PermissionUserAssignment', array('User' => $UserId,
|
---|
137 | 'AssignedGroup' => 2));
|
---|
138 |
|
---|
139 | $NewPassword = substr(sha1(strtoupper($Login)), 0, 7);
|
---|
140 |
|
---|
141 | // Send activation mail to user email
|
---|
142 | $ServerURL = 'http://'.$this->System->Config['Web']['Host'].$this->System->Config['Web']['RootFolder'];
|
---|
143 | $Mail = new Mail();
|
---|
144 | $Mail->Subject = 'Registrace nového účtu';
|
---|
145 | $Mail->AddBody('Provedli jste registraci nového účtu na serveru <a href="'.$ServerURL.'">'.$ServerURL.'"</a>.'.
|
---|
146 | '<br/>\nPokud jste tak neučinili, měli by jste tento email ignorovat.<br/><br/>\n\n'.
|
---|
147 | 'Váš účet je: '.$Login."\n<br/>Pro dokončení registrace klikněte na tento odkaz: ".'<a href="'.
|
---|
148 | $ServerURL.'/?Action=UserRegisterConfirm&User='.
|
---|
149 | $UserId.'&H='.$NewPassword.'">'.$ServerURL.'/?Action=UserRegisterConfirm&User='.
|
---|
150 | $UserId.'&H='.$NewPassword.'</a>.'."\n<br> \n\n'.
|
---|
151 | '<br/><br/>Na tento email neodpovídejte.", 'text/html');
|
---|
152 | $Mail->AddTo($Email, $Name);
|
---|
153 | $Mail->From = $this->System->Config['Web']['Title'].' <noreplay@zdechov.net>';
|
---|
154 | $Mail->Send();
|
---|
155 |
|
---|
156 | $Result = USER_REGISTRATED;
|
---|
157 | $this->System->ModuleManager->Modules['Log']->NewRecord('User', 'NewRegistration', $Login);
|
---|
158 | }
|
---|
159 | }
|
---|
160 | }
|
---|
161 | }
|
---|
162 | return($Result);
|
---|
163 | }
|
---|
164 |
|
---|
165 | function RegisterConfirm($Id, $Hash)
|
---|
166 | {
|
---|
167 | $DbResult = $this->Database->select('User', 'Id, Login, Password', 'Id = '.$Id);
|
---|
168 | if($DbResult->num_rows > 0)
|
---|
169 | {
|
---|
170 | $Row = $DbResult->fetch_array();
|
---|
171 | $NewPassword = substr(sha1(strtoupper($Row['Login'])), 0, 7);
|
---|
172 | if($Hash == $NewPassword)
|
---|
173 | {
|
---|
174 | $this->Database->update('User', 'Id='.$Row['Id'], array('Locked' => 0));
|
---|
175 | $Output = USER_REGISTRATION_CONFIRMED;
|
---|
176 | $this->System->ModuleManager->Modules['Log']->NewRecord('User', 'RegisterConfirm', 'Login='.
|
---|
177 | $Row['Login'].', Id='.$Row['Id']);
|
---|
178 | } else $Output = PASSWORDS_UNMATCHED;
|
---|
179 | } else $Output = USER_NOT_FOUND;
|
---|
180 | return($Output);
|
---|
181 | }
|
---|
182 |
|
---|
183 | function Login($Login, $Password)
|
---|
184 | {
|
---|
185 | $SID = session_id();
|
---|
186 | $Query = $this->Database->select('User', '*', 'Login="'.$Login.'"');
|
---|
187 | if($Query->num_rows > 0)
|
---|
188 | {
|
---|
189 | $Row = $Query->fetch_assoc();
|
---|
190 | $PasswordHash = new PasswordHash();
|
---|
191 | if(!$PasswordHash->Verify($Password, $Row['Salt'], $Row['Password'])) $Result = BAD_PASSWORD;
|
---|
192 | else if($Row['Locked'] == 1) $Result = ACCOUNT_LOCKED;
|
---|
193 | else
|
---|
194 | {
|
---|
195 | $this->Database->update('User', 'Id='.$Row['Id'], array('LastLoginTime' => 'NOW()', 'LastIpAddress' => GetRemoteAddress()));
|
---|
196 | $this->Database->update('UserOnline', 'SessionId="'.$SID.'"', array('User' => $Row['Id']));
|
---|
197 |
|
---|
198 | $Result = USER_LOGGED_IN;
|
---|
199 | $this->Check();
|
---|
200 | $this->System->ModuleManager->Modules['Log']->NewRecord('User', 'Login', 'Login='.$Login.',Host='.gethostbyaddr(GetRemoteAddress()));
|
---|
201 | }
|
---|
202 | } else $Result = USER_NOT_REGISTRED;
|
---|
203 | return($Result);
|
---|
204 | }
|
---|
205 |
|
---|
206 | function Logout()
|
---|
207 | {
|
---|
208 | $SID = session_id();
|
---|
209 | $this->Database->update('UserOnline', 'SessionId="'.$SID.'"', array('User' => null));
|
---|
210 | $this->System->ModuleManager->Modules['Log']->NewRecord('User', 'Logout', $this->User['Login']);
|
---|
211 | $this->Check();
|
---|
212 | return(USER_LOGGED_OUT);
|
---|
213 | }
|
---|
214 |
|
---|
215 | function LoadRoles()
|
---|
216 | {
|
---|
217 | $this->Roles = array();
|
---|
218 | $DbResult = $this->Database->select('UserRole', '*');
|
---|
219 | while($DbRow = $DbResult->fetch_array())
|
---|
220 | $this->Roles[] = $DbRow;
|
---|
221 | }
|
---|
222 |
|
---|
223 | function LoadPermission($Role)
|
---|
224 | {
|
---|
225 | $this->User['Permission'] = array();
|
---|
226 | $DbResult = $this->Database->query('SELECT `UserRolePermission`.*, `PermissionOperation`.`Description` FROM `UserRolePermission` JOIN `PermissionOperation` ON `PermissionOperation`.`Id` = `UserRolePermission`.`Operation` WHERE `UserRolePermission`.`Role` = '.$Role);
|
---|
227 | if($DbResult->num_rows > 0)
|
---|
228 | while($DbRow = $DbResult->fetch_array())
|
---|
229 | $this->User['Permission'][$DbRow['Operation']] = $DbRow;
|
---|
230 | }
|
---|
231 |
|
---|
232 | function PermissionMatrix()
|
---|
233 | {
|
---|
234 | $Result = array();
|
---|
235 | $DbResult = $this->Database->query('SELECT `UserRolePermission`.*, `PermissionOperation`.`Description`, `UserRole`.`Title` FROM `UserRolePermission` LEFT JOIN `PermissionOperation` ON `PermissionOperation`.`Id` = `UserRolePermission`.`Operation` LEFT JOIN `UserRole` ON `UserRole`.`Id` = `UserRolePermission`.`Role`');
|
---|
236 | while($DbRow = $DbResult->fetch_array())
|
---|
237 | {
|
---|
238 | $Value = '';
|
---|
239 | if($DbRow['Read']) $Value .= 'R';
|
---|
240 | if($DbRow['Write']) $Value .= 'W';
|
---|
241 | $Result[$DbRow['Description']][$DbRow['Title']] = $Value;
|
---|
242 | }
|
---|
243 | return($Result);
|
---|
244 | }
|
---|
245 |
|
---|
246 | function CheckGroupPermission($GroupId, $OperationId)
|
---|
247 | {
|
---|
248 | $PermissionExists = false;
|
---|
249 | // First try to check cache group-group relation
|
---|
250 | if(array_key_exists($GroupId, $this->PermissionGroupCache))
|
---|
251 | {
|
---|
252 | $PermissionExists = true;
|
---|
253 | } else
|
---|
254 | {
|
---|
255 | // If no permission combination exists in cache, do new check of database items
|
---|
256 | $DbResult = $this->Database->select('PermissionGroupAssignment', '*', '`Group`="'.$GroupId.'" AND `AssignedGroup` IS NOT NULL');
|
---|
257 | $DbRow = array();
|
---|
258 | while($DbRow[] = $DbResult->fetch_array());
|
---|
259 | $this->PermissionGroupCache[$GroupId] = $DbRow;
|
---|
260 | $PermissionExists = true;
|
---|
261 | }
|
---|
262 | if($PermissionExists)
|
---|
263 | {
|
---|
264 | foreach($this->PermissionGroupCache[$GroupId] as $DbRow)
|
---|
265 | {
|
---|
266 | if($DbRow['AssignedGroup'] != '')
|
---|
267 | if($this->CheckGroupPermission($DbRow['AssignedGroup'], $OperationId) == true) return(true);
|
---|
268 | }
|
---|
269 | }
|
---|
270 |
|
---|
271 | // Check group-operation relation
|
---|
272 | if(array_key_exists($GroupId.','.$OperationId, $this->PermissionGroupCacheOp))
|
---|
273 | {
|
---|
274 | $PermissionExists = true;
|
---|
275 | } else
|
---|
276 | {
|
---|
277 | // If no permission combination exists in cache, do new check of database items
|
---|
278 | $DbResult = $this->Database->select('PermissionGroupAssignment', '*', '`Group`="'.$GroupId.'" AND `AssignedOperation`="'.$OperationId.'"');
|
---|
279 | if($DbResult->num_rows > 0) $this->PermissionGroupCacheOp[$GroupId.','.$OperationId] = true;
|
---|
280 | else $this->PermissionGroupCacheOp[$GroupId.','.$OperationId] = false;
|
---|
281 | $PermissionExists = true;
|
---|
282 | }
|
---|
283 | if($PermissionExists)
|
---|
284 | {
|
---|
285 | return($this->PermissionGroupCacheOp[$GroupId.','.$OperationId]);
|
---|
286 | }
|
---|
287 | return(false);
|
---|
288 | }
|
---|
289 |
|
---|
290 | function CheckPermission($Module, $Operation, $ItemType = '', $ItemIndex = 0)
|
---|
291 | {
|
---|
292 | // First try to check cache
|
---|
293 | if(in_array(array($Module, $Operation, $ItemType, $ItemType), $this->PermissionCache))
|
---|
294 | {
|
---|
295 | $OperationId = array_search(array($Module, $Operation, $ItemType, $ItemIndex), $this->PermissionCache);
|
---|
296 | $PermissionExists = is_numeric($OperationId);
|
---|
297 | } else
|
---|
298 | {
|
---|
299 | // If no permission combination exists in cache, do new check of database items
|
---|
300 | $DbResult = $this->Database->select('PermissionOperation', 'Id', '`Module`="'.$Module.'" AND `Item`="'.$ItemType.'" AND `ItemId`='.$ItemIndex.' AND `Operation`="'.$Operation.'"');
|
---|
301 | if($DbResult->num_rows > 0)
|
---|
302 | {
|
---|
303 | $DbRow = $DbResult->fetch_array();
|
---|
304 | $OperationId = $DbRow['Id'];
|
---|
305 | $this->PermissionCache[$DbRow['Id']] = array($Module, $Operation, $ItemType, $ItemIndex);
|
---|
306 | $PermissionExists = true;
|
---|
307 | } else
|
---|
308 | {
|
---|
309 | $this->PermissionCache[count($this->PermissionCache).'_'] = array($Module, $Operation, $ItemType, $ItemIndex);
|
---|
310 | $PermissionExists = false;
|
---|
311 | }
|
---|
312 | }
|
---|
313 |
|
---|
314 | if($PermissionExists)
|
---|
315 | {
|
---|
316 | if($this->User['Id'] == null) $UserCondition = '(`User` IS NULL)';
|
---|
317 | else $UserCondition = '(`User`="'.$this->User['Id'].'")';
|
---|
318 | // Check user-operation relation
|
---|
319 | $DbResult = $this->Database->select('PermissionUserAssignment', '*', $UserCondition.' AND (`AssignedOperation`="'.$OperationId.'")');
|
---|
320 | if($DbResult->num_rows > 0) return(true);
|
---|
321 |
|
---|
322 | // Check user-group relation
|
---|
323 | $DbResult = $this->Database->select('PermissionUserAssignment', 'AssignedGroup', $UserCondition);
|
---|
324 | while($DbRow = $DbResult->fetch_array())
|
---|
325 | {
|
---|
326 | if($this->CheckGroupPermission($DbRow['AssignedGroup'], $OperationId) == true) return(true);
|
---|
327 | }
|
---|
328 | return(false);
|
---|
329 | } else return(false);
|
---|
330 | }
|
---|
331 |
|
---|
332 | function PasswordRecoveryRequest($Login, $Email)
|
---|
333 | {
|
---|
334 | $DbResult = $this->Database->select('User', 'Login, Name, Id, Email, Password', '`Login`="'.$Login.'" AND `Email`="'.$Email.'"');
|
---|
335 | if($DbResult->num_rows > 0)
|
---|
336 | {
|
---|
337 | $Row = $DbResult->fetch_array();
|
---|
338 | $NewPassword = substr(sha1(strtoupper($Row['Login'])), 0, 7);
|
---|
339 |
|
---|
340 | $ServerURL = 'http://'.$this->System->Config['Web']['Host'].$this->Config['Web']['RootFolder'];
|
---|
341 | $Mail = new Mail();
|
---|
342 | $Mail->Subject = 'Obnova hesla';
|
---|
343 | $Mail->From = $this->Config['Web']['Title'].' <noreplay@zdechov.net>';
|
---|
344 | $Mail->AddTo($Row['Email'], $Row['Name']);
|
---|
345 | $Mail->AddBody('Požádali jste o zaslání nového hesla na serveru <a href="'.$ServerURL.'">'.$ServerURL.'"</a>.<br />\n'.
|
---|
346 | "Pokud jste tak neučinili, měli by jste tento email ignorovat.<br /><br />\n\nVaše nové heslo k účtu ".
|
---|
347 | $Row['Login'].' je: '.$NewPassword."\n<br/>".
|
---|
348 | 'Pro aktivaci tohoto hesla klikněte na <a href="'.$ServerURL.'/?Action=PasswordRecoveryConfirm&User='.
|
---|
349 | $Row['Id'].'&H='.$Row['Password'].'&P='.$NewPassword.'">tento odkaz</a>.'."\n<br />".
|
---|
350 | "Po přihlášení si prosím změňte heslo na nové.\n\n<br><br>Na tento email neodpovídejte.", 'text/html');
|
---|
351 | $Mail->Send();
|
---|
352 |
|
---|
353 | $Output = USER_PASSWORD_RECOVERY_SUCCESS;
|
---|
354 | $this->System->ModuleManager->Modules['Log']->NewRecord('User', 'PasswordRecoveryRequest', 'Login='.$Login.',Email='.$Email);
|
---|
355 | } else $Output = USER_PASSWORD_RECOVERY_FAIL;
|
---|
356 | return($Output);
|
---|
357 | }
|
---|
358 |
|
---|
359 | function PasswordRecoveryConfirm($Id, $Hash, $NewPassword)
|
---|
360 | {
|
---|
361 | $DbResult = $this->Database->select('User', 'Id, Login, Password', 'Id = '.$Id);
|
---|
362 | if($DbResult->num_rows > 0)
|
---|
363 | {
|
---|
364 | $Row = $DbResult->fetch_array();
|
---|
365 | $NewPassword2 = substr(sha1(strtoupper($Row['Login'])), 0, 7);
|
---|
366 | if(($NewPassword == $NewPassword2) and ($Hash == $Row['Password']))
|
---|
367 | {
|
---|
368 | $PasswordHash = new PasswordHash();
|
---|
369 | $Salt = $PasswordHash->GetSalt();
|
---|
370 | $this->Database->update('User', 'Id='.$Row['Id'], array('Password' => $PasswordHash->Hash($NewPassword, $Salt),
|
---|
371 | 'Salt' => $Salt, 'Locked' => 0));
|
---|
372 | $Output = USER_PASSWORD_RECOVERY_CONFIRMED;
|
---|
373 | $this->System->ModuleManager->Modules['Log']->NewRecord('User', 'PasswordRecoveryConfirm', 'Login='.$Row['Login']);
|
---|
374 | } else $Output = PASSWORDS_UNMATCHED;
|
---|
375 | } else $Output = USER_NOT_FOUND;
|
---|
376 | return($Output);
|
---|
377 | }
|
---|
378 | }
|
---|
379 |
|
---|
380 | class ModuleUser extends AppModule
|
---|
381 | {
|
---|
382 | function __construct($System)
|
---|
383 | {
|
---|
384 | parent::__construct($System);
|
---|
385 | $this->Name = 'User';
|
---|
386 | $this->Version = '1.0';
|
---|
387 | $this->Creator = 'Chronos';
|
---|
388 | $this->License = 'GNU/GPLv3';
|
---|
389 | $this->Description = 'User management';
|
---|
390 | $this->Dependencies = array();
|
---|
391 | }
|
---|
392 |
|
---|
393 | function Install()
|
---|
394 | {
|
---|
395 | }
|
---|
396 |
|
---|
397 | function Uninstall()
|
---|
398 | {
|
---|
399 | }
|
---|
400 |
|
---|
401 | function Start()
|
---|
402 | {
|
---|
403 | parent::Start();
|
---|
404 | $this->System->User = new User($this->System);
|
---|
405 | if(isset($_SERVER['REMOTE_ADDR'])) $this->System->User->Check();
|
---|
406 | $this->System->RegisterPage('userlist', 'PageUserList');
|
---|
407 | $this->System->FormManager->RegisterClass('User', array(
|
---|
408 | 'Title' => 'Uživatelé',
|
---|
409 | 'Table' => 'User',
|
---|
410 | 'DefaultSortColumn' => 'Name',
|
---|
411 | 'Items' => array(
|
---|
412 | 'Login' => array('Type' => 'String', 'Caption' => 'Přihlašovací jméno', 'Default' => ''),
|
---|
413 | 'Name' => array('Type' => 'String', 'Caption' => 'Celé jméno', 'Default' => ''),
|
---|
414 | 'Salt' => array('Type' => 'RandomHash', 'Caption' => 'Sůl', 'Default' => ''),
|
---|
415 | 'Password' => array('Type' => 'Password', 'Caption' => 'Heslo', 'Default' => '', 'Method' => 'DoubleSHA1'),
|
---|
416 | 'Email' => array('Type' => 'String', 'Caption' => 'E-mail', 'Default' => ''),
|
---|
417 | 'LastIpAddress' => array('Type' => 'String', 'Caption' => 'Poslední IP adresa', 'Default' => '', 'ReadOnly' => true),
|
---|
418 | 'LastLoginTime' => array('Type' => 'DateTime', 'Caption' => 'Poslední čas přihlášení', 'Default' => '', 'ReadOnly' => true),
|
---|
419 | 'RegistrationTime' => array('Type' => 'DateTime', 'Caption' => 'Čas registrace', 'Default' => ''),
|
---|
420 | 'Locked' => array('Type' => 'Boolean', 'Caption' => 'Uzamčen', 'Default' => ''),
|
---|
421 | 'ICQ' => array('Type' => 'String', 'Caption' => 'ICQ', 'Default' => ''),
|
---|
422 | 'PhoneNumber' => array('Type' => 'String', 'Caption' => 'Telefon', 'Default' => ''),
|
---|
423 | 'UserRel' => array('Type' => 'TUserCustomerRelListUser', 'Caption' => 'Přístup k zákazníkům', 'Default' => ''),
|
---|
424 | 'Permission' => array('Type' => 'TPermissionUserAssignmentListUser', 'Caption' => 'Oprávnění', 'Default' => ''),
|
---|
425 | ),
|
---|
426 | ));
|
---|
427 | $this->System->FormManager->RegisterClass('PermissionUserAssignment', array(
|
---|
428 | 'Title' => 'Oprávnění uživatelů',
|
---|
429 | 'Table' => 'PermissionUserAssignment',
|
---|
430 | 'Items' => array(
|
---|
431 | 'User' => array('Type' => 'TUser', 'Caption' => 'Uživatel', 'Default' => ''),
|
---|
432 | 'AssignedGroup' => array('Type' => 'TPermissionGroup', 'Caption' => 'Přiřazené skupiny', 'Default' => '', 'Null' => true),
|
---|
433 | 'AssignedOperation' => array('Type' => 'TPermissionOperation', 'Caption' => 'Přiřazené operace', 'Default' => '', 'Null' => true),
|
---|
434 | ),
|
---|
435 | ));
|
---|
436 | $this->System->FormManager->RegisterClass('PermissionGroup', array(
|
---|
437 | 'Title' => 'Skupiny oprávnění',
|
---|
438 | 'Table' => 'PermissionGroup',
|
---|
439 | 'Items' => array(
|
---|
440 | 'Description' => array('Type' => 'String', 'Caption' => 'Název', 'Default' => ''),
|
---|
441 | 'AssignedGroup' => array('Type' => 'TPermissionGroupAssignmentListGroup', 'Caption' => 'Přiřazené skupiny a operace', 'Default' => '', 'Null' => true),
|
---|
442 | 'AssignedGroup2' => array('Type' => 'TPermissionGroupAssignmentListAssignedGroup', 'Caption' => 'Použito ve skupinách', 'Default' => '', 'Null' => true),
|
---|
443 | ),
|
---|
444 | ));
|
---|
445 | $this->System->FormManager->RegisterClass('PermissionGroupAssignment', array(
|
---|
446 | 'Title' => 'Přiřazení skupin oprávnění',
|
---|
447 | 'Table' => 'PermissionGroupAssignment',
|
---|
448 | 'Items' => array(
|
---|
449 | 'Group' => array('Type' => 'TPermissionGroup', 'Caption' => 'Skupina', 'Default' => ''),
|
---|
450 | 'AssignedGroup' => array('Type' => 'TPermissionGroup', 'Caption' => 'Přiřazené skupiny', 'Default' => '', 'Null' => true),
|
---|
451 | 'AssignedOperation' => array('Type' => 'TPermissionOperation', 'Caption' => 'Přiřazené operace', 'Default' => '', 'Null' => true),
|
---|
452 | ),
|
---|
453 | ));
|
---|
454 | $this->System->FormManager->RegisterClass('PermissionOperation', array(
|
---|
455 | 'Title' => 'Operace oprávnění',
|
---|
456 | 'Table' => 'PermissionOperation',
|
---|
457 | 'Items' => array(
|
---|
458 | 'Module' => array('Type' => 'String', 'Caption' => 'Modul', 'Default' => ''),
|
---|
459 | 'Operation' => array('Type' => 'String', 'Caption' => 'Operace', 'Default' => ''),
|
---|
460 | 'Item' => array('Type' => 'String', 'Caption' => 'Položka', 'Default' => ''),
|
---|
461 | 'ItemId' => array('Type' => 'Integer', 'Caption' => 'Index položky', 'Default' => ''),
|
---|
462 | 'AssignedGroup' => array('Type' => 'TPermissionGroupAssignmentListOperation', 'Caption' => 'Použito ve skupinách', 'Default' => '', 'Null' => true),
|
---|
463 | ),
|
---|
464 | ));
|
---|
465 |
|
---|
466 | }
|
---|
467 |
|
---|
468 | function Stop()
|
---|
469 | {
|
---|
470 | }
|
---|
471 | }
|
---|