Skip to content

Instantly share code, notes, and snippets.

@bhameyie
Created June 17, 2013 01:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bhameyie/5794092 to your computer and use it in GitHub Desktop.
Save bhameyie/5794092 to your computer and use it in GitHub Desktop.
Extension class that helps handle my security needs
public static class ModuleSecurity
{
public static void ShouldBeAuthenticated(this NancyModule module)
{
module.Before.AddItemToEndOfPipeline(ShouldBeAuthenticated);
}
private static Response ShouldBeAuthenticated(NancyContext context)
{
Response response = null;
if ((context.CurrentUser == null) ||
String.IsNullOrWhiteSpace(context.CurrentUser.UserName))
{
response = new RedirectResponse("/");
}
return response;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment