示例#1
0
        public void OnAuthorization(AuthorizationFilterContext context)
        {
            var token = context.HttpContext.Session.GetString("token");

            if (token == null || string.IsNullOrEmpty(token))
            {
                token = context.HttpContext.Request.Query["token"];
            }
            if (token == null || string.IsNullOrEmpty(token))
            {
                if (context.HttpContext.Request.Form != null && context.HttpContext.Request.Form.Any())
                {
                    token = context.HttpContext.Request.Form["token"];
                }
            }
            if (token == null || string.IsNullOrEmpty(token))
            {
                token = context.HttpContext.Request.Headers["token"];
            }
            if (token == null || string.IsNullOrEmpty(token))
            {
                token = context.HttpContext.Session.GetString("token");
            }

            if (token == null || string.IsNullOrEmpty(token) || !tokenSerivce.VerifyToken(token))
            {
                context.HttpContext.Session.Remove("token");
                //context.HttpContext.Response.StatusCode = (int)HttpStatusCode.Forbidden;
                ApiRe apiRe = new ApiRe()
                {
                    Ok  = false,
                    Msg = "NOTLOGIN",
                };
                //return Json(apiRe, MyJsonConvert.GetOptions());
                context.Result = new JsonResult(apiRe, MyJsonConvert.GetSimpleOptions());

                return;
            }
        }
示例#2
0
        public void OnAuthorization(AuthorizationFilterContext context)
        {
            var userid = context.HttpContext.Session.GetString("UserId");
            var token  = context.HttpContext.Session.GetString("token");

            if (token == null || string.IsNullOrEmpty(token))
            {
                context.Result = new RedirectResult("/Auth/Login");
                return;
            }
            //验证token
            if (!tokenSerivce.VerifyToken(token))
            {
                context.HttpContext.Session.Remove("token");
                context.Result = new RedirectResult("/Auth/Login");
                return;
            }
            if (string.IsNullOrEmpty(userid))
            {
                context.Result = new RedirectResult("/Auth/Login");
            }

            if (string.IsNullOrEmpty(userid))
            {
                context.Result = new RedirectResult("/Auth/Login");
            }

            if (CheckVerified)
            {
                var verified = _session.GetBool("Verified");
                if (verified == null || !verified.Value)
                {
                    context.Result = new RedirectResult("/Auth/Verify");
                }
            }
        }