Beispiel #1
0
 /*
  *  Login out
  */
 public ActionResult Logout()
 {
     //clear cookie
     CookieHelper.ClearCookies();
     //sing out all froms auth
     FormsAuthentication.SignOut();
     return(View("Login"));
 }
        protected override void HandleUnauthorizedRequest(AuthorizationContext filterContext)
        {
            var user = CookieHelper.GetCookiesValue();

            if (user == null)
            {
                if (filterContext.RequestContext.HttpContext.Request.IsAjaxRequest())
                {
                    filterContext.Result = new JsonResult()
                    {
                        Data = "unauthorized user", JsonRequestBehavior = JsonRequestBehavior.AllowGet
                    };
                    return;
                }
                else
                {
                    filterContext.Result = new RedirectToRouteResult(new RouteValueDictionary {
                        { "Controller", "Account" }, { "Action", "Login" }
                    });
                    return;
                }
            }
            else
            {
                var userService = DependencyResolver.Current.GetService <IUserService>();
                var result      = userService.Login(user);
                var userData    = (User)HttpContext.Current.Session["UserData"];
                if (!result.IsSuccess || userData == null)
                {
                    CookieHelper.ClearCookies();
                    //
                    if (filterContext.RequestContext.HttpContext.Request.IsAjaxRequest())
                    {
                        filterContext.Result = new JsonResult()
                        {
                            Data = $"unauthorized user ,{result.Message}", JsonRequestBehavior = JsonRequestBehavior.AllowGet
                        };
                        return;
                    }
                    else
                    {
                        filterContext.Result = new RedirectToRouteResult(new RouteValueDictionary {
                            { "Controller", "Account" }, { "Action", "Login" }
                        });
                        return;
                    }
                }
            }
        }
Beispiel #3
0
        protected override void HandleUnauthorizedRequest(AuthorizationContext filterContext)
        {
            var user = CookieHelper.GetCookiesValue();

            if (user == null)
            {
                if (filterContext.RequestContext.HttpContext.Request.IsAjaxRequest())
                {
                    filterContext.Result = new JsonResult()
                    {
                        Data = "unauthorized user", JsonRequestBehavior = JsonRequestBehavior.AllowGet
                    };
                    return;
                }
                else
                {
                    filterContext.Result = new RedirectToRouteResult(new RouteValueDictionary {
                        { "Controller", "Account" }, { "Action", "Login" }
                    });
                    return;
                }
            }
            else
            {
                if (user.Username?.Trim().ToLower() != "Username".GetAppSetting().ToLower() || user.Password?.Trim() != "Password".GetAppSetting())
                {
                    CookieHelper.ClearCookies();
                    //
                    if (filterContext.RequestContext.HttpContext.Request.IsAjaxRequest())
                    {
                        filterContext.Result = new JsonResult()
                        {
                            Data = "unauthorized user", JsonRequestBehavior = JsonRequestBehavior.AllowGet
                        };
                        return;
                    }
                    else
                    {
                        filterContext.Result = new RedirectToRouteResult(new RouteValueDictionary {
                            { "Controller", "Account" }, { "Action", "Login" }
                        });
                        return;
                    }
                }
            }
        }