/// <summary>
        /// 执行操作(调用方法特性后由框架调用)
        /// </summary>
        /// <param name="filterContext">过滤上下文</param>
        public override void OnActionExecuted(ActionExecutedContext filterContext)
        {
            //方法名称
            var actionName = filterContext.ActionDescriptor.ActionName;
            //控制器
            var controllerName = filterContext.ActionDescriptor.ControllerDescriptor.ControllerName;

            Dictionary <String, String> parmsObj = new Dictionary <String, String>();

            foreach (var item in parameterNameList.Split(',', '|'))
            {
                var valueProviderResult = filterContext.Controller.ValueProvider.GetValue(item);

                if (valueProviderResult != null && !parmsObj.ContainsKey(item))
                {
                    parmsObj.Add(item, valueProviderResult.AttemptedValue);
                }
            }

            var ticketUser = FormsAuthenticationService.GetAuthenticatedUser();

            try
            {
                String responseDataStr = JsonConvert.SerializeObject(filterContext.Result);
                if (responseDataStr == null)
                {
                    responseDataStr = String.Empty;
                }

                DataAccessBLL.Insert(new UserOperationLog
                {
                    UserID          = ticketUser?.UserID ?? 0,
                    UserAccount     = ticketUser == null ? "未知用户" : ticketUser.UserAccount,
                    OperationMothod = $"{controllerName}.{actionName}",
                    OperationName   = operationExplain,
                    OperationData   = JsonConvert.SerializeObject(parmsObj),
                    ReturnData      = responseDataStr,
                    Crdate          = DateTime.Now
                });
            }
            catch (Exception ex)
            {
                // 记录错误日志
            }
        }
Exemplo n.º 2
0
        public ActionResult Index(UserViewModel model, String vcode)
        {
            String  message = String.Empty;
            Boolean result  = false;

            if (false)
            {
                if (Session["vcode"] == null)
                {
                    message       = "验证码过期";
                    model.Message = message;
                    model.UserPwd = String.Empty;
                    return(View("Index", model));
                }

                if (Session["vcode"].ToString() != vcode)
                {
                    message       = "验证码错误";
                    model.Message = message;
                    model.UserPwd = String.Empty;
                    return(View("Index", model));
                }
            }

            if (String.IsNullOrEmpty(model.UserAccount) || String.IsNullOrEmpty(model.UserPwd))
            {
                message       = "请输入账号、密码!";
                model.Message = message;
                model.UserPwd = String.Empty;
                return(View("Index", model));
            }

            var loginUserByDB = GetUser(model.UserAccount, model.UserPwd);

            if (loginUserByDB == null)
            {
                message       = "请输入正确的账号、密码!";
                model.Message = message;
                model.UserPwd = String.Empty;
                return(View("Index", model));
            }

            if (loginUserByDB.Status != 0)
            {
                message       = "您的帐号已被锁定,请联系管理员!";
                model.Message = message;
                model.UserPwd = String.Empty;
                return(View("Index", model));
            }

            var loginUser = ModelConvert(loginUserByDB);
            var loginIp   = Request.UserHostAddress;

            UpdateLoginInfo(loginUserByDB, loginIp);
            FormsAuthenticationService.SignIn(loginUser);

            //日志记录
            DataAccessBLL.Insert(new UserOperationLog
            {
                UserID          = loginUser.UserID,
                UserAccount     = loginUser.UserAccount,
                OperationMothod = "login.Index",
                OperationName   = "系统登录",
                OperationData   = "",
                ReturnData      = String.Empty,
                Crdate          = DateTime.Now
            });

            Session["vcode"] = String.Empty;

            // 登陆成功 判断之前是否访问某个页面 没有就跳转到home
            if (String.IsNullOrEmpty(model.ReturnUrl) || model.ReturnUrl.Trim() == "/")
            {
                return(RedirectToAction("Index", "Home"));
            }
            else
            {
                return(Redirect(model.ReturnUrl));
            }
        }