예제 #1
0
        public override void OnException(ExceptionContext filterContext)
        {
            base.OnException(filterContext);

            LogMessage logMessage = new LogMessage(HttpContext.Current);

            string token = HttpContext.Current.Request.Headers["Token"];

            if (!string.IsNullOrEmpty(token))
            {
                TokenInfo tokenInfo = JwtUtil.GetTokenInfo(token);

                if (tokenInfo != null)
                {
                    logMessage.UserName = tokenInfo.Number;
                }
            }

            logMessage.ExceptionInfo = string.Format("{0}\r\n{1}\r\n{2}\r\n", filterContext.Exception.Message, filterContext.Exception.StackTrace, filterContext.Exception.Source);

            LogUtility.ErrorLogger.Error(new LogFormat().ExceptionFormat(logMessage));

            filterContext.ExceptionHandled = true; //指示异常已经处理,不需要返回异常信息到客户端

            filterContext.Result = new JsonResult()
            {
                Data = new BackMessage()
                {
                    Code = 500,
                    Msg  = "false",
                    Data = null
                }
            };
        }
예제 #2
0
        public JsonResult ModifyPwd(string oldPassword, string newPassword, PasswordType passwordType)
        {
            var tokenInfo = JwtUtil.GetTokenInfo();

            return(new JsonResult()
            {
                Data = settingService.ModifyPassword(tokenInfo.Number, oldPassword, newPassword, passwordType)
            });
        }
        protected virtual bool IsAuthenticated(AuthenticationContext filterContext)
        {
            string token = filterContext.HttpContext.Request.Headers["Token"];

            if (!string.IsNullOrEmpty(token))
            {
                TokenInfo tokenInfo = JwtUtil.GetTokenInfo(token);

                if (tokenInfo != null)
                {
                    var span = DateTime.Now - TimeUtil.StampToDateTime(tokenInfo.Expire);
                    if (span.TotalHours > 2)
                    {
                        return(false);
                    }
                    else
                    {
                        return(true);
                    }
                }
            }
            return(false);
        }