Skip to content

Instantly share code, notes, and snippets.

@bhameyie
Created June 17, 2013 01:21
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/5794129 to your computer and use it in GitHub Desktop.
Save bhameyie/5794129 to your computer and use it in GitHub Desktop.
A simple account module to handle logging in and off
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