mirror of
https://github.com/danieleteti/delphimvcframework.git
synced 2024-11-16 00:05:53 +01:00
5601767e04
- added method TWebContext.SessionID - added unit test for TWebContext.SessionStarted
65 lines
1.2 KiB
ObjectPascal
65 lines
1.2 KiB
ObjectPascal
unit AppControllerU;
|
|
|
|
interface
|
|
|
|
uses MVCFramework,
|
|
MVCFramework.Logger,
|
|
Web.HTTPApp;
|
|
|
|
type
|
|
|
|
[MVCPath('/')]
|
|
TApp1MainController = class(TMVCController)
|
|
public
|
|
[MVCPath('/name')]
|
|
[MVCHTTPMethod([httpGET])]
|
|
procedure Index;
|
|
|
|
[MVCPath('/login/($username)')]
|
|
[MVCHTTPMethod([httpGET])]
|
|
procedure DoLogin(username: String);
|
|
|
|
[MVCPath('/logout')]
|
|
[MVCHTTPMethod([httpGET])]
|
|
procedure DoLogout;
|
|
|
|
end;
|
|
|
|
implementation
|
|
|
|
uses
|
|
Data.DBXJSON,
|
|
System.SysUtils, MVCFramework.Commons;
|
|
|
|
{ TApp1MainController }
|
|
|
|
procedure TApp1MainController.DoLogin(username: String);
|
|
begin
|
|
Session['username'] := username;
|
|
Render(204, 'No Content');
|
|
end;
|
|
|
|
procedure TApp1MainController.DoLogout;
|
|
begin
|
|
Context.SessionStop(false);
|
|
Render(204, 'No Content');
|
|
end;
|
|
|
|
procedure TApp1MainController.Index;
|
|
begin
|
|
ContentType := TMVCMediaType.TEXT_PLAIN;
|
|
|
|
// 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;
|
|
end;
|
|
|
|
end.
|