Exemple #1
0
        public IEnumerable <Models.LoginLog> Get(string user)
        {
            try{
                MySqlConnection conexion = new MySqlConnection(connectionString);
                conexion.Open();

                MySqlCommand cmd = new MySqlCommand();
                cmd.Connection  = conexion;
                cmd.CommandText = "SELECT (dayofweek(date)+5)%7+1 dayofweek, user, UNIX_TIMESTAMP(date) as date  FROM bitacora WHERE user='******' AND yearweek(DATE(date), 1) = yearweek(curdate(), 1)";


                Models.LoginLog usr1 = new Models.LoginLog();
                ListaUsuarios = new List <Models.LoginLog>();
                using (var reader = cmd.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        usr1           = new Models.LoginLog();
                        usr1.user      = reader["user"].ToString();
                        usr1.timestamp = reader["date"].ToString();

                        ListaUsuarios.Add(usr1);
                    }
                }
                conexion.Dispose();
                return(ListaUsuarios);
            }catch (Exception e) {
                return(Enumerable.Range(1, 1).Select(index => new Models.LoginLog
                {
                    user = "******" + e.ToString(),
                }).ToArray());
            }
        }
Exemple #2
0
        /// <summary>
        ///根据id修改一条数据(返)修改结果)
        /// </summary>
        public bool Update(Models.LoginLog Models)
        {
            string sqlStr = " update [MS_LoginLog] set LOGIN_ID=@LOGIN_ID,LOGIN_PWD=@LOGIN_PWD,GUID=@GUID,IP_ADDRESS=@IP_ADDRESS,CITY=@CITY,SUCCESS=@SUCCESS,STATE=@STATE where id = @id";

            using (var connection = new ConnectionCode().GetConnection())
            {
                return(connection.Execute(sqlStr, Models) > 0);
            }
        }
Exemple #3
0
        /// <summary>
        ///添加一条数据(返)插入的数据的id)
        /// </summary>
        public int Add(Models.LoginLog Models)
        {
            string sqlStr = " insert into [MS_LoginLog](LOGIN_ID,LOGIN_PWD,GUID,IP_ADDRESS,CITY,SUCCESS,STATE) values(@LOGIN_ID,@LOGIN_PWD,@GUID,@IP_ADDRESS,@CITY,@SUCCESS,@STATE);select @@identity ";

            using (var connection = new ConnectionCode().GetConnection())
            {
                return(connection.Query <int>(sqlStr, Models).SingleOrDefault());
            }
        }
Exemple #4
0
        public ActionResult Login(string userid, string password)
        {
            loginNumber++;
            #region 判断近期登陆次数
            if (loginNumber > 3)
            {
                TimeSpan ts = TimeSpan.Parse("00:15:00.000");
                if (TimeSpan.Compare(DateTime.Now - lastTime, ts) == -1)
                {
                    lastTime = DateTime.Now;
                    return(Json(new { code = 1, msg = "登陆过于频繁" }));
                }
                else
                {
                    loginNumber = 0;
                }
            }
            #endregion

            string uid = MyTools.Tool.GetAppSetting("UserName");
            string pwd = MyTools.Tool.GetTxt(MyTools.Tool.GetAppSetting("Pwd"));
            #region 查询登陆的物理地址
            string          city     = ApiBLL.IpCityBLL.GetIpCityStr(HttpContext.Request.UserHostAddress);
            Models.LoginLog logModel = new Models.LoginLog {
                LOGIN_ID   = uid,
                LOGIN_PWD  = pwd,
                GUID       = "Unknown",
                IP_ADDRESS = HttpContext.Request.UserHostAddress,
                CITY       = string.IsNullOrEmpty(city) ? "Unknown" : city,
                SUCCESS    = 1,
                STATE      = 0
            };
            #endregion

            int id = BLL.LoginBLL.AddLog(logModel);

            #region 验证登陆
            if (uid == userid && MyTools.Helper.MD5(password + "Lin", true) == pwd)
            {
                Dictionary <string, string> dic = new Dictionary <string, string>();
                dic.Add("uid", uid);
                dic.Add("guid", MyTools.Tool.GetAppSetting("Guid"));
                dic.Add("name", "Moli");
                dic.Add("LoginTime", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
                Session["adminLin"] = dic;
                loginNumber         = 0;
                BLL.LoginBLL.UpdateLog(id);
                return(Json(new { status = "success", code = 0, model = "登陆成功" }));
            }
            else
            {
                return(Json(new { code = 1, msg = "账号或密码错误" }));
            }
            #endregion
        }
Exemple #5
0
 static public int AddLog(Models.LoginLog model)
 {
     try {
         return(logdal.Add(model));
     }
     catch (Exception ex)
     {
         Error_msg = ex.Message;
         BaseBLL.ErrorLog("添加登陆日志时发生错误", "BLL->ClassBLL->GetClassList", ex);
         return(0);
     }
 }