Ejemplo n.º 1
0
        /// <summary>
        /// 控制器执行之后
        /// </summary>
        /// <param name="filterContext">控制器执行上下文</param>
        public override void OnActionExecuted(ActionExecutedContext filterContext)
        {
            try
            {
                string pnr = string.Empty;
                string orderid = string.Empty;
                Dictionary<string, object> lists = new Dictionary<string, object>();
                try
                {
                    foreach (string item in filterContext.HttpContext.Request.Form.AllKeys)
                    {
                        if (filterContext.HttpContext.Request.Form[item].Trim().Length == 6)
                        {
                            pnr = filterContext.HttpContext.Request.Form[item];
                        }
                        else if (filterContext.HttpContext.Request.Form[item].Trim().Length == 18)
                        {
                            orderid = filterContext.HttpContext.Request.Form[item];
                        }

                        lists.Add(item, filterContext.HttpContext.Request.Form[item]);
                    }
                }
                catch
                {
                }
                finally
                {
                    UiaccParam param = new UiaccParam();
                    param.SysId = "您的网站名称"; // 填写网站名称
                    param.OperId = ((ControllerContext)filterContext).RouteData.Values["controller"].ToString();
                    param.UiId = ((ControllerContext)filterContext).RouteData.Values["action"].ToString();
                    param.UserIP = filterContext.HttpContext.Request.UserHostAddress;
                    param.Pnr = pnr;
                    param.OrderID = orderid;
                    param.UserName = HttpContext.Current.User.Identity.Name;
                    param.DicContext = lists;
                    if (TrackIdManager.CurrentTrackID == null)
                    {
                        TrackIdManager.GetInstance(param.UserName);
                    }

                    this.watch.Stop();
                    param.TimeSpan = this.watch.Elapsed;
                    Better.Infrastructures.Log.LogManager.Log.WriteUiAcc(param);
                }
            }
            catch
            {
            }

            base.OnActionExecuted(filterContext);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 登陆按钮
        /// </summary>
        /// <param name="userID">用户名</param>
        /// <param name="pwd">用户密码</param>
        /// <param name="validateCode">验证码</param>
        /// <returns>结果</returns>
        public JsonResult LoginIndex(string userID, string pwd, string validateCode)
        {
            string errMsg = string.Empty;
            string result = string.Empty;
            try
            {
                if (string.IsNullOrEmpty(userID))
                {
                    result = "请输入用户名!";
                    return this.Json("请输入用户名!");
                }

                if (string.IsNullOrEmpty(pwd))
                {
                    result = "请输入密码!";
                    return this.Json("请输入密码!");
                }

                TrackIdManager.GetInstance(userID);

                if (string.IsNullOrEmpty(validateCode))
                {
                    ////TODO 提示输入验证码
                    result = "请输入验证码!";
                    return this.Json("请输入验证码!");
                }

                string sessionValidateCode = this.Session["validatecode"] == null ? string.Empty : this.Session["validatecode"].ToString();
                if (validateCode.Trim().ToLower() != sessionValidateCode.ToLower())
                {
                    ////TODO 提示验证码输入错误
                    result = "请输入验证码!";
                    return this.Json("验证码错误!");
                }

                ClearCK1Cookie();

                UserLoginServiceHelper.UserLoginServiceHelper userHelper = new UserLoginServiceHelper.UserLoginServiceHelper();

                string message = string.Empty;
                MLogin login = new MLogin();
                login.AccountId = userID;
                login.HostAddress = Request.UserHostAddress;

                MUserLoginInfo loginInfo = new MUserLoginInfo();
                loginInfo.Staff_Id = userID;
                loginInfo.Password = pwd;
                if (userHelper.CommonLogin(loginInfo, ref message, ref login))
                {
                    MStaffInfo staffInfo = userHelper.GetStaffInfoModel(userID);
                    ////登录用户不为平台时限制ip
                    int staffType = staffInfo.StaffType;
                    if (staffType != 1)
                    {
                       if (!userHelper.LimitIpLogin(staffInfo.Department_id, this.GetIpAddr()))
                       {
                           return this.Json("当前登录IP不在允许的登录IP范围内!", "text/html", JsonRequestBehavior.AllowGet);
                       }
                    }

                    //// 平台登陆 
                    if (staffInfo.StaffType != 1)
                    {
                        result = "当前账号无权限!";
                        return this.Json("当前账号无权限");
                    }

                    //// 登录成功,创建本地票据
                    this.SetLocalTicket(staffInfo);

                    //// TODO 保存用户对象
                    this.Session["$sessionName$_UserInfo"] = staffInfo;

                    FormsAuthentication.SetAuthCookie(userID, false);
                    result = "登陆成功";
                    return this.Json(result);
                }
                else
                {
                    result = "用户名或密码错误!";
                    return this.Json(result);
                }
            }
            catch (AppException app)
            {
                errMsg = app.Message;
                result = errMsg;
            }
            catch (Exception ex)
            {
                AppException app = new AppException(string.Empty, ex.Message, ex, null);
                LogManager.Log.WriteException(app);
                errMsg = app.Message;
                result = errMsg;
            }
            finally
            {
                string addr = string.Empty;
                try
                {
                    addr = IpLocator.GetIpLocation(System.Configuration.ConfigurationManager.AppSettings["IPFile"], this.GetIpAddr()).Country;
                }
                catch
                {
                }

                UiaccParam param = new UiaccParam();
                param.SysId = "您的网站名称";
                param.OperId = "登录";
                param.UiId = "点击登录按钮";
                param.UserIP = this.GetIpAddr();
                param.UserName = userID;
                param.KeyMessage = "您的网站名称用户登录" + "用户ID:" + userID + "登录结果:" + result + "登录域名:" + HttpContext.Request.Url.Authority + " 登录城市:" + addr;
                if (TrackIdManager.CurrentTrackID == null)
                {
                    TrackIdManager.GetInstance(param.UserName);
                }

                this.watch.Stop();
                param.TimeSpan = this.watch.Elapsed;
                Better.Infrastructures.Log.LogManager.Log.WriteUiAcc(param);
            }

            if (!string.IsNullOrEmpty(errMsg))
            {
                return this.Json("用户名或密码错误!");
            }

            return this.Json(string.Empty);
        }