public void OnActionExecuting(ActionExecutingContext filterContext)
{
if (!string.IsNullOrEmpty(filterContext.HttpContext.Request[_signedKey]))
{
var client = new FacebookClient();
client.AppId = GetAppId();
client.AppSecret = GetSecret();
dynamic obj = client.ParseSignedRequest(filterContext.HttpContext.Request[_signedKey]);
if (obj.page != null)
{
bool isLiked = false;
isLiked = obj.page.liked;
if (!isLiked) return;
}
}
if (string.IsNullOrEmpty(filterContext.HttpContext.Request[_statusKey]))
{
var resp = Resources.Filters.FacebookAuthorise;
resp = resp.Replace(new Dictionary<string, string>()
{
{ "{{appId}}", this.GetAppId() },
{ "{{permissions}}", GetPermissions() },
{ "{{url}}", filterContext.HttpContext.Request.Url.ToString()}
});
filterContext.HttpContext.Response.Write(resp);
filterContext.Result = new EmptyResult();
return;
}
else if (filterContext.HttpContext.Request[_statusKey].Equals("popup-blocked"))
{
return;
}
else if (!filterContext.HttpContext.Request[_statusKey].Equals("connected"))
{
if (!string.IsNullOrEmpty(this.ErrorPageAction))
{
var route = new RouteValueDictionary()
{
{ "action", this.ErrorPageAction}
};
if (!string.IsNullOrEmpty(this.ErrorPageController))
{
route.Add("controller", this.ErrorPageController);
}
filterContext.Result = new RedirectToRouteResult(route);
}
else if (!string.IsNullOrEmpty(this.ErrorPageUrl))
{
filterContext.HttpContext.Response.Redirect(this.ErrorPageUrl);
}
}
}