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,
|
|
|
|
System.SysUtils, MVCFramework.Commons;
|
|
|
|
|
|
|
|
{ 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;
|
2014-04-01 00:02:31 +02:00
|
|
|
Render(204, 'No Content');
|
|
|
|
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);
|
2014-04-01 00:02:31 +02:00
|
|
|
Render(204, 'No Content');
|
|
|
|
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
|
|
|
|
Render('Session[''username''] = ' + Session['username']);
|
|
|
|
end
|
|
|
|
else
|
|
|
|
begin
|
|
|
|
Render(400, 'Session not created. Do login first');
|
|
|
|
end;
|
2014-04-01 00:02:31 +02:00
|
|
|
end;
|
|
|
|
|
|
|
|
end.
|