delphimvcframework/samples/sessions/AppControllerU.pas

61 lines
1.1 KiB
ObjectPascal
Raw Normal View History

2014-04-01 00:02:31 +02:00
unit AppControllerU;
interface
2017-06-22 16:18:58 +02:00
uses
MVCFramework,
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])]
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])]
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
Session['username'] := username;
Render(200, 'Logged in');
2014-04-01 00:02:31 +02:00
end;
procedure TApp1MainController.DoLogout;
2014-04-01 00:02:31 +02:00
begin
Context.SessionStop(false);
Render(200, 'Logged out');
2014-04-01 00:02:31 +02:00
end;
procedure TApp1MainController.Index;
2014-04-01 00:02:31 +02:00
begin
// do not create session if not already created
if Context.SessionStarted then
begin
// automaticaly create the session
Render(200, 'Hello ' + Session['username']);
end
else
begin
RenderStatusMessage(http_status.BadRequest, 'Session not created. Do login first');
end;
2014-04-01 00:02:31 +02:00
end;
end.