Skip to content

Commit

Permalink
Sync latest
Browse files Browse the repository at this point in the history
  • Loading branch information
itadapter committed Jan 20, 2016
1 parent 1c84b47 commit 2f9dfa6
Show file tree
Hide file tree
Showing 151 changed files with 7,078 additions and 1,930 deletions.
3 changes: 1 addition & 2 deletions Guides/WAVE/RecordView/readme.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# RecordView

Binds Record model (an isntance of Record class) with UI builder/rendering library which dynamically builds the DOM in the attached view components (div placeholders). Thus, changes made to view model/data model in record instance will get automatically represented in the attached UI.
Binds Record model (an instance of Record class) with UI builder/rendering library which dynamically builds the DOM in the attached view components (div placeholders). Thus, changes made to view model/data model in record instance will get automatically represented in the attached UI.

## RecordView
Constructor. Initializes a new instance using string field definition and value.
Expand Down
14 changes: 13 additions & 1 deletion Guides/WAVE/WVJS.md
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ convertScalarType(false, 13, "string", "<unconvertible>");


## Event manager mixin
Implementation of event-handler mechanism that can be added to any class.
Implements the event-handler mechanism and can be added to any class.
For examples of using look at [Record](Record/readme.md) class description.

##### eventInvocationSuspendCount: 0
Expand All @@ -201,6 +201,18 @@ Clears all functions from the named event handler.
##### eventInvoke(evtName)
Invokes all functions bound to the named event handler.

##### eventSinkBind(sink)
Binds a sink instance (an object) that will receive all events dispatched by this manager. The `sink` must have a function called `eventNotify(evtName, sender, args)` that will be invoked.

##### eventSinkUnbind(sink)
Un-Binds an object that received all events from this manager.

##### eventSinkClear()
Clears all objects that cat as event sinks bound to this instance.

##### eventSinks()
Returns a list of sink object that receive event notifications from this manager.


## Record Model
Record model is in the WAVE.RecordModel namespace.
Expand Down
40 changes: 40 additions & 0 deletions Source/NFX.Wave/Filters/PortalFilter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ public class PortalFilter : WorkFilter
{
#region CONSTS
public const string VAR_PORTAL_NAME = "portal-name";
public const string CONF_THEME_COOKIE_NAME_ATTR = "theme-cookie-name";
public const string CONF_USE_THEME_COOKIE_ATTR = "use-theme-cookie";
public const string DEFAULT_THEME_COOKIE_NAME = "UIT";
#endregion

#region .ctor
Expand All @@ -43,6 +46,10 @@ public PortalFilter(WorkHandler handler, string name, int order) : base(handler,

private void ctor(IConfigSectionNode confNode)
{

m_UseThemeCookie = confNode.AttrByName(CONF_USE_THEME_COOKIE_ATTR).ValueAsBool(true);
m_ThemeCookieName = confNode.AttrByName(CONF_THEME_COOKIE_NAME_ATTR).ValueAsString(DEFAULT_THEME_COOKIE_NAME);

//read matches
foreach(var cn in confNode.Children.Where(cn=>cn.IsSameName(WorkMatch.CONFIG_MATCH_SECTION)))
if(!m_PortalMatches.Register( FactoryUtils.Make<WorkMatch>(cn, typeof(WorkMatch), args: new object[]{ cn })) )
Expand All @@ -54,6 +61,9 @@ private void ctor(IConfigSectionNode confNode)
#region Fields

private OrderedRegistry<WorkMatch> m_PortalMatches = new OrderedRegistry<WorkMatch>();

private bool m_UseThemeCookie;
private string m_ThemeCookieName = DEFAULT_THEME_COOKIE_NAME;

#endregion

Expand All @@ -64,6 +74,24 @@ private void ctor(IConfigSectionNode confNode)
/// </summary>
public OrderedRegistry<WorkMatch> PortalMatches { get{ return m_PortalMatches;}}


/// <summary>
/// Specifies true to interpret ThemeCookieName
/// </summary>
public bool UseThemeCookie
{
get { return m_UseThemeCookie;}
set { m_UseThemeCookie = value; }
}

/// <summary>
/// Specifies theme cookie name
/// </summary>
public string ThemeCookieName
{
get { return m_ThemeCookieName ?? DEFAULT_THEME_COOKIE_NAME;}
set { m_ThemeCookieName = value; }
}
#endregion

#region Protected
Expand Down Expand Up @@ -105,6 +133,18 @@ protected sealed override void DoFilterWork(WorkContext work, IList<WorkFilter>
}
}

if (m_UseThemeCookie && work.m_Portal!=null)
{
//Use regular cookies so client JS can set it up
var tcv = work.Request.Cookies[m_ThemeCookieName];//work.Response.GetClientVar(m_ThemeCookieName);
if (tcv!=null && tcv.Value.IsNotNullOrWhiteSpace())
{
var theme = work.m_Portal.Themes[tcv.Value];
if (theme!=null)
work.m_PortalTheme = theme;
}
}

if (Server.m_InstrumentationEnabled &&
work.m_Portal!=null &&
work.m_Portal.InstrumentationEnabled)
Expand Down
2 changes: 2 additions & 0 deletions Source/NFX.Wave/Handlers/FileDownloadHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,8 @@ protected override void DoHandleWork(WorkContext work)
work.Response.WriteFile(fileName, attachment: attachment);
else
{
var ext = Path.GetExtension(fsFile.Name);
work.Response.ContentType = NFX.Web.ContentType.ExtensionToContentType(ext, NFX.Web.ContentType.BINARY);
work.Response.WriteStream(fsFile.FileStream, attachmentName: attachment ? Path.GetFileName(fileName) : null);
}
}
Expand Down
1 change: 1 addition & 0 deletions Source/NFX.Wave/Handlers/MVCHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ protected override void DoTargetWork(Controller target, WorkContext work)
}
finally
{

target.m_WorkContext = null;
}
}
Expand Down
63 changes: 63 additions & 0 deletions Source/NFX.Wave/MVC/SessionCSRFCheckAttribute.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;

