Changeset 890 for trunk/Modules/User
- Timestamp:
- Dec 29, 2020, 11:11:12 PM (4 years ago)
- Location:
- trunk/Modules/User
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Modules/User/User.php
r887 r890 25 25 function DoInstall(): void 26 26 { 27 $this->Database->query("CREATE TABLE IF NOT EXISTS `User` ( 28 `Id` int(11) NOT NULL AUTO_INCREMENT, 29 `Login` varchar(64) NOT NULL, 30 `Name` varchar(128) NOT NULL, 31 `Password` varchar(255) NOT NULL, 32 `Salt` varchar(255) NOT NULL, 33 `Email` varchar(128) NOT NULL DEFAULT '', 34 `LastIpAddress` varchar(16) NOT NULL DEFAULT '', 35 `LastLoginTime` datetime NOT NULL DEFAULT '0000-00-00 00:00:00', 36 `RegistrationTime` datetime NOT NULL DEFAULT '0000-00-00 00:00:00', 37 `Locked` tinyint(1) NOT NULL DEFAULT '0', 38 `InitPassword` varchar(255) NOT NULL, 39 PRIMARY KEY (`Id`), 40 UNIQUE KEY `Name` (`Login`), 41 UNIQUE KEY `Nick` (`Name`) 42 ) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;"); 43 $this->Database->query("CREATE TABLE IF NOT EXISTS `UserOnline` ( 44 `Id` int(11) NOT NULL AUTO_INCREMENT, 45 `User` int(11) DEFAULT NULL COMMENT 'User.Id', 46 `ActivityTime` datetime NOT NULL DEFAULT '0000-00-00 00:00:00', 47 `LoginTime` datetime NOT NULL DEFAULT '0000-00-00 00:00:00', 48 `SessionId` varchar(255) NOT NULL DEFAULT '', 49 `IpAddress` varchar(16) NOT NULL DEFAULT '', 50 `HostName` varchar(255) NOT NULL DEFAULT '', 51 `ScriptName` varchar(255) NOT NULL, 52 `StayLogged` INT NOT NULL, 53 `StayLoggedHash` VARCHAR(40) NOT NULL, 54 PRIMARY KEY (`Id`), 55 KEY `User` (`User`) 56 ) ENGINE=MEMORY DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;"); 57 $this->Database->query("CREATE TABLE IF NOT EXISTS `PermissionGroup` ( 58 `Id` int(11) NOT NULL AUTO_INCREMENT, 59 `Description` varchar(255) NOT NULL DEFAULT '', 60 PRIMARY KEY (`Id`) 61 ) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;"); 62 63 $this->Database->query("CREATE TABLE IF NOT EXISTS `PermissionGroupAssignment` ( 64 `Id` int(11) NOT NULL AUTO_INCREMENT, 65 `Group` int(11) NOT NULL DEFAULT '0', 66 `AssignedGroup` int(11) DEFAULT NULL, 67 `AssignedOperation` int(11) DEFAULT NULL, 68 PRIMARY KEY (`Id`), 69 KEY `Group` (`Group`), 70 KEY `AssignedGroup` (`AssignedGroup`), 71 KEY `AssignedOperation` (`AssignedOperation`) 72 ) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;"); 73 74 $this->Database->query("CREATE TABLE IF NOT EXISTS `PermissionOperation` ( 75 `Id` int(11) NOT NULL AUTO_INCREMENT, 76 `Module` int(11) NOT NULL, 77 `Operation` varchar(128) NOT NULL DEFAULT '', 78 `Item` varchar(64) NOT NULL DEFAULT '', 79 `ItemId` int(11) NOT NULL DEFAULT '0', 80 PRIMARY KEY (`Id`), 81 KEY `Module` (`Module`), 82 KEY `Operation` (`Operation`), 83 KEY `Item` (`Item`), 84 KEY `ItemId` (`ItemId`) 85 ) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;"); 86 87 $this->Database->query("CREATE TABLE IF NOT EXISTS `PermissionUserAssignment` ( 88 `Id` int(11) NOT NULL AUTO_INCREMENT, 89 `User` int(11) DEFAULT NULL, 90 `AssignedGroup` int(11) DEFAULT NULL, 91 `AssignedOperation` int(11) DEFAULT NULL, 92 PRIMARY KEY (`Id`), 93 KEY `User` (`User`), 94 KEY `AssignedGroup` (`AssignedGroup`), 95 KEY `AssignedOperation` (`AssignedOperation`) 96 ) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;"); 97 98 $this->Database->query("ALTER TABLE `PermissionGroupAssignment` 99 ADD CONSTRAINT `PermissionGroupAssignment_ibfk_1` FOREIGN KEY (`Group`) REFERENCES `PermissionGroup` (`Id`), 100 ADD CONSTRAINT `PermissionGroupAssignment_ibfk_2` FOREIGN KEY (`AssignedGroup`) REFERENCES `PermissionGroup` (`Id`), 101 ADD CONSTRAINT `PermissionGroupAssignment_ibfk_3` FOREIGN KEY (`AssignedOperation`) REFERENCES `PermissionOperation` (`Id`);"); 102 103 $this->Database->query("ALTER TABLE `PermissionOperation` 104 ADD CONSTRAINT `PermissionOperation_ibfk_1` FOREIGN KEY (`Module`) REFERENCES `Module` (`Id`);"); 105 106 $this->Database->query("ALTER TABLE `PermissionUserAssignment` 107 ADD CONSTRAINT `PermissionUserAssignment_ibfk_2` FOREIGN KEY (`AssignedGroup`) REFERENCES `PermissionGroup` (`Id`), 108 ADD CONSTRAINT `PermissionUserAssignment_ibfk_3` FOREIGN KEY (`AssignedOperation`) REFERENCES `PermissionOperation` (`Id`), 109 ADD CONSTRAINT `PermissionUserAssignment_ibfk_4` FOREIGN KEY (`User`) REFERENCES `User` (`Id`);"); 27 $this->InstallModel(User::GetDesc()); 28 $this->InstallModel(UserOnline::GetDesc()); 29 $this->InstallModel(PermissionGroup::GetDesc()); 30 $this->InstallModel(PermissionOperation::GetDesc()); 31 $this->InstallModel(PermissionGroupAssignment::GetDesc()); 32 $this->InstallModel(PermissionUserAssignment::GetDesc()); 110 33 } 111 34 112 35 function DoUninstall(): void 113 36 { 114 $this->Database->query('DROP TABLE `PermissionUserAssignment`'); 115 $this->Database->query('DROP TABLE `PermissionGroupAssignment`'); 116 $this->Database->query('DROP TABLE `PermissionGroup`'); 117 $this->Database->query('DROP TABLE `PermissionOperation`'); 118 $this->Database->query('DROP TABLE `UserOnline`'); 119 $this->Database->query('DROP TABLE `User`'); 120 } 121 122 function DoUpgrade(): void 123 { 124 /* 125 126 if ($this->InstalledVersion == '1.0') { 127 $this->System->Database->Query('SELECT * FROM User WHERE Id=1'); 128 $this->InstalledVersion = '1.1'; 129 } 130 */ 37 $this->UninstallModel(PermissionUserAssignment::GetDesc()); 38 $this->UninstallModel(PermissionGroupAssignment::GetDesc()); 39 $this->UninstallModel(PermissionOperation::GetDesc()); 40 $this->UninstallModel(PermissionGroup::GetDesc()); 41 $this->UninstallModel(UserOnline::GetDesc()); 42 $this->UninstallModel(User::GetDesc()); 131 43 } 132 44 -
trunk/Modules/User/UserModel.php
r887 r890 65 65 } 66 66 67 static function GetDesc(): ModelDesc 68 { 69 $Desc = new ModelDesc('User'); 70 $Column = $Desc->AddString('Login'); 71 $Column->Unique = true; 72 $Column = $Desc->AddString('Name'); 73 $Column->Unique = true; 74 $Desc->AddString('Password'); 75 $Desc->AddString('Salt'); 76 $Desc->AddString('Email'); 77 $Desc->AddString('LastIpAddress'); 78 $Desc->AddString('LastLoginTime'); 79 $Desc->AddDateTime('RegistrationTime'); 80 $Desc->AddBoolean('Locked'); 81 $Desc->AddString('InitPassword'); 82 return $Desc; 83 } 84 67 85 function Check(): void 68 86 { … … 435 453 } 436 454 } 455 456 class UserOnline extends Model 457 { 458 static function GetDesc(): ModelDesc 459 { 460 $Desc = new ModelDesc('UserOnline'); 461 $Desc->Memory = true; 462 $Column = $Desc->AddReference('User', 'User'); 463 $Column->Nullable = true; 464 $Desc->AddDateTime('ActivityTime'); 465 $Desc->AddDateTime('LoginTime'); 466 $Desc->AddString('SessionId'); 467 $Desc->AddString('IpAddress'); 468 $Desc->AddString('HostName'); 469 $Desc->AddString('ScriptName'); 470 $Desc->AddBoolean('StayLogged'); 471 $Desc->AddString('StayLoggedHash'); 472 return $Desc; 473 } 474 } 475 476 class PermissionGroup extends Model 477 { 478 static function GetDesc(): ModelDesc 479 { 480 $Desc = new ModelDesc('PermissionGroup'); 481 $Desc->AddString('Description'); 482 return $Desc; 483 } 484 } 485 486 class PermissionGroupAssignment extends Model 487 { 488 static function GetDesc(): ModelDesc 489 { 490 $Desc = new ModelDesc('PermissionGroupAssignment'); 491 $Desc->AddReference('Group', 'PermissionGroup'); 492 $Column = $Desc->AddReference('AssignedGroup', 'PermissionGroup'); 493 $Column->Nullable = true; 494 $Column = $Desc->AddReference('AssignedOperation', 'PermissionOperation'); 495 $Column->Nullable = true; 496 return $Desc; 497 } 498 } 499 500 class PermissionOperation extends Model 501 { 502 static function GetDesc(): ModelDesc 503 { 504 $Desc = new ModelDesc('PermissionOperation'); 505 $Desc->AddReference('Module', 'Module'); 506 $Desc->AddString('Operation'); 507 $Desc->AddString('Item'); 508 $Desc->AddInteger('ItemId'); 509 $Desc->Indices = array('Operation', 'Item', 'ItemId'); 510 return $Desc; 511 } 512 } 513 514 class PermissionUserAssignment extends Model 515 { 516 static function GetDesc(): ModelDesc 517 { 518 $Desc = new ModelDesc('PermissionUserAssignment'); 519 $Desc->AddReference('User', 'User'); 520 $Column = $Desc->AddReference('AssignedGroup', 'PermissionGroup'); 521 $Column->Nullable = true; 522 $Column = $Desc->AddReference('AssignedOperation', 'PermissionOperation'); 523 $Column->Nullable = true; 524 return $Desc; 525 } 526 }
Note:
See TracChangeset
for help on using the changeset viewer.