1 | unit ModuleUser;
|
---|
2 |
|
---|
3 | interface
|
---|
4 |
|
---|
5 | uses
|
---|
6 | Classes, SysUtils, ModularSystem, User, ModuleBase, WebPage;
|
---|
7 |
|
---|
8 | type
|
---|
9 | { TModuleUser }
|
---|
10 |
|
---|
11 | TModuleUser = class(TModule)
|
---|
12 | private
|
---|
13 | UserControlPage: TWebPage; //TUserControlPage;
|
---|
14 | public
|
---|
15 | User: TWebUser;
|
---|
16 | UserOnline: TWebOnlineUser;
|
---|
17 | ModuleBase: TModuleBase;
|
---|
18 | constructor Create(Owner: TComponent); override;
|
---|
19 | destructor Destroy; override;
|
---|
20 | procedure Start; override;
|
---|
21 | procedure Stop; override;
|
---|
22 | procedure Install; override;
|
---|
23 | procedure Uninstall; override;
|
---|
24 | procedure Upgrade; override;
|
---|
25 | procedure LoadUserInfo;
|
---|
26 | end;
|
---|
27 |
|
---|
28 |
|
---|
29 | implementation
|
---|
30 |
|
---|
31 | uses
|
---|
32 | Core, SqlDatabase, UserControlPage;
|
---|
33 |
|
---|
34 | { TModuleUser }
|
---|
35 |
|
---|
36 | constructor TModuleUser.Create(Owner: TComponent);
|
---|
37 | begin
|
---|
38 | inherited;
|
---|
39 | Identification := 'User';
|
---|
40 | Title := 'User management';
|
---|
41 | Version := '1.0';
|
---|
42 | License := 'GNU/LGPL v3';
|
---|
43 | Author := 'Chronosoft';
|
---|
44 | Dependencies.Add('Base');
|
---|
45 | end;
|
---|
46 |
|
---|
47 | destructor TModuleUser.Destroy;
|
---|
48 | begin
|
---|
49 | inherited;
|
---|
50 | end;
|
---|
51 |
|
---|
52 | procedure TModuleUser.Start;
|
---|
53 | begin
|
---|
54 | BeforeStart;
|
---|
55 | ModuleBase := TModuleBase(Manager.FindModuleByName('Base'));
|
---|
56 | UserControlPage := TUserControlPage.Create(nil);
|
---|
57 | ModuleBase.Pages.RegisterPage(UserControlPage, 'uzivatel');
|
---|
58 | //RegisterPage(TUserControlPage, UserControlPage, '');
|
---|
59 | User := TWebUser.Create;
|
---|
60 | User.Database := ModuleBase.Session.Database;
|
---|
61 | User.HandlerData := ModuleBase.Session;
|
---|
62 | UserOnline := TWebOnlineUser.Create;
|
---|
63 | UserOnline.Database := ModuleBase.Session.Database;
|
---|
64 | UserOnline.HandlerData := ModuleBase.Session;
|
---|
65 | AfterStart;
|
---|
66 | end;
|
---|
67 |
|
---|
68 | procedure TModuleUser.Stop;
|
---|
69 | begin
|
---|
70 | BeforeStop;
|
---|
71 | FreeAndNil(User);
|
---|
72 | FreeAndNil(UserOnline);
|
---|
73 | ModuleBase.Pages.UnregisterPage(UserControlPage);
|
---|
74 | FreeAndNil(UserControlPage);
|
---|
75 | ModuleBase := nil;
|
---|
76 | AfterStop;
|
---|
77 | end;
|
---|
78 |
|
---|
79 | procedure TModuleUser.Install;
|
---|
80 | var
|
---|
81 | DbRows: TDbRows;
|
---|
82 | begin
|
---|
83 | try
|
---|
84 | DbRows := TDbRows.Create;
|
---|
85 |
|
---|
86 | Core.Core.CommonDatabase.Query(DbRows,
|
---|
87 | 'CREATE TABLE IF NOT EXISTS `User` (' +
|
---|
88 | ' `Id` int(11) NOT NULL AUTO_INCREMENT,' +
|
---|
89 | ' `Name` varchar(255) NOT NULL,' +
|
---|
90 | ' `FullName` varchar(255) NOT NULL,' +
|
---|
91 | ' `Password` varchar(255) NOT NULL,' +
|
---|
92 | ' `Salt` varchar(255) NOT NULL,' +
|
---|
93 | ' `Email` varchar(255) NOT NULL,' +
|
---|
94 | ' `RegistrationTime` datetime NOT NULL,' +
|
---|
95 | ' PRIMARY KEY (`Id`)' +
|
---|
96 | ') ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;');
|
---|
97 |
|
---|
98 | Core.Core.CommonDatabase.Query(DbRows,
|
---|
99 | 'CREATE TABLE IF NOT EXISTS `UserOnline` (' +
|
---|
100 | ' `Id` int(11) NOT NULL AUTO_INCREMENT,' +
|
---|
101 | ' `User` int(11) NOT NULL DEFAULT ''0'',' +
|
---|
102 | ' `ActivityTime` datetime NOT NULL DEFAULT ''0000-00-00 00:00:00'',' +
|
---|
103 | ' `LoginTime` datetime NOT NULL DEFAULT ''0000-00-00 00:00:00'',' +
|
---|
104 | ' `SessionId` varchar(255) COLLATE utf8_czech_ci NOT NULL DEFAULT '''',' +
|
---|
105 | ' `IpAddress` varchar(16) COLLATE utf8_czech_ci NOT NULL DEFAULT '''',' +
|
---|
106 | ' `HostName` varchar(255) COLLATE utf8_czech_ci NOT NULL DEFAULT '''',' +
|
---|
107 | ' `ScriptName` varchar(255) COLLATE utf8_czech_ci NOT NULL,' +
|
---|
108 | ' PRIMARY KEY (`Id`),' +
|
---|
109 | ' KEY `User` (`User`)' +
|
---|
110 | ') ENGINE=MEMORY DEFAULT CHARSET=utf8 COLLATE=utf8_czech_ci AUTO_INCREMENT=1 ;');
|
---|
111 |
|
---|
112 | Core.Core.CommonDatabase.Query(DbRows,
|
---|
113 | 'CREATE TABLE IF NOT EXISTS `PermissionGroup` (' +
|
---|
114 | ' `Id` int(11) NOT NULL AUTO_INCREMENT,' +
|
---|
115 | ' `Description` varchar(255) COLLATE utf8_czech_ci NOT NULL DEFAULT "",' +
|
---|
116 | ' PRIMARY KEY (`Id`)' +
|
---|
117 | ') ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_czech_ci AUTO_INCREMENT=1 ;');
|
---|
118 |
|
---|
119 | Core.Core.CommonDatabase.Query(DbRows,
|
---|
120 | 'CREATE TABLE IF NOT EXISTS `PermissionGroupAssignment` (' +
|
---|
121 | ' `Id` int(11) NOT NULL AUTO_INCREMENT,' +
|
---|
122 | ' `Group` int(11) NOT NULL DEFAULT "0",' +
|
---|
123 | ' `AssignedGroup` int(11) DEFAULT NULL,' +
|
---|
124 | ' `AssignedOperation` int(11) DEFAULT NULL,' +
|
---|
125 | ' PRIMARY KEY (`Id`),' +
|
---|
126 | ' KEY `Group` (`Group`),' +
|
---|
127 | ' KEY `AssignedGroup` (`AssignedGroup`),' +
|
---|
128 | ' KEY `AssignedOperation` (`AssignedOperation`)' +
|
---|
129 | ') ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_czech_ci AUTO_INCREMENT=1 ;');
|
---|
130 |
|
---|
131 | Core.Core.CommonDatabase.Query(DbRows,
|
---|
132 | 'CREATE TABLE IF NOT EXISTS `PermissionOperation` (' +
|
---|
133 | ' `Id` int(11) NOT NULL AUTO_INCREMENT,' +
|
---|
134 | ' `Module` varchar(64) COLLATE utf8_czech_ci NOT NULL DEFAULT "",' +
|
---|
135 | ' `Operation` varchar(128) COLLATE utf8_czech_ci NOT NULL DEFAULT "",' +
|
---|
136 | ' `Item` varchar(64) COLLATE utf8_czech_ci NOT NULL DEFAULT "",' +
|
---|
137 | ' `ItemId` int(11) NOT NULL DEFAULT "0",' +
|
---|
138 | ' PRIMARY KEY (`Id`),' +
|
---|
139 | ' KEY `Module` (`Module`),' +
|
---|
140 | ' KEY `Operation` (`Operation`),' +
|
---|
141 | ' KEY `Item` (`Item`),' +
|
---|
142 | ' KEY `ItemId` (`ItemId`)' +
|
---|
143 | ') ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_czech_ci AUTO_INCREMENT=1 ;');
|
---|
144 |
|
---|
145 | Core.Core.CommonDatabase.Query(DbRows,
|
---|
146 | ' CREATE TABLE IF NOT EXISTS `PermissionUserAssignment` (' +
|
---|
147 | ' `Id` int(11) NOT NULL AUTO_INCREMENT,' +
|
---|
148 | ' `User` int(11) NOT NULL DEFAULT "0",' +
|
---|
149 | ' `AssignedGroup` int(11) DEFAULT NULL,' +
|
---|
150 | ' `AssignedOperation` int(11) DEFAULT NULL,' +
|
---|
151 | ' PRIMARY KEY (`Id`),' +
|
---|
152 | ' KEY `User` (`User`),' +
|
---|
153 | ' KEY `AssignedGroup` (`AssignedGroup`),' +
|
---|
154 | ' KEY `AssignedOperation` (`AssignedOperation`)' +
|
---|
155 | ') ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_czech_ci AUTO_INCREMENT=1 ;');
|
---|
156 |
|
---|
157 | Core.Core.CommonDatabase.Query(DbRows,
|
---|
158 | 'ALTER TABLE `PermissionGroupAssignment`' +
|
---|
159 | ' ADD CONSTRAINT `PermissionGroupAssignment_ibfk_1` FOREIGN KEY (`Group`) REFERENCES `permissiongroup` (`Id`),' +
|
---|
160 | ' ADD CONSTRAINT `PermissionGroupAssignment_ibfk_2` FOREIGN KEY (`AssignedGroup`) REFERENCES `permissiongroup` (`Id`),' +
|
---|
161 | ' ADD CONSTRAINT `PermissionGroupAssignment_ibfk_3` FOREIGN KEY (`AssignedOperation`) REFERENCES `permissionoperation` (`Id`);');
|
---|
162 |
|
---|
163 | Core.Core.CommonDatabase.Query(DbRows,
|
---|
164 | 'ALTER TABLE `PermissionUserAssignment`' +
|
---|
165 | ' ADD CONSTRAINT `PermissionUserAssignment_ibfk_1` FOREIGN KEY (`User`) REFERENCES `user` (`Id`),' +
|
---|
166 | ' ADD CONSTRAINT `PermissionUserAssignment_ibfk_2` FOREIGN KEY (`AssignedGroup`) REFERENCES `permissiongroup` (`Id`),' +
|
---|
167 | ' ADD CONSTRAINT `PermissionUserAssignment_ibfk_3` FOREIGN KEY (`AssignedOperation`) REFERENCES `permissionoperation` (`Id`);');
|
---|
168 | finally
|
---|
169 | DbRows.Free;
|
---|
170 | end;
|
---|
171 | inherited;
|
---|
172 | end;
|
---|
173 |
|
---|
174 | procedure TModuleUser.Uninstall;
|
---|
175 | var
|
---|
176 | DbRows: TDbRows;
|
---|
177 | begin
|
---|
178 | inherited;
|
---|
179 | try
|
---|
180 | DbRows := TDbRows.Create;
|
---|
181 |
|
---|
182 | Core.Core.CommonDatabase.Query(DbRows, 'DROP TABLE IF EXISTS `PermissionUserAssignment`');
|
---|
183 | Core.Core.CommonDatabase.Query(DbRows, 'DROP TABLE IF EXISTS `PermissionGroupAssignment`');
|
---|
184 | Core.Core.CommonDatabase.Query(DbRows, 'DROP TABLE IF EXISTS `PermissionGroup`');
|
---|
185 | Core.Core.CommonDatabase.Query(DbRows, 'DROP TABLE IF EXISTS `PermissionOperation`');
|
---|
186 | Core.Core.CommonDatabase.Query(DbRows, 'DROP TABLE IF EXISTS `User`');
|
---|
187 | Core.Core.CommonDatabase.Query(DbRows, 'DROP TABLE IF EXISTS `UserOnline`');
|
---|
188 | finally
|
---|
189 | DbRows.Free;
|
---|
190 | end;
|
---|
191 | end;
|
---|
192 |
|
---|
193 | procedure TModuleUser.Upgrade;
|
---|
194 | begin
|
---|
195 | inherited;
|
---|
196 | end;
|
---|
197 |
|
---|
198 | procedure TModuleUser.LoadUserInfo;
|
---|
199 | begin
|
---|
200 | User.HandlerData := ModuleBase.HandlerData;
|
---|
201 | UserOnline.HandlerData := ModuleBase.HandlerData;
|
---|
202 | UserOnline.Update;
|
---|
203 | User.Id := UserOnline.User;
|
---|
204 | User.Load;
|
---|
205 | end;
|
---|
206 |
|
---|
207 | end.
|
---|
208 |
|
---|