2014-04-01 00:02:31 +02:00
|
|
|
unit AppControllerU;
|
|
|
|
|
|
|
|
interface
|
|
|
|
|
2017-06-22 16:18:58 +02:00
|
|
|
uses
|
|
|
|
MVCFramework,
|
2017-01-18 21:53:53 +01:00
|
|
|
MVCFramework.Commons,
|
2014-04-01 00:02:31 +02:00
|
|
|
MVCFramework.Logger,
|
|
|
|
Web.HTTPApp;
|
|
|
|
|
|
|
|
type
|
|
|
|
|
|
|
|
[MVCPath('/')]
|
|
|
|
TApp1MainController = class(TMVCController)
|
|
|
|
public
|
2014-04-01 19:36:05 +02:00
|
|
|
[MVCPath('/name')]
|
2014-04-01 00:02:31 +02:00
|
|
|
[MVCHTTPMethod([httpGET])]
|
2016-06-28 13:42:14 +02:00
|
|
|
procedure Index;
|
2014-04-01 00:02:31 +02:00
|
|
|
|
|
|
|
[MVCPath('/login/($username)')]
|
|
|
|
[MVCHTTPMethod([httpGET])]
|
2017-06-22 16:18:58 +02:00
|
|
|
procedure DoLogin(username: string);
|
2014-04-01 00:02:31 +02:00
|
|
|
|
|
|
|
[MVCPath('/logout')]
|
|
|
|
[MVCHTTPMethod([httpGET])]
|
2016-06-28 13:42:14 +02:00
|
|
|
procedure DoLogout;
|
2014-04-01 00:02:31 +02:00
|
|
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
implementation
|
|
|
|
|
|
|
|
{ TApp1MainController }
|
|
|
|
|
2017-06-22 16:18:58 +02:00
|
|
|
procedure TApp1MainController.DoLogin(username: string);
|
2014-04-01 00:02:31 +02:00
|
|
|
begin
|
2016-06-28 13:42:14 +02:00
|
|
|
Session['username'] := username;
|
2016-12-05 15:50:00 +01:00
|
|
|
Render(200, 'Logged in');
|
2014-04-01 00:02:31 +02:00
|
|
|
end;
|
|
|
|
|
2016-06-28 13:42:14 +02:00
|
|
|
procedure TApp1MainController.DoLogout;
|
2014-04-01 00:02:31 +02:00
|
|
|
begin
|
2016-06-28 13:42:14 +02:00
|
|
|
Context.SessionStop(false);
|
2016-12-05 15:50:00 +01:00
|
|
|
Render(200, 'Logged out');
|
2014-04-01 00:02:31 +02:00
|
|
|
end;
|
|
|
|
|
2016-06-28 13:42:14 +02:00
|
|
|
procedure TApp1MainController.Index;
|
2014-04-01 00:02:31 +02:00
|
|
|
begin
|
2016-06-28 13:42:14 +02:00
|
|
|
// do not create session if not already created
|
|
|
|
if Context.SessionStarted then
|
|
|
|
begin
|
|
|
|
// automaticaly create the session
|
2022-10-26 19:31:54 +02:00
|
|
|
Render(200, 'Hello ' + Session['username']);
|
2016-06-28 13:42:14 +02:00
|
|
|
end
|
|
|
|
else
|
|
|
|
begin
|
2022-10-26 19:31:54 +02:00
|
|
|
RenderStatusMessage(http_status.BadRequest, 'Session not created. Do login first');
|
2016-06-28 13:42:14 +02:00
|
|
|
end;
|
2014-04-01 00:02:31 +02:00
|
|
|
end;
|
|
|
|
|
|
|
|
end.
|