Last active
May 5, 2016 16:56
-
-
Save igorkulman/2430a948fe6c426cdd01 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
protected override void RequestStartup(TinyIoCContainer container, IPipelines pipelines, NancyContext context) | |
{ | |
base.RequestStartup(container, pipelines, context); | |
var formsAuthConfiguration = | |
new FormsAuthenticationConfiguration() | |
{ | |
DisableRedirect = true, | |
UserMapper = container.Resolve<IUserMapper>() | |
}; | |
FormsAuthentication.Enable(pipelines, formsAuthConfiguration); | |
} |
This file contains hidden or 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
Post["/login"] = _ => | |
{ | |
var loginParams = this.Bind<LoginParams>(); | |
var user = _userService.Get(loginParams.Username, loginParams.Password); | |
if (user == null) | |
{ | |
return HttpStatusCode.Unauthorized; | |
} | |
var authResult = this.LoginAndRedirect(user.Guid); | |
return Response.AsJson(new | |
{ | |
username = user.Username | |
}).WithCookie(authResult.Cookies.First()); | |
}; |
This file contains hidden or 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
Get["/logout"] = _ => | |
{ | |
this.RequiresAuthentication(); | |
var response = this.LogoutWithoutRedirect(); | |
return Response.AsText("logout").WithCookie(response.Cookies.First()); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment