public IActionResult Login([FromBody] Models.User.UserLoginInfoViewModel userInfo)
 {
     Util.Return.ReturnResult returnValue = new Util.Return.ReturnResult();
     try
     {
         bool   validateResult;
         String strErrorMsg = null;
         (validateResult, strErrorMsg) = ValidateData(userInfo);
         if (validateResult)
         {
             //使用用户名到数据库获取用户信息
             DataBll.User.UserInfoDataBll userInfoDataBll = new DataBll.User.UserInfoDataBll();
             Model.User.UserInfo          user            = userInfoDataBll.Get(userInfo.UserName);
             if (null != user &&
                 user.State == Model.EnumType.UserState.Normal &&
                 !String.IsNullOrWhiteSpace(userInfo.Password))
             {
                 String strPassword = Util.EncryptionAlgorithm.Md5Algorithm.Encryption32(userInfo.Password);
                 if (strPassword == user.Password)
                 {
                     //生成Token
                     Int32 expired = 1;
                     if (userInfo.RememberMe)
                     {
                         expired = 30;
                     }
                     DateTime expiredTime = System.DateTime.UtcNow.AddDays(expired);
                     HttpContext.Response.Cookies.Append(
                         Util.LoginTokenHelper.LoginTokenName
                         , Util.LoginTokenHelper.GetToken(userInfo.UserName, expiredTime)
                         , new Microsoft.AspNetCore.Http.CookieOptions()
                     {
                         Expires = expiredTime
                     });
                     returnValue.IsOperateSuccess = true;
                     returnValue.Description      = "Success";
                 }
                 else
                 {
                     returnValue.Description = "Wrong password, please re-enter.";
                 }
             }
             else
             {
                 returnValue.Description = "This user not exist.Please re-enter your username and password.";
             }
         }
         else
         {
             returnValue.Description = strErrorMsg;
         }
     }
     catch (Exception ex)
     {
         returnValue.Description = "The server is abnormal, please try again later.";
         m_log.Error("Login fail.", ex);
     }
     return(new JsonResult(returnValue));
 }
        public override void OnActionExecuted(ActionExecutedContext context)
        {
            // Do something after the action executes.
            var result = context.Result;

            // Do something with Result.
            if (context.Canceled == true)
            {
                // Action execution was short-circuited by another filter.
            }

            if (context.Exception != null)
            {
                StringBuilder sbErrorDescription = new StringBuilder();
                sbErrorDescription.Append($"Error Controller:{context.Controller.ToString()}");
                sbErrorDescription.Append($"\r\n ActionDescriptor:{context.ActionDescriptor.DisplayName.ToString()}");
                sbErrorDescription.Append($"\r\n Exception.Message:{context.Exception.Message.ToString()}");
                m_log.Error(sbErrorDescription.ToString(), context.Exception);

                // Exception thrown by action or action filter.
                // Set to null to handle the exception.
                context.Exception = null;
            }
            base.OnActionExecuted(context);
        }
示例#3
0
        /// <summary>
        /// 处理异常
        /// </summary>
        /// <param name="argDescription">描述信息</param>
        /// <param name="exception">异常</param>
        protected void ProcessException(String argDescription, Exception exception)
        {
            StringBuilder sbContent = new StringBuilder();

            sbContent.Append(argDescription);
            sbContent.Append("\r\n");
            sbContent.Append("Error message:");
            sbContent.Append("\r\n");
            sbContent.Append($"     {exception.Message}");
            sbContent.Append("\r\n");
            sbContent.Append("Error stack trace:");
            sbContent.Append("\r\n");
            sbContent.Append($"     {exception.StackTrace}");
            sbContent.Append("\r\n");
            sbContent.Append("");
            m_log.Error(sbContent.ToString(), exception);
        }