Created
June 17, 2013 01:10
-
-
Save bhameyie/5794092 to your computer and use it in GitHub Desktop.
Extension class that helps handle my security needs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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