Created
June 26, 2011 03:28
-
-
Save mikeobrien/1047191 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
public class AuthenticationBehavior : IActionBehavior | |
{ | |
private readonly IUrlRegistry _registry; | |
private readonly CurrentRequest _request; | |
private readonly IOutputWriter _writer; | |
private readonly IActionBehavior _actionBehavior; | |
private readonly ISecureSession _secureSession; | |
public AuthenticationBehavior(IUrlRegistry registry, CurrentRequest request, IOutputWriter writer, IActionBehavior actionBehavior, ISecureSession secureSession) | |
{ | |
_registry = registry; | |
_request = request; | |
_writer = writer; | |
_actionBehavior = actionBehavior; | |
_secureSession = secureSession; | |
} | |
public void Invoke() | |
{ | |
var loginPageUrl = _registry.UrlFor<LoginHandler>(x => x.Query(null)); | |
var requestingLoginPage = _request.Path.Equals(loginPageUrl, StringComparison.OrdinalIgnoreCase); | |
var loggedIn = _secureSession.IsLoggedIn(); | |
if (loggedIn && requestingLoginPage) _writer.RedirectToUrl(_registry.UrlFor<DashboardHandler>(x => x.Query())); | |
else if (loggedIn) _actionBehavior.Invoke(); | |
else if (requestingLoginPage) _actionBehavior.Invoke(); | |
else _writer.RedirectToUrl(loginPageUrl); | |
} | |
public void InvokePartial() | |
{ | |
if (_secureSession.IsLoggedIn()) _actionBehavior.InvokePartial(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment