示例#1
0
        /// <summary>
        /// 验证登录用户是否存在
        /// </summary>
        /// <param name="userID"></param>
        /// <param name="password"></param>
        /// <returns></returns>
        public JsonResult CheckLoginAjax(string userID, string password)
        {
            IList list    = new ArrayList();
            Log   userLog = new Log();

            userLog.LOG_UserID     = userID;
            userLog.LOG_FuctionID  = "";
            userLog.LOG_actionType = 1;
            userLog.LOG_actionDate = DateTime.Now;
            userLog.LOG_actionDesc = String.Format("手机登陆");
            var logRepos = LogRepos.LogInstance();

            logRepos.AddLog(userLog);
            //用户名为空返回-1
            if (String.IsNullOrEmpty(userID))
            {
                list.Add(new
                {
                    status = -1,
                });
                return(Json(list, JsonRequestBehavior.AllowGet));
            }
            string encryptPassword = SHA1Encrypt(userID + password);
            var    user            = _userRepos.GetUserByIDAndPassword(userID, encryptPassword);

            //用户名不存在返回0
            if (user == null)
            {
                list.Add(new
                {
                    status = 0,
                });
                return(Json(list, JsonRequestBehavior.AllowGet));
            }
            else
            {
                list.Add(new
                {
                    status = 1,
                });
                return(Json(list, JsonRequestBehavior.AllowGet));
            }
        }
        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            string         controllerName      = filterContext.RouteData.Values["controller"].ToString();
            string         actionName          = filterContext.RouteData.Values["action"].ToString();
            string         controllerActionStr = controllerName + "/" + actionName;
            IList <string> functionLinkList    = filterContext.HttpContext.Session["userFunctionLinks"] as IList <string>;

            if (functionLinkList == null || !functionLinkList.Contains(controllerActionStr)) // 没有权限
            {
                if (!filterContext.HttpContext.Request.IsAjaxRequest())
                {
                    filterContext.Result = new RedirectToRouteResult(new RouteValueDictionary(new { controller = "Shared", action = "NoRight" }));
                }
                else
                {
                    filterContext.Result = new EmptyResult();
                }
            }
            else
            {
                // 记录日志
                var    fullSubFunctionList = filterContext.HttpContext.Session["fullSubFunctionList"] as IList <Function>;
                var    function            = fullSubFunctionList.Where(x => x.FN_LinkLocation == controllerActionStr).FirstOrDefault();
                string funcionId           = "";
                string functionDesc        = "";
                if (function != null)
                {
                    funcionId    = function.FN_ID;
                    functionDesc = function.FN_Description;
                }
                var    user           = filterContext.HttpContext.Session["loginUser"] as EnergyMonitor.Models.LinqEntity.User;
                var    request        = filterContext.RequestContext.HttpContext.Request;
                string fullRequestUrl = request.Url.PathAndQuery;
                string hostAddress    = request.UserHostAddress;
                string hostName       = request.UserHostName;
                string userAgent      = request.UserAgent;
                string localLoginIP;
                if (request.ServerVariables["HTTP_VIA"] != null)
                {
                    localLoginIP = request.ServerVariables["HTTP_X_FORWARDED_FOR"].ToString();
                }
                else
                {
                    localLoginIP = request.ServerVariables["REMOTE_ADDR"].ToString();
                }
                string desc = String.Format("用户【{0}】操作【{1}】,当前访问本地IP为【{2}】", user.USR_Name, functionDesc, localLoginIP);
                if (hostAddress != localLoginIP)
                {
                    desc += String.Format(",远程IP为【{0}】", hostAddress);
                }
                if (hostName != hostAddress)
                {
                    desc += String.Format(",远程主机名为【{0}】", hostName);
                }
                desc += String.Format(",其他信息【{0}】", userAgent);

                Log userLog = new Log();
                userLog.LOG_UserID     = user.USR_ID;
                userLog.LOG_FuctionID  = funcionId;
                userLog.LOG_actionType = 0;
                userLog.LOG_actionDate = DateTime.Now;
                userLog.LOG_actionDesc = desc;
                var logRepos = LogRepos.LogInstance();
                logRepos.AddLog(userLog);
            }
        }