public bool Perform(ExecuteEnum exec, IRailsEngineContext context, Controller controller)
{
// Read previous authenticated principal from session
// (could be from cookie although with more work)
User user = (User) context.Session["user"];
// Sets the principal as the current user
context.CurrentUser = user;
// Checks if it is OK
if (context.CurrentUser == null || !context.CurrentUser.Identity.IsAuthenticated)
{
// Not authenticated, redirect to login
NameValueCollection parameters = new NameValueCollection();
parameters.Add("ReturnUrl", context.Url);
controller.Redirect("login", "index", parameters);
// Prevent request from continue
return false;
}
// Everything is ok
return true;
}
}