diff --git a/samples/serversideviews_templatepro/CustomTemplateProFiltersU.pas b/samples/serversideviews_templatepro/CustomTemplateProFiltersU.pas index b77284a4..5a037252 100644 --- a/samples/serversideviews_templatepro/CustomTemplateProFiltersU.pas +++ b/samples/serversideviews_templatepro/CustomTemplateProFiltersU.pas @@ -27,21 +27,21 @@ interface uses - System.Rtti; + TemplatePro, System.Rtti; procedure TemplateProContextConfigure; implementation uses - TemplatePro, System.SysUtils; + System.SysUtils; -function MyHelper1(const aValue: TValue; const aParameters: TArray): TValue; +function MyHelper1(const aValue: TValue; const aParameters: TArray): TValue; begin Result := aValue.ToString + ' (I''m The MyHelper1)'; end; -function MyHelper2(const aValue: TValue; const aParameters: TArray): TValue; +function MyHelper2(const aValue: TValue; const aParameters: TArray): TValue; begin Result := aValue.ToString + ' (I''m The MyHelper2)'; end; diff --git a/sources/MVCFramework.View.Renderers.Mustache.pas b/sources/MVCFramework.View.Renderers.Mustache.pas index 17727217..ca6e9bca 100644 --- a/sources/MVCFramework.View.Renderers.Mustache.pas +++ b/sources/MVCFramework.View.Renderers.Mustache.pas @@ -219,38 +219,23 @@ procedure TMVCMustacheViewEngine.PrepareModels; Exit; end; - if Assigned(FJSONModel) and (not Assigned(ViewModel)) then - begin - // if only jsonmodel is <> nil then we take the "fast path" - FJSONModelAsString := FJSONModel.ToJSON(False); - end - else - begin - lSer := fSerializerPool.GetFromPool(True) as IMVCSerializer; + lSer := fSerializerPool.GetFromPool(True) as IMVCSerializer; + try + lJSONModel := TJsonObject.Create; try - if Assigned(FJSONModel) then - begin - lJSONModel := FJSONModel.Clone as TJsonObject; - end - else + if Assigned(ViewModel) then begin - lJSONModel := TJsonObject.Create; - end; - try - if Assigned(ViewModel) then + for DataObj in ViewModel do begin - for DataObj in ViewModel do - begin - TMVCJsonDataObjectsSerializer(lSer).TValueToJSONObjectProperty(lJSONModel, DataObj.Key, DataObj.Value, TMVCSerializationType.stDefault, nil, nil); - end; + TMVCJsonDataObjectsSerializer(lSer).TValueToJSONObjectProperty(lJSONModel, DataObj.Key, DataObj.Value, TMVCSerializationType.stDefault, nil, nil); end; - FJSONModelAsString := lJSONModel.ToJSON(False); - finally - lJSONModel.Free; end; + FJSONModelAsString := lJSONModel.ToJSON(False); finally - fSerializerPool.ReleaseToPool(lSer) + lJSONModel.Free; end; + finally + fSerializerPool.ReleaseToPool(lSer) end; fModelPrepared := True; end; diff --git a/sources/MVCFramework.pas b/sources/MVCFramework.pas index b8fcb9fd..a5173e79 100644 --- a/sources/MVCFramework.pas +++ b/sources/MVCFramework.pas @@ -916,7 +916,6 @@ TMVCController = class(TMVCRenderer) function GetCurrentWebModule: TWebModule; function GetViewModel: TMVCViewDataObject; function GetRenderedView(const AViewNames: TArray; const OnBeforeRenderCallback: TMVCSSVBeforeRenderCallback = nil): string; overload; virtual; - function GetRenderedView(const AViewNames: TArray; const JSONModel: TJSONObject; const OnBeforeRenderCallback: TMVCSSVBeforeRenderCallback = nil): string; overload; virtual; /// /// Normally used in OnBeforeControllerAction to define view headers automatically used by the Page method. @@ -1271,7 +1270,6 @@ TMVCBaseViewEngine = class(TMVCBase) FViewPath: string; FDefaultViewFileExtension: string; FUseViewCache: Boolean; - FJSONModel: TJSONObject; FBeforeRenderCallback: TMVCSSVBeforeRenderCallback; function GetRealFileName(const AViewName: string): string; virtual; function IsCompiledVersionUpToDate(const AFileName, ACompiledFileName: string): Boolean; virtual; abstract; @@ -1282,13 +1280,6 @@ TMVCBaseViewEngine = class(TMVCBase) const AController: TMVCController; const AViewModel: TMVCViewDataObject; const AContentType: string); overload; virtual; - constructor Create( - const AEngine: TMVCEngine; - const AWebContext: TWebContext; - const AController: TMVCController; - const AViewModel: TMVCViewDataObject; - const AJSONModel: TJSONObject; - const AContentType: string); overload; virtual; destructor Destroy; override; procedure Execute(const ViewName: string; const Builder: TStringBuilder); virtual; abstract; @@ -2353,7 +2344,13 @@ constructor TMVCErrorResponseItem.Create(const AMessage: string); function TWebContext.GetLoggedUser: TUser; begin if not Assigned(FLoggedUser) then + begin FLoggedUser := TUser.Create; + if SessionStarted then + begin + fLoggedUser.LoadFromSession(GetWebSession); + end; + end; Result := FLoggedUser; end; @@ -2457,8 +2454,8 @@ procedure TWebContext.SessionStop(const ARaiseExceptionIfExpired: Boolean); Cookie := FResponse.Cookies.Add; Cookie.name := TMVCConstants.SESSION_TOKEN_NAME; - Cookie.Value := GUIDToString(TGUID.NewGuid) + 'invalid' + GUIDToString(TGUID.NewGuid); - Cookie.Expires := EncodeDate(1970, 1, 1); + Cookie.Value := ''; + Cookie.Expires := EncodeDate(1979, 11, 4); Cookie.Path := '/'; TMonitor.Enter(GlobalSessionList); @@ -4195,13 +4192,13 @@ function TMVCController.GetIfNoneMatch: String; Result := Context.Request.GetHeader('If-None-Match'); end; -function TMVCController.GetRenderedView(const AViewNames: TArray; const JSONModel: TJSONObject; const OnBeforeRenderCallback: TMVCSSVBeforeRenderCallback): string; +function TMVCController.GetRenderedView(const AViewNames: TArray; const OnBeforeRenderCallback: TMVCSSVBeforeRenderCallback): string; var lView: TMVCBaseViewEngine; lViewName: string; lStrStream: TStringBuilder; begin lStrStream := TStringBuilder.Create; try - lView := FEngine.ViewEngineClass.Create(Engine, Context, Self, FViewModel, JSONModel, ContentType); + lView := FEngine.ViewEngineClass.Create(Engine, Context, Self, FViewModel, ContentType); try lView.FBeforeRenderCallback := OnBeforeRenderCallback; for lViewName in AViewNames do @@ -4377,20 +4374,6 @@ function TMVCController.GetViewModel: TMVCViewDataObject; Result := FViewModel; end; -//function TMVCController.LoadView(const AViewNames: TArray; const JSONModel: TJSONObject = nil): string; -//begin -// try -// Result := GetRenderedView(AViewNames, JSONModel); -// ResponseStream.Append(Result); -// except -// on E: Exception do -// begin -// Log.Error('[%s] %s', [E.Classname, E.Message], LOGGERPRO_TAG); -// raise; -// end; -// end; -//end; - procedure TMVCController.MVCControllerAfterCreate; begin { Implement if need be. } @@ -4417,7 +4400,7 @@ procedure TMVCController.OnBeforeAction(AContext: TWebContext; const AActionName function TMVCController.Page(const AViewName: string; const OnBeforeRenderCallback: TMVCSSVBeforeRenderCallback): string; begin - Result := GetRenderedView([AViewName], nil, OnBeforeRenderCallback); + Result := GetRenderedView([AViewName], OnBeforeRenderCallback); end; function TMVCController.Page(const AViewNames: TArray; const UseCommonHeadersAndFooters: Boolean; const OnBeforeRenderCallback: TMVCSSVBeforeRenderCallback): string; @@ -4846,11 +4829,6 @@ procedure TMVCRenderer.Render(const AStatusCode: Integer; const ACollection: Render(ACollection, AOwns, ASerializationAction); end; -function TMVCController.GetRenderedView(const AViewNames: TArray; const OnBeforeRenderCallback: TMVCSSVBeforeRenderCallback): string; -begin - Result := GetRenderedView(AViewNames, nil, OnBeforeRenderCallback); -end; - procedure TMVCRenderer.Render(const ACollection: TObjectList; const ASerializationAction: TMVCSerializationAction); begin @@ -5230,18 +5208,6 @@ constructor TMVCBaseViewEngine.Create( FDefaultViewFileExtension := WebContext.Config[TMVCConfigKey.DefaultViewFileExtension]; end; -constructor TMVCBaseViewEngine.Create( - const AEngine: TMVCEngine; - const AWebContext: TWebContext; - const AController: TMVCController; - const AViewModel: TMVCViewDataObject; - const AJSONModel: TJSONObject; - const AContentType: string); -begin - Create(AEngine, AWebContext, AController, AViewModel, AContentType); - fJSONModel := AJSONModel; -end; - destructor TMVCBaseViewEngine.Destroy; begin inherited Destroy; diff --git a/unittests/general/Several/LiveServerTestU.pas b/unittests/general/Several/LiveServerTestU.pas index 3cff27ac..a6ce6585 100644 --- a/unittests/general/Several/LiveServerTestU.pas +++ b/unittests/general/Several/LiveServerTestU.pas @@ -1082,7 +1082,7 @@ procedure TServerTest.TestCustomAuthLoginLogout; lPass := false; for lCookie in lRes.Cookies do begin - if lCookie.Value.Contains('invalid') then + if lCookie.Value.IsEmpty then begin lPass := true; Break;