Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Added Html helpers for CurrentUser for use in Razor views #896

Merged
merged 2 commits into from

3 participants

@jchannon
Owner

In the view you can now call

@Html.IsAuthenticated and @Html.CurrentUser

src/Nancy.ViewEngines.Razor/HtmlHelpers.cs
@@ -102,5 +102,26 @@ public string CurrentLocale
{
get { return this.RenderContext.Context.Culture.Name; }
}
+
+ /// <summary>
+ /// Returns current authenticated user name
+ /// </summary>
+ public string CurrentUser
+ {
+ get
+ {
+ return this.RenderContext.Context.CurrentUser == null
@grumpydev Owner

I think this should just return the current user, not the username string.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@thecodejunkie thecodejunkie commented on the diff
src/Nancy.ViewEngines.Razor/HtmlHelpers.cs
@@ -3,6 +3,7 @@
using System;
using System.IO;
using System.Linq.Expressions;
+ using Nancy.Security;
@thecodejunkie Owner

Good man! =)

@jchannon Owner
jchannon added a note

I'm nervous now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@thecodejunkie thecodejunkie merged commit d35433a into NancyFx:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 18 additions and 1 deletion.
  1. +18 −1 src/Nancy.ViewEngines.Razor/HtmlHelpers.cs
View
19 src/Nancy.ViewEngines.Razor/HtmlHelpers.cs
@@ -3,6 +3,7 @@
using System;
using System.IO;
using System.Linq.Expressions;
+ using Nancy.Security;
@thecodejunkie Owner

Good man! =)

@jchannon Owner
jchannon added a note

I'm nervous now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
/// <summary>
/// Helpers to generate html content.
@@ -89,7 +90,7 @@ public IHtmlString Raw(string text)
/// <returns>An <see cref="IHtmlString"/> representation of the anti forgery token.</returns>
public IHtmlString AntiForgeryToken()
{
- var tokenKeyValue =
+ var tokenKeyValue =
this.RenderContext.GetCsrfToken();
return new NonEncodedHtmlString(String.Format("<input type=\"hidden\" name=\"{0}\" value=\"{1}\"/>", tokenKeyValue.Key, tokenKeyValue.Value));
@@ -102,5 +103,21 @@ public string CurrentLocale
{
get { return this.RenderContext.Context.Culture.Name; }
}
+
+ /// <summary>
+ /// Returns current authenticated user name
+ /// </summary>
+ public IUserIdentity CurrentUser
+ {
+ get { return this.RenderContext.Context.CurrentUser; }
+ }
+
+ /// <summary>
+ /// Determines if current user is authenticated
+ /// </summary>
+ public bool IsAuthenticated
+ {
+ get { return this.RenderContext.Context.CurrentUser != null; }
+ }
}
}
Something went wrong with that request. Please try again.