Created
June 17, 2013 01:21
-
-
Save bhameyie/5794129 to your computer and use it in GitHub Desktop.
A simple account module to handle logging in and off
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 class AccountModule : NancyModule | |
{ | |
private readonly IAuthenticationServiceClient m_authenticationService; | |
public AccountModule(IAuthenticationServiceClient authenticationService) | |
: base("/Account") | |
{ | |
m_authenticationService = authenticationService; | |
Post["/Login"] = args => | |
{ | |
var model = this.Bind<LogOnModel>(); | |
var apiToken = m_authenticationService.Authenticate(model); | |
return this.LoginAndRedirect(Guid.NewGuid(), fallbackRedirectUrl: "~/blog"); | |
}; | |
Get["/Register"] = _ => View["/Account/Register"]; | |
Get["/Login"] = _ => View["/Account/Login"]; | |
Get["/LogOff"] = _ => | |
{ | |
this.ShouldBeAuthenticated(); | |
Context.CurrentUser = null; | |
return this.LogoutAndRedirect("/Login"); | |
}; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment