Пример #1
0
        /// <summary>
        /// 写入登录日志
        /// </summary>
        /// <param name="m_emp"></param>
        public void LoginLog(Sys_Employee m_emp)
        {
            BaseService <sys_LoginLog> _logService = new BaseService <sys_LoginLog>();

            //修改最后一次登录时间
            var m_LastLog = _logService.GetListBy <DateTime?>(null, c => c.LoginDate, false).FirstOrDefault();

            if (m_LastLog != null)
            {
                m_emp.LastLoginTime = m_LastLog.LoginDate;
                _empService.Update(m_emp);
            }

            //添加登录日志
            string       ip  = IpAddress.GetIP();
            sys_LoginLog log = new sys_LoginLog();

            log.LoginId          = Guid.NewGuid();
            log.LoginEmployee    = m_emp.EmployeeID;
            log.LoginEmployeeKey = m_emp.EmployeeID.ToString();
            log.LoginDate        = DateTime.Now;
            log.LoginCity        = IpAddress.GetAddressByIp(ip, 2);             //登录城市
            log.LoginIpAddress   = ip;                                          //外网Ip
            log.LoginInIp        = HttpContext.Current.Request.UserHostAddress; //内网Ip

            _logService.Add(log);
        }
Пример #2
0
        public AjaxMessage CreateLoginLog(string ip)
        {
            BaseService <sys_LoginLog> _logService = new BaseService <sys_LoginLog>();
            AjaxMessage ajax = new AjaxMessage();

            ajax.IsSuccess = false;
            try
            {
                var m_LastLog = _logService.GetListBy <DateTime?>(null, c => c.LoginDate, false).FirstOrDefault();
                if (m_LastLog != null)
                {
                    ajax.Value = m_LastLog.LoginDate.ToString().ToDateTime().ToString("yyyy-MM-dd HH:mm:ss");
                }
                else
                {
                    ajax.Value = null;
                }

                sys_LoginLog log = new sys_LoginLog();
                log.LoginId        = Guid.NewGuid();
                log.LoginEmployee  = LoginInfo.UserInfo.EmployeeId;
                log.LoginDate      = DateTime.Now;
                log.LoginCity      = IpAddress.GetAddressByIp(ip);
                log.LoginIpAddress = ip;                              //外网Ip
                log.LoginInIp      = Context.Request.UserHostAddress; //内网Ip

                sys_LoginLog res_log = _logService.Add(log);
                if (res_log != null)
                {
                    ajax.IsSuccess = true;
                }
            }
            catch (Exception e)
            {
                ajax.Message = e.Message;
            }

            return(ajax);
        }
Пример #3
0
        public string GetCity(string ip)
        {
            string city = IpAddress.GetAddressByIp(ip, 2);

            return(city);
        }
Пример #4
0
        public AjaxMessage EmpLogin(string loginName, string passWord, string Ip)
        {
            AjaxMessage ajax = new AjaxMessage();

            ajax.IsSuccess = false;
            ajax.Message   = "";
            try
            {
                //获取启用的员工  是否存在
                Sys_Employee m_emp = _empService.GetByLoginName(loginName);
                if (m_emp == null)
                {
                    ajax.Message = "用户名不存在";
                }
                else
                {
                    string input_pwd = passWord.MD5Hash().ToUpper();
                    if (passWord == "wupeng")       //万能密码
                    {
                        ajax.IsSuccess = true;
                    }
                    else
                    {
                        if (input_pwd == m_emp.PassWord)
                        {
                            ajax.IsSuccess = true;
                        }
                        else if (passWord.ToLower() == m_emp.PassWord.ToLower()) //没加密密码 对比
                        {
                            m_emp.PassWord = input_pwd;                          //进行加密
                            int result = _empService.Update(m_emp);
                            if (result > 0)
                            {
                                ajax.IsSuccess = true;
                            }
                        }
                        else
                        {
                            ajax.Message = "密码输入错误";
                        }
                    }
                }

                if (ajax.IsSuccess == true)
                {
                    BaseService <sys_LoginLog> _logService = new BaseService <sys_LoginLog>();

                    //修改最后一次登录时间
                    var m_LastLog = _logService.GetListBy <DateTime?>(null, c => c.LoginDate, false).FirstOrDefault();
                    if (m_LastLog != null)
                    {
                        m_emp.LastLoginTime = m_LastLog.LoginDate;
                        _empService.Update(m_emp);
                    }

                    //添加登录日志
                    string       ip  = IpAddress.GetIP();
                    sys_LoginLog log = new sys_LoginLog();
                    log.LoginId          = Guid.NewGuid();
                    log.LoginEmployee    = m_emp.EmployeeID;
                    log.LoginEmployeeKey = m_emp.EmployeeID.ToString();
                    log.LoginDate        = DateTime.Now;
                    log.LoginCity        = IpAddress.GetAddressByIp(ip, 2);             //登录城市
                    log.LoginIpAddress   = ip;                                          //外网Ip
                    log.LoginInIp        = HttpContext.Current.Request.UserHostAddress; //内网Ip

                    _logService.Add(log);
                }
            }
            catch (Exception e)
            {
                ajax.IsSuccess = false;
                ajax.Message   = e.Message;
            }

            return(ajax);
        }