1 | unit UserControlPage;
|
---|
2 |
|
---|
3 | interface
|
---|
4 |
|
---|
5 | uses
|
---|
6 | Classes, SysUtils, FileUtil, WebPage, HTTPServer, HtmlClasses, XmlClasses,
|
---|
7 | WebObjects, ModuleUser, ModuleBase;
|
---|
8 |
|
---|
9 | type
|
---|
10 |
|
---|
11 | { TUserControlPage }
|
---|
12 |
|
---|
13 | TUserControlPage = class(TWebPage)
|
---|
14 | procedure DataModuleProduce(HandlerData: THTTPHandlerData);
|
---|
15 | private
|
---|
16 | procedure HandleLogin(HandlerData: THTTPHandlerData);
|
---|
17 | procedure HandleRegistration(HandlerData: THTTPHandlerData);
|
---|
18 | procedure HandleLogout(HandlerData: THTTPHandlerData);
|
---|
19 | procedure HandleProfile(HandlerData: THTTPHandlerData);
|
---|
20 | public
|
---|
21 | ModuleUser: TModuleUser;
|
---|
22 | ModuleBase: TModuleBase;
|
---|
23 | end;
|
---|
24 |
|
---|
25 | var
|
---|
26 | UserControlPage: TUserControlPage;
|
---|
27 |
|
---|
28 |
|
---|
29 | implementation
|
---|
30 |
|
---|
31 | {$R *.lfm}
|
---|
32 |
|
---|
33 | uses
|
---|
34 | Core, Utils, User, WebSession;
|
---|
35 |
|
---|
36 | { TUserControlPage }
|
---|
37 |
|
---|
38 | procedure TUserControlPage.DataModuleProduce(HandlerData: THTTPHandlerData);
|
---|
39 | var
|
---|
40 | PageName: string;
|
---|
41 | NewForm: TQueryForm;
|
---|
42 | NewGroup: TQueryFormGroup;
|
---|
43 | NewItem: TQueryFormItem;
|
---|
44 | begin
|
---|
45 | with TWebSession(HandlerData) do begin
|
---|
46 | if Request.Path.Count > 1 then PageName := Request.Path[1]
|
---|
47 | else PageName := '';
|
---|
48 | with HtmlDocument.Body do begin
|
---|
49 | ModuleUser.LoadUserInfo;
|
---|
50 | if PageName = '' then PageName := 'prihlaseni';
|
---|
51 | if PageName = 'prihlaseni' then HandleLogin(HandlerData)
|
---|
52 | else if PageName = 'registrace' then HandleRegistration(HandlerData)
|
---|
53 | else if PageName = 'odhlaseni' then HandleLogout(HandlerData)
|
---|
54 | else if PageName = 'profil' then HandleProfile(HandlerData);
|
---|
55 | end;
|
---|
56 | GeneratePage(Self);
|
---|
57 | end;
|
---|
58 | end;
|
---|
59 |
|
---|
60 | procedure TUserControlPage.HandleLogin(HandlerData: THTTPHandlerData);
|
---|
61 | var
|
---|
62 | Form: TQueryForm;
|
---|
63 | UserId: Integer;
|
---|
64 | begin
|
---|
65 | with TWebSession(HandlerData), Core.Core, HtmlDocument.Body do begin
|
---|
66 | Form := TQueryForm.Create;
|
---|
67 | with Form do begin
|
---|
68 | Title := 'Přihlášení';
|
---|
69 | ClassId := 'WideTable';
|
---|
70 | //Action.AsString := '/dev/zdechovnet/trunk/serverinfoo';
|
---|
71 | with AddNewGroup do begin
|
---|
72 | Title := '';
|
---|
73 | with AddNewItem do begin
|
---|
74 | Caption := 'Jméno';
|
---|
75 | Name := 'UserName';
|
---|
76 | Hint := 'Zadejte vaše přihlašovací jméno';
|
---|
77 | Required := True;
|
---|
78 | end;
|
---|
79 | with AddNewItem do begin
|
---|
80 | Caption := 'Heslo';
|
---|
81 | Name := 'Password';
|
---|
82 | Hint := 'Zadejte vaše heslo';
|
---|
83 | Required := True;
|
---|
84 | ItemType := fitPassword;
|
---|
85 | end;
|
---|
86 | end;
|
---|
87 | AddNewAction('Přihlásit', 'Login');
|
---|
88 | end;
|
---|
89 | if HandlerData.Request.Post.ContainsKey('Login') then begin
|
---|
90 | Form.Load(HandlerData.Request.Post);
|
---|
91 | with SubItems.AddString do
|
---|
92 | Text := 'Přihlášení uživatele: ' + TQueryFormGroup(Form.Groups[0]).Rows.FindByName('UserName').Value.Value;
|
---|
93 | UserId := ModuleUser.User.GetIdByNamePassword(TQueryFormGroup(Form.Groups[0]).Rows.FindByName('UserName').Value.Value,
|
---|
94 | TQueryFormGroup(Form.Groups[0]).Rows.FindByName('Password').Value.Value);
|
---|
95 | if UserId = -1 then begin
|
---|
96 | with SubItems.AddString do
|
---|
97 | Text := '<br/>Chybné jméno nebo heslo';
|
---|
98 | end else ModuleUser.UserOnline.Login(UserId);
|
---|
99 | Form.Free;
|
---|
100 | end else
|
---|
101 | SubItems.Add(Form);
|
---|
102 | end;
|
---|
103 | end;
|
---|
104 |
|
---|
105 | procedure TUserControlPage.HandleRegistration(HandlerData: THTTPHandlerData);
|
---|
106 | var
|
---|
107 | Form: TQueryForm;
|
---|
108 | UserId: Integer;
|
---|
109 | begin
|
---|
110 | with TWebSession(HandlerData), Core.Core, HtmlDocument.Body do begin
|
---|
111 | Form := TQueryForm.Create;
|
---|
112 | with Form do begin
|
---|
113 | Title := 'Registrace nového účtu';
|
---|
114 | ClassId := 'WideTable';
|
---|
115 | with AddNewGroup do begin
|
---|
116 | Title := '';
|
---|
117 | with AddNewItem do begin
|
---|
118 | Caption := 'Jméno';
|
---|
119 | Name := 'UserName';
|
---|
120 | Hint := 'Zadejte vaše přihlašovací jméno';
|
---|
121 | Required := True;
|
---|
122 | end;
|
---|
123 | with AddNewItem do begin
|
---|
124 | Caption := 'Email';
|
---|
125 | Name := 'Email';
|
---|
126 | Hint := 'Zadejte vaši elektronickou poštovní schránku';
|
---|
127 | Required := True;
|
---|
128 | end;
|
---|
129 | with AddNewItem do begin
|
---|
130 | Caption := 'Heslo';
|
---|
131 | Name := 'Password';
|
---|
132 | Hint := 'Zadejte vaše heslo';
|
---|
133 | Required := True;
|
---|
134 | ItemType := fitPassword;
|
---|
135 | end;
|
---|
136 | with AddNewItem do begin
|
---|
137 | Caption := 'Ověření hesla';
|
---|
138 | Name := 'PasswordConfirm';
|
---|
139 | Hint := 'Zadejte znovu vaše heslo pro ověření';
|
---|
140 | Required := True;
|
---|
141 | ItemType := fitPassword;
|
---|
142 | end;
|
---|
143 | end;
|
---|
144 | AddNewAction('Registrovat', 'Register');
|
---|
145 | end;
|
---|
146 | if HandlerData.Request.Post.ContainsKey('Register') then
|
---|
147 | with HandlerData.Request do begin
|
---|
148 | Form.Load(HandlerData.Request.Post);
|
---|
149 | with SubItems.AddString do
|
---|
150 | Text := 'Registrace uživatele: ' + TQueryFormGroup(Form.Groups[0]).Rows.FindByName('UserName').Value.Value;
|
---|
151 | ModuleUser.User.Add(TQueryFormGroup(Form.Groups[0]).Rows.FindByName('UserName').Value.Value,
|
---|
152 | TQueryFormGroup(Form.Groups[0]).Rows.FindByName('Password').Value.Value,
|
---|
153 | TQueryFormGroup(Form.Groups[0]).Rows.FindByName('Email').Value.Value);
|
---|
154 | UserId := ModuleUser.User.GetIdByNamePassword(TQueryFormGroup(Form.Groups[0]).Rows.FindByName('UserName').Value.Value,
|
---|
155 | TQueryFormGroup(Form.Groups[0]).Rows.FindByName('Password').Value.Value);
|
---|
156 | if UserId <> -1 then ModuleUser.UserOnline.Login(UserId);
|
---|
157 | Form.Free;
|
---|
158 | end else SubItems.Add(Form);
|
---|
159 | end;
|
---|
160 | end;
|
---|
161 |
|
---|
162 | procedure TUserControlPage.HandleLogout(HandlerData: THTTPHandlerData);
|
---|
163 | begin
|
---|
164 | with TWebSession(HandlerData), Core.Core, HtmlDocument.Body do begin
|
---|
165 | ModuleUser.UserOnline.Logout;
|
---|
166 | with SubItems.AddString do
|
---|
167 | Text := 'Uživatel odhlášen';
|
---|
168 | end;
|
---|
169 | end;
|
---|
170 |
|
---|
171 | procedure TUserControlPage.HandleProfile(HandlerData: THTTPHandlerData);
|
---|
172 | var
|
---|
173 | Form: TQueryForm;
|
---|
174 | begin
|
---|
175 | with TWebSession(HandlerData), HtmlDocument.Body do begin
|
---|
176 | Form := TQueryForm.Create;
|
---|
177 | with Form do begin
|
---|
178 | Title := 'Nastavení profilu';
|
---|
179 | ClassId := 'WideTable';
|
---|
180 | with AddNewGroup do begin
|
---|
181 | Title := '';
|
---|
182 | with AddNewItem do begin
|
---|
183 | Caption := 'Jméno';
|
---|
184 | Name := 'UserName';
|
---|
185 | Hint := 'Zadejte vaše přihlašovací jméno';
|
---|
186 | Required := True;
|
---|
187 | Value.Value := ModuleUser.User.Name;
|
---|
188 | end;
|
---|
189 | with AddNewItem do begin
|
---|
190 | Caption := 'Heslo';
|
---|
191 | Name := 'Password';
|
---|
192 | Hint := 'Zadejte vaše heslo';
|
---|
193 | Required := True;
|
---|
194 | ItemType := fitPassword;
|
---|
195 | end;
|
---|
196 | with AddNewItem do begin
|
---|
197 | Caption := 'Email';
|
---|
198 | Name := 'Email';
|
---|
199 | Hint := 'Zadejte vaši emailovou adresu';
|
---|
200 | Required := True;
|
---|
201 | ItemType := fitText;
|
---|
202 | Value.Value := ModuleUser.User.Email;
|
---|
203 | end;
|
---|
204 | with AddNewItem do begin
|
---|
205 | Caption := 'Celé jméno';
|
---|
206 | Name := 'FullName';
|
---|
207 | Hint := 'Zadejte vaše celé jméno';
|
---|
208 | Required := False;
|
---|
209 | ItemType := fitText;
|
---|
210 | Value.Value := ModuleUser.User.FullName;
|
---|
211 | end;
|
---|
212 | end;
|
---|
213 | AddNewAction('Uložit', 'Save');
|
---|
214 | end;
|
---|
215 | if HandlerData.Request.Post.ContainsKey('Save') then
|
---|
216 | with HandlerData.Request do begin
|
---|
217 | Form.Load(HandlerData.Request.Post);
|
---|
218 | with SubItems.AddString do
|
---|
219 | Text := 'Profil uživatele: ' + TQueryFormGroup(Form.Groups[0]).Rows.FindByName('UserName').Value.Value + ' uložen';
|
---|
220 | ModuleUser.User.Name := TQueryFormGroup(Form.Groups[0]).Rows.FindByName('UserName').Value.Value;
|
---|
221 | ModuleUser.User.FullName := TQueryFormGroup(Form.Groups[0]).Rows.FindByName('FullName').Value.Value;
|
---|
222 | ModuleUser.User.Email := TQueryFormGroup(Form.Groups[0]).Rows.FindByName('Email').Value.Value;
|
---|
223 | ModuleUser.User.Save;
|
---|
224 | Form.Free;
|
---|
225 | end else SubItems.Add(Form);
|
---|
226 | end;
|
---|
227 | end;
|
---|
228 |
|
---|
229 | end.
|
---|
230 |
|
---|