2016-11-13 20:59:21 +01:00
|
|
|
unit MVCFramework.Tests.WebModule2;
|
2015-06-15 18:57:46 +02:00
|
|
|
|
|
|
|
interface
|
|
|
|
|
|
|
|
uses
|
|
|
|
System.SysUtils,
|
|
|
|
System.Classes,
|
2016-06-16 22:13:35 +02:00
|
|
|
System.Generics.Collections,
|
2015-06-15 18:57:46 +02:00
|
|
|
Web.HTTPApp,
|
|
|
|
MVCFramework;
|
|
|
|
|
|
|
|
type
|
|
|
|
|
2016-11-13 20:59:21 +01:00
|
|
|
TTestWebModule2 = class(TWebModule)
|
2015-06-15 18:57:46 +02:00
|
|
|
procedure WebModuleCreate(Sender: TObject);
|
|
|
|
procedure WebModuleDestroy(Sender: TObject);
|
|
|
|
private
|
|
|
|
FMVCEngine: TMVCEngine;
|
|
|
|
public
|
|
|
|
{ Public declarations }
|
|
|
|
end;
|
|
|
|
|
|
|
|
var
|
2016-11-13 20:59:21 +01:00
|
|
|
TestWebModuleClass: TComponentClass = TTestWebModule2;
|
|
|
|
TestWebModuleClass2: TComponentClass = TTestWebModule2;
|
2015-06-15 18:57:46 +02:00
|
|
|
|
|
|
|
implementation
|
|
|
|
|
|
|
|
uses
|
2015-12-22 12:29:25 +01:00
|
|
|
MVCFramework.Tests.StandaloneServer,
|
2015-06-15 22:51:36 +02:00
|
|
|
MVCFramework.Middleware.Authentication,
|
2016-06-16 22:13:35 +02:00
|
|
|
MVCFramework.Server,
|
|
|
|
MVCFramework.Server.Impl;
|
2015-06-15 18:57:46 +02:00
|
|
|
|
|
|
|
{$R *.dfm}
|
|
|
|
|
2016-11-13 20:59:21 +01:00
|
|
|
procedure TTestWebModule2.WebModuleCreate(Sender: TObject);
|
2015-06-15 18:57:46 +02:00
|
|
|
begin
|
|
|
|
FMVCEngine := TMVCEngine.Create(Self);
|
2015-06-15 22:51:36 +02:00
|
|
|
|
2016-02-29 13:48:36 +01:00
|
|
|
// Add With Delegate Constructor Controller
|
2016-06-16 22:13:35 +02:00
|
|
|
FMVCEngine.AddController(TTestController,
|
2016-02-29 13:48:36 +01:00
|
|
|
function: TMVCController
|
|
|
|
begin
|
2016-06-16 22:13:35 +02:00
|
|
|
Result := TTestController.Create;
|
2016-02-29 13:48:36 +01:00
|
|
|
end
|
|
|
|
);
|
2015-06-15 22:51:36 +02:00
|
|
|
|
2016-06-16 22:13:35 +02:00
|
|
|
FMVCEngine.AddMiddleware(TMVCBasicAuthenticationMiddleware.Create(
|
|
|
|
TMVCDefaultAuthenticationHandler.New
|
|
|
|
.SetOnAuthentication(
|
|
|
|
procedure(const AUserName, APassword: string;
|
|
|
|
AUserRoles: TList<string>; var IsValid: Boolean; const ASessionData: TDictionary<String, String>)
|
|
|
|
begin
|
|
|
|
IsValid := AUserName.Equals('dmvc') and APassword.Equals('123');
|
|
|
|
end
|
|
|
|
)
|
|
|
|
));
|
2015-06-15 18:57:46 +02:00
|
|
|
end;
|
|
|
|
|
2016-11-13 20:59:21 +01:00
|
|
|
procedure TTestWebModule2.WebModuleDestroy(Sender: TObject);
|
2015-06-15 18:57:46 +02:00
|
|
|
begin
|
2016-06-16 22:13:35 +02:00
|
|
|
FMVCEngine.Free;
|
2015-06-15 18:57:46 +02:00
|
|
|
end;
|
|
|
|
|
|
|
|
end.
|