namespace NFX.Wave.MVC
{
/// <summary>
/// Decorates controller actions that need to check CSRF token against the user session
/// </summary>
public sealed class SessionCSRFCheckAttribute : ActionFilterAttribute
{
public const string DEFAULT_TOKEN_NAME = "token";


public SessionCSRFCheckAttribute()
{
TokenName = DEFAULT_TOKEN_NAME;
}

public SessionCSRFCheckAttribute(string tokenName) : this(tokenName, true)
{
}

public SessionCSRFCheckAttribute(string tokenName, bool onlyExistingSession)
{
TokenName = tokenName;

if (TokenName.IsNullOrWhiteSpace())
TokenName = DEFAULT_TOKEN_NAME;

OnlyExistingSession = onlyExistingSession;
}


public string TokenName{ get; private set; }
public bool OnlyExistingSession{ get; private set; }


protected internal override bool BeforeActionInvocation(Controller controller, WorkContext work, string action, MethodInfo method, object[] args, ref object result)
{
if (work.IsGET) return false;

work.NeedsSession(OnlyExistingSession);

var session = work.Session;
var supplied = work.MatchedVars[TokenName].AsString();

if (session==null ||
!session.CSRFToken.EqualsOrdIgnoreCase(supplied))
throw new HTTPStatusException(NFX.Wave.SysConsts.STATUS_400, NFX.Wave.SysConsts.STATUS_400_DESCRIPTION, "CSRF failed");

return false;
}

protected internal override bool AfterActionInvocation(Controller controller, WorkContext work, string action, MethodInfo method, object[] args, ref object result)
{
return false;
}
}
}
12 changes: 9 additions & 3 deletions Source/NFX.Wave/NFX.Wave.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
<Compile Include="MVC\Attributes.cs" />
<Compile Include="MVC\Controller.cs" />
<Compile Include="MVC\Reflection.cs" />
<Compile Include="MVC\SessionCSRFCheckAttribute.cs" />
<Compile Include="Portal.cs" />
<Compile Include="PortalHub.cs" />
<Compile Include="Response.cs" />
Expand Down Expand Up @@ -102,16 +103,19 @@
</ItemGroup>
<ItemGroup>
<Content Include="BUILD_INFO.txt" />
<EmbeddedResource Include="Templatization\StockContent\Embedded\script\jquery-2.1.4.min.js" />
<Content Include="Templatization\StockContent\Embedded\script\wv.all.min.js" />
<EmbeddedResource Include="Templatization\StockContent\Embedded\script\wv.braintree.js" />
<EmbeddedResource Include="Templatization\StockContent\Embedded\script\wv.stripe.js" />
<None Include="Templatization\StockContent\Embedded\script\utest\wv.min.data.tests.htm" />
<Content Include="Templatization\StockContent\Embedded\script\payment.providers.test.html" />
<Content Include="Templatization\StockContent\Embedded\script\utest\wv.data.tests.js" />
<Content Include="Templatization\StockContent\Embedded\script\utest\wv.tests.js" />
<None Include="Templatization\StockContent\Embedded\script\utest\wv.min.tests.htm" />
<EmbeddedResource Include="Templatization\StockContent\Embedded\script\wv.all.min.js" />
<EmbeddedResource Include="Templatization\StockContent\Embedded\stl\console.default.css" />
<EmbeddedResource Include="Templatization\StockContent\Embedded\stl\console.modern.css" />
<None Include="Templatization\StockContent\Embedded\script\image-box.test.htm" />
<EmbeddedResource Include="Templatization\StockContent\Embedded\script\jquery-2.1.4.js" />
<EmbeddedResource Include="Templatization\StockContent\Embedded\script\jquery-2.1.4.min.js" />
<None Include="Templatization\StockContent\Embedded\script\wv.objectinspector.test.htm" />
<None Include="Templatization\StockContent\Embedded\script\wv.ruler.test.htm" />
<None Include="Templatization\StockContent\Embedded\script\wv.tree.test.htm" />
Expand Down Expand Up @@ -400,9 +404,11 @@ java -jar "$(SolutionDir)lib\closure-compiler\compiler.jar" ^
--js "$(ProjectDir)Templatization\StockContent\Embedded\script\wv.js" ^
"$(ProjectDir)Templatization\StockContent\Embedded\script\wv.gui.js" ^
"$(ProjectDir)Templatization\StockContent\Embedded\script\wv.chart.svg.js" ^
"$(ProjectDir)Templatization\StockContent\Embedded\script\wv.braintree.js" ^
"$(ProjectDir)Templatization\StockContent\Embedded\script\wv.stripe.js" ^
--js_output_file "$(ProjectDir)Templatization\StockContent\Embedded\script\wv.all.min.js" ^
--compilation_level SIMPLE_OPTIMIZATIONS ^
--language_in ECMASCRIPT5 &gt; "$(ProjectDir)Templatization\StockContent\Embedded\script\CLOSURE_ERROR_OUT.txt" 2&gt;&amp;1
--language_in ECMASCRIPT5_STRICT &gt; "$(ProjectDir)Templatization\StockContent\Embedded\script\CLOSURE_ERROR_OUT.txt" 2&gt;&amp;1

:NO_JAVA
exit 0</PreBuildEvent>
Expand Down
Loading

0 comments on commit 2f9dfa6

Please sign in to comment.