2015-12-22 12:29:25 +01:00
|
|
|
unit MVCFramework.Tests.WebModule;
|
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
|
|
|
|
|
|
|
|
TTestWebModule = class(TWebModule)
|
|
|
|
procedure WebModuleCreate(Sender: TObject);
|
|
|
|
procedure WebModuleDestroy(Sender: TObject);
|
|
|
|
private
|
|
|
|
FMVCEngine: TMVCEngine;
|
|
|
|
public
|
|
|
|
{ Public declarations }
|
|
|
|
end;
|
|
|
|
|
|
|
|
var
|
|
|
|
TestWebModuleClass: TComponentClass = TTestWebModule;
|
2016-06-16 22:13:35 +02:00
|
|
|
TestWebModuleClass2: TComponentClass = TTestWebModule;
|
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}
|
|
|
|
|
|
|
|
procedure TTestWebModule.WebModuleCreate(Sender: TObject);
|
|
|
|
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;
|
|
|
|
|
|
|
|
procedure TTestWebModule.WebModuleDestroy(Sender: TObject);
|
|
|
|
begin
|
2016-06-16 22:13:35 +02:00
|
|
|
FMVCEngine.Free;
|
2015-06-15 18:57:46 +02:00
|
|
|
end;
|
|
|
|
|
|
|
|
end.
|