Example #1
0
        /// <summary>
        /// 检查用户登录
        /// </summary>
        /// <param name="userInfo">用户名</param>
        /// <returns></returns>
        public bool CheckLogin(ViewUserLogin userInfo)
        {
            bool validate = false;

            userInfo.UserPwd = userInfo.UserPwd.GetMD5FromString();
            var userName = StringHelp.FilterSql(userInfo.UserName);
            var userPwd  = StringHelp.FilterSql(userInfo.UserPwd);
            var user     = userBll.FirstOrDefault <Sys_User>(x => x.UserNickName.Equals(userName) && x.Password.Equals(userPwd));

            if (user != null)
            {
                //var session = HttpContext.Session[ConstString.SysUserLoginId];
                //if (session == null)
                //{
                SessionManager.Add(ConstString.SysUserLoginId, user.UserId);
                string browser  = NetworkHelper.GetBrowser();
                string hostIP   = NetworkHelper.GetIp() != "0.0.0.0" ? NetworkHelper.GetIp() : ZHttp.ClientIP;
                string hostName = ZHttp.IsLanIP(ZHttp.ClientIP) ? ZHttp.ClientHostName : string.Empty; //如果是内网就获取,否则出错获取不到,且影响效率
                loginHistoryBLL.AddEntity(Sys_LoginHistory.CreateInstance(user.UserId, hostName, hostIP, userInfo.City, browser));
                SetUserCache(user);
                SetCookie(user.UserId);
                //}
                validate = true;
            }
            return(validate);
        }
Example #2
0
 /// <summary>
 /// 添加登陆记录
 /// </summary>
 /// <param name="userInfo"></param>
 /// <returns></returns>
 public void LoginHistory(string UserId, string City)
 {
     try
     {
         SessionManager.Add(ConstString.SysUserLoginId, UserId);
         string browser      = NetworkHelper.GetBrowser();
         string hostIP       = NetworkHelper.GetIp() != "0.0.0.0" ? NetworkHelper.GetIp() : ZHttp.ClientIP;
         string hostName     = ZHttp.IsLanIP(ZHttp.ClientIP) ? ZHttp.ClientHostName : string.Empty; //如果是内网就获取,否则出错获取不到,且影响效率
         var    loginHistory = Sys_LoginHistory.CreateInstance(UserId, hostName, hostIP, City, browser);
         loginHistoryBLL.AddEntity(loginHistory);
     }
     catch (Exception ex)
     {
         Log.Write(LogLevel.Error, "添加登陆记录日志表出错", ex);
     }
 }