Exemplo n.º 1
0
        public override async Task ValidatePrincipal(CookieValidatePrincipalContext context)
        {
            //재검증
            var refreshMin    = 15;
            var userPrincipal = context.Principal;

            var nextCheckDate = userPrincipal.GetClaimValue(WebExtention.CustomClaimType.NextCheckTime);

            //Console.WriteLine(nextCheckDate);

            if (string.IsNullOrWhiteSpace(nextCheckDate) || DateTime.ParseExact(nextCheckDate, "yyyyMMddHHmmss", CultureInfo.CurrentCulture) < DateTime.Now)
            {
                var u_id  = userPrincipal.GetClaim(ClaimTypes.NameIdentifier).Value.ToUint();
                var email = userPrincipal.GetClaim(ClaimTypes.Name).Value;

                var model = await MUserinfo.GetAsync(u_id);

                if (model?.EMAIL == email && model?.STATUS >= 0) //로그인 사용자에게 문제가 없다면
                {
                    var claimType  = WebExtention.GetCustomClaimTypeString(WebExtention.CustomClaimType.NextCheckTime);
                    var claimValue = DateTime.Now.AddMinutes(refreshMin).ToString("yyyyMMddHHmmss");
                    var checkClaim = userPrincipal.GetClaim(claimType);
                    var identity   = (userPrincipal.Identity as ClaimsIdentity);
                    identity.RemoveClaim(checkClaim);
                    identity.AddClaim(new Claim(claimType, claimValue));
                    await context.HttpContext.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme, userPrincipal);
                }
                else //사용자가 검증 로직을 통과하지 못했다면?
                {
                    //강제 로그아웃 처리
                    context.RejectPrincipal();
                    await context.HttpContext.SignOutAsync(CookieAuthenticationDefaults.AuthenticationScheme);
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// 授权失败返回处理
        /// </summary>
        /// <param name="vret"></param>
        /// <returns></returns>
        public virtual ActionResult AuthorizeVerifyFail(Result vret)
        {
            //调用默认授权失败返回消息处理
            string url = WebExtention.GetCurrentDomainUrl() + WebExtention.UrlEncode(HttpContext.Current.Request.RawUrl.ToString());

            //判断是否为Ajax请求
            if (WebExtention.IsAjax())
            {
                if (string.IsNullOrEmpty(vret.Message))
                {
                    vret.Message = "登录超时,请重新登录!";
                }
                //Ajax请求返回json数据
                Result     ret    = new Result(vret.Message, ResultTypes.UnAuthorize);
                JsonResult result = new JsonResult();
                result.Data = ret;
                return((ActionResult)result);
            }
            else
            {
                //没有登录跳转请问登录
                RouteValueDictionary route = new RouteValueDictionary();
                route.Add("action", "Index");
                route.Add("controller", "OAuth");
                route.Add("return_url", url);
                RedirectToRouteResult result = new RedirectToRouteResult(route);
                return(result);
            }
        }
Exemplo n.º 3
0
 /// <summary>
 /// 重写处理链接方法,处理https请求,使其重定向http
 /// </summary>
 /// <param name="filterContext"></param>
 protected virtual void HandleNonHttpRequest(AuthorizationContext filterContext)
 {
     if (String.Equals(filterContext.HttpContext.Request.HttpMethod, "GET", StringComparison.OrdinalIgnoreCase))
     {
         string url = WebExtention.GetCurrentDomainUrl() + filterContext.HttpContext.Request.RawUrl.ToString();
         //重定向
         filterContext.Result = new RedirectResult(url);
     }
 }
Exemplo n.º 4
0
        /// <summary>
        /// 行为执行事件
        /// </summary>
        /// <param name="filterContext"></param>
        protected override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            VisitorTerminal vt = WebExtention.GetVisitorTerminal();

            if (vt.IsMobileTerminal)
            {
                //this.JumpMobileUrl(filterContext.RouteData, "");//跳转至移动网站
            }
            base.OnActionExecuting(filterContext);
        }
Exemplo n.º 5
0
 /// <summary>
 /// 返回错误信息
 /// </summary>
 /// <param name="Message">错误消息</param>
 /// <param name="ViewName">页面名字</param>
 /// <returns></returns>
 private ActionResult GetErrorResult(string Message, string ViewName = "Error")
 {
     if (WebExtention.IsAjax())//判断是否是ajax请求
     {
         JsonResult result = new JsonResult();
         result.Data = new
         {
             Success = false,
             Status  = 500,
             Message = Message
         };
         return((ActionResult)result);
     }
     else
     {
         ViewResult view = new ViewResult();
         view.ViewName        = ViewName;
         view.ViewBag.Message = Message;
         return((ActionResult)view);
     }
 }
Exemplo n.º 6
0
        /// <summary>
        /// 收集信息
        /// </summary>
        /// <param name="Request"></param>
        public void Collection()
        {
            VisitorTerminal vt = WebExtention.GetVisitorTerminal();

            LogHelper.Info(vt);//存储
        }