2014-04-01 00:02:31 +02:00
|
|
|
unit AppControllerU;
|
|
|
|
|
|
|
|
interface
|
|
|
|
|
|
|
|
uses MVCFramework,
|
|
|
|
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])]
|
2016-06-28 13:42:14 +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
|
|
|
|
|
|
|
|
uses
|
|
|
|
Data.DBXJSON,
|
2016-12-05 15:50:00 +01:00
|
|
|
System.SysUtils, MVCFramework.Commons;
|
2014-04-01 00:02:31 +02:00
|
|
|
|
|
|
|
{ TApp1MainController }
|
|
|
|
|
2016-06-28 13:42:14 +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-01-01 23:00:22 +01:00
|
|
|
ContentType := TMVCMediaType.TEXT_PLAIN;
|
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
|
2016-12-05 15:50:00 +01:00
|
|
|
Render('Hello ' + Session['username']);
|
2016-06-28 13:42:14 +02:00
|
|
|
end
|
|
|
|
else
|
|
|
|
begin
|
|
|
|
Render(400, 'Session not created. Do login first');
|
|
|
|
end;
|
2014-04-01 00:02:31 +02:00
|
|
|
end;
|
|
|
|
|
|
|
|
end.
|