Beispiel #1
0
        public static int Add(LoginLogInfo entity)
        {
            int result;

            if (entity == null)
            {
                result = 0;
            }
            else
            {
                result = BizBase.dbo.InsertModel <LoginLogInfo>(entity);
            }
            return(result);
        }
Beispiel #2
0
        /// <summary>
        /// 得到一个对象实体
        /// Author 2015-08-11
        /// </summary>
        public LoginLogInfo GetModel(object tran, int LogID)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select LogID,UserID,LoginName,State,LoginIP,IPAddress,LoginTime ");
            strSql.Append(" from LoginLog ");
            strSql.Append(" where LogID=@LogID");
            SqlParameter[] parameters =
            {
                new SqlParameter("@LogID", SqlDbType.Int, 4)
            };
            parameters[0].Value = LogID;


            LoginLogInfo model = new LoginLogInfo();
            DataSet      ds    = SQLHelper.GetDataSet((SqlTransaction)tran, strSql.ToString(), parameters);

            if (ds.Tables[0].Rows.Count > 0)
            {
                if (ds.Tables[0].Rows[0]["LogID"].ToString() != "")
                {
                    model.LogID = int.Parse(ds.Tables[0].Rows[0]["LogID"].ToString());
                }
                if (ds.Tables[0].Rows[0]["UserID"].ToString() != "")
                {
                    model.UserID = int.Parse(ds.Tables[0].Rows[0]["UserID"].ToString());
                }
                if (ds.Tables[0].Rows[0]["LoginName"].ToString() != "")
                {
                    model.LoginName = ds.Tables[0].Rows[0]["LoginName"].ToString();
                }
                if (ds.Tables[0].Rows[0]["State"].ToString() != "")
                {
                    model.State = int.Parse(ds.Tables[0].Rows[0]["State"].ToString());
                }
                model.LoginIP   = ds.Tables[0].Rows[0]["LoginIP"].ToString();
                model.IPAddress = ds.Tables[0].Rows[0]["IPAddress"].ToString();
                if (ds.Tables[0].Rows[0]["LoginTime"].ToString() != "")
                {
                    model.LoginTime = DateTime.Parse(ds.Tables[0].Rows[0]["LoginTime"].ToString());
                }

                return(model);
            }
            else
            {
                return(null);
            }
        }
Beispiel #3
0
        public JsonResult Login(string loginName, string pwd)
        {
            MessageJSON message   = new MessageJSON();
            UsersInfo   usersinfo = usersbll.GetModelByName(loginName, Utility.DESEncrypt.GetMd5Str(pwd));

            if (usersinfo != null)
            {
                if (usersinfo.DeleteMark == 0)
                {
                    //清空验证码
                    Session["verifyCode"] = null;

                    //保存用户登录信息
                    SessionInfo.UserID    = usersinfo.UserID;
                    SessionInfo.UserName  = usersinfo.UserName;
                    SessionInfo.LoginName = usersinfo.LoginName;
                    SessionInfo.IsAdmin   = usersinfo.IsAdmin;

                    //添加登录日志
                    LoginLogInfo loginloginfo = new LoginLogInfo();
                    loginloginfo.UserID    = usersinfo.UserID;
                    loginloginfo.LoginName = usersinfo.LoginName;
                    loginloginfo.State     = 1;
                    loginloginfo.LoginIP   = Request.UserHostAddress;
                    loginloginfo.IPAddress = "";
                    loginlogbll.Add(null, loginloginfo);
                    message = new MessageJSON()
                    {
                        State = MessageState.success, Icon = MessageIcon.yes, Content = "登录成功"
                    };
                }
                else
                {
                    message = new MessageJSON()
                    {
                        State = MessageState.fail, Icon = MessageIcon.no, Content = "用户已被删除"
                    };
                }
            }
            else
            {
                message = new MessageJSON()
                {
                    State = MessageState.fail, Icon = MessageIcon.no, Content = "账户或密码有错误"
                };
            }
            return(Json(message, JsonRequestBehavior.AllowGet));
        }
Beispiel #4
0
        public void AddLoginLog(UserType userType, string strUserName, bool isLogined)
        {
            LoginLogInfo last   = LoginLog.GetLast(userType, strUserName);
            LoginLogInfo entity = new LoginLogInfo
            {
                UserType       = userType.ToString(),
                UserName       = strUserName,
                IPAddress      = IPUtils.GetIP(),
                IPArea         = ((userType == UserType.Manager) ? IPUtils.GetIPAreaFromPcOnline(IPUtils.GetIP()) : string.Empty),
                LoginStatus    = (isLogined ? 1 : 0),
                LoginFailCount = ((!isLogined) ? ((last == null) ? 1 : (last.LoginFailCount + 1)) : 0),
                Lang           = JObject.cultureLang,
                AutoTimeStamp  = DateTime.Now
            };

            LoginLog.Add(entity);
        }
Beispiel #5
0
        /// <summary>
        /// 更新一条数据
        /// Author 2015-08-11
        /// </summary>
        public bool Update(object tran, LoginLogInfo model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("update LoginLog set ");

            strSql.Append("UserID=@UserID,");
            strSql.Append("LoginName=@LoginName,");
            strSql.Append("State=@State,");
            strSql.Append("LoginIP=@LoginIP,");
            strSql.Append("IPAddress=@IPAddress,");
            strSql.Append("LoginTime=@LoginTime");
            strSql.Append(" where LogID=@LogID ");

            SqlParameter[] parameters =
            {
                new SqlParameter("@LogID",     SqlDbType.Int,       4),
                new SqlParameter("@UserID",    SqlDbType.Int,       4),
                new SqlParameter("@LoginName", SqlDbType.VarChar,  50),
                new SqlParameter("@State",     SqlDbType.Int,       4),
                new SqlParameter("@LoginIP",   SqlDbType.VarChar,  20),
                new SqlParameter("@IPAddress", SqlDbType.NVarChar, 50),
                new SqlParameter("@LoginTime", SqlDbType.DateTime)
            };

            parameters[0].Value = model.LogID;
            parameters[1].Value = model.UserID;
            parameters[2].Value = model.LoginName;
            parameters[3].Value = model.State;
            parameters[4].Value = model.LoginIP;
            parameters[5].Value = model.IPAddress;
            parameters[6].Value = model.LoginTime;
            int rows = SQLHelper.ExecuteNonQuery((SqlTransaction)tran, strSql.ToString(), parameters);

            if (rows > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Beispiel #6
0
        /// <summary>
        /// 增加一条数据
        /// Author 2015-08-11
        /// </summary>
        public bool Add(object tran, LoginLogInfo model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("insert into LoginLog(");
            strSql.Append("UserID,LoginName,State,LoginIP,IPAddress,LoginTime");
            strSql.Append(") values (");
            strSql.Append("@UserID,@LoginName,@State,@LoginIP,@IPAddress,@LoginTime");
            strSql.Append(") ");
            SqlParameter[] parameters =
            {
                new SqlParameter("@UserID",    SqlDbType.Int,       4),
                new SqlParameter("@LoginName", SqlDbType.VarChar,  50),
                new SqlParameter("@State",     SqlDbType.Int,       4),
                new SqlParameter("@LoginIP",   SqlDbType.VarChar,  20),
                new SqlParameter("@IPAddress", SqlDbType.NVarChar, 50),
                new SqlParameter("@LoginTime", SqlDbType.DateTime)
            };

            parameters[0].Value = model.UserID;
            parameters[1].Value = model.LoginName;
            parameters[2].Value = model.State;
            parameters[3].Value = model.LoginIP;
            parameters[4].Value = model.IPAddress;
            parameters[5].Value = model.LoginTime;
            int rows = SQLHelper.ExecuteNonQuery((SqlTransaction)tran, strSql.ToString(), parameters);

            if (rows > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
        public LoginOutput Login(LoginInput loginInput)
        {
            IQueryable <UserInfo>       infos       = _dbContext.Set <UserInfo>();
            IQueryable <UserType>       types       = _dbContext.Set <UserType>();
            IQueryable <DepartmentInfo> departments = _dbContext.Set <DepartmentInfo>();
            IQueryable <RoleInfo>       roleInfos   = _dbContext.Set <RoleInfo>();
            IQueryable <RUserRoleInfo>  userRoles   = _dbContext.Set <RUserRoleInfo>();
            string   password = MD5Helper.EncryptString(loginInput.Password);
            UserInfo user     = infos.Where(u => u.UserId == loginInput.UserId && u.Password == password && u.DelFlag == false).FirstOrDefault();

            if (user != null)
            {
                IEnumerable <string> roleName = (from a in userRoles
                                                 join b in roleInfos on a.RoleId equals b.RoleId into join_a
                                                 from c in join_a.DefaultIfEmpty()
                                                 where a.UserId == user.UserId
                                                 select new
                {
                    c.RoleName
                }).Select(s => s.RoleName).ToList();
                IEnumerable <string> roleId = (from a in userRoles
                                               join b in roleInfos on a.RoleId equals b.RoleId into join_a
                                               from c in join_a.DefaultIfEmpty()
                                               where a.UserId == user.UserId
                                               select new
                {
                    c.RoleId
                }).Select(s => s.RoleId).ToList();
                string userType       = types.Where(t => t.Id == user.UserTypeId).Select(s => s.TypeName).FirstOrDefault();
                string departmentName = departments.Where(d => d.DepartmentId == user.DepartmentId).Select(s => s.DepartmentName).FirstOrDefault();
                //if (string.IsNullOrEmpty(departmentName))
                //{
                //    departmentName = "";
                //}
                LoginOutput outputs = new LoginOutput
                {
                    Id             = user.Id,
                    UserTypeName   = userType,
                    DepartmentId   = user.DepartmentId,
                    DepartmentName = departmentName,
                    Email          = user.Email,
                    Tel            = user.Tel,
                    AddTime        = user.AddTime,
                    DelFlag        = user.DelFlag,
                    EnterpriseName = user.EnterpriseName,
                    Gender         = user.Gender,
                    Token          = user.Token,
                    UserId         = user.UserId,
                    UserName       = user.UserName,
                    RoleName       = roleName,
                    RoleId         = roleId
                };
                LoginLogInfo loginSuccessLog = new LoginLogInfo
                {
                    UserId         = loginInput.UserId,
                    Ip             = loginInput.IP,
                    BrowserInfo    = loginInput.BrowerInfo,
                    SystemInfo     = loginInput.OSVersion,
                    IsLoginSuccess = true,
                    HappenTime     = DateTime.Now
                };
                _dbContext.Set <LoginLogInfo>().Add(loginSuccessLog);
                if (_dbContext.SaveChanges() > 0)
                {
                    return(outputs);
                }
                return(null);
            }
            LoginLogInfo loginFaildLog = new LoginLogInfo
            {
                UserId         = loginInput.UserId,
                Ip             = loginInput.IP,
                BrowserInfo    = loginInput.BrowerInfo,
                SystemInfo     = loginInput.OSVersion,
                IsLoginSuccess = false,
                HappenTime     = DateTime.Now
            };

            _dbContext.Set <LoginLogInfo>().Add(loginFaildLog);
            _dbContext.SaveChanges();
            return(null);
        }
Beispiel #8
0
 public static bool Update(LoginLogInfo entity)
 {
     return(entity != null && BizBase.dbo.UpdateModel <LoginLogInfo>(entity));
 }
Beispiel #9
0
 /// <summary>
 /// 更新一条数据
 /// Author 2015-08-11
 /// </summary>
 public bool Update(object tran, LoginLogInfo model)
 {
     return(dal.Update(tran, model));
 }
Beispiel #10
0
 /// <summary>
 /// 增加一条数据
 /// Author 2015-08-11
 /// </summary>
 public bool Add(object tran, LoginLogInfo model)
 {
     return(dal.Add(tran, model));
 }
 public long Save(LoginLogInfo loginLogInfo)
 {
     base.Save(loginLogInfo);
     return(loginLogInfo.ID.Value);
 }
Beispiel #12
0
        public static LoginStatus UserLogin(string strLoginName, string strEncryPassword, ref UserInfo userRef)
        {
            SqlParameter[] arrParam = new SqlParameter[]
            {
                new SqlParameter("@loginname", strLoginName)
            };
            userRef = BizBase.dbo.GetModel <UserInfo>(BizBase.dbo.ExecProcReReader("p_System_UserLogin", arrParam));
            LoginLogInfo last = LoginLog.GetLast(UserType.User, strLoginName);
            LoginStatus  result;

            if (userRef == null)
            {
                result = LoginStatus.UserNameIncorrect;
            }
            else if (last != null && last.LoginFailCount >= ConfigProvider.Configs.TryLoginTimes && (DateTime.Now - last.AutoTimeStamp).TotalMinutes < 5.0)
            {
                result = LoginStatus.MutilLoginFail;
            }
            else if (strEncryPassword != userRef.Password)
            {
                new LogManager().AddLoginLog(UserType.User, strLoginName, false);
                result = LoginStatus.PasswordIncorrect;
            }
            else if (userRef.Status != 99)
            {
                result = LoginStatus.StatusNotAllow;
            }
            else
            {
                HttpCookie httpCookie = new HttpCookie("singoouser");
                httpCookie.Values["uid"]      = userRef.AutoID.ToString();
                httpCookie.Values["uname"]    = HttpUtility.UrlEncode(userRef.UserName);
                httpCookie.Values["nickname"] = HttpUtility.UrlEncode(userRef.NickName);
                httpCookie.Values["pwd"]      = HttpUtility.UrlEncode(DEncryptUtils.DESEncode(userRef.Password));
                string cookieTime = ConfigProvider.Configs.CookieTime;
                if (cookieTime != null)
                {
                    if (!(cookieTime == "一周"))
                    {
                        if (cookieTime == "一年")
                        {
                            httpCookie.Expires = DateTime.Now.AddYears(1);
                        }
                    }
                    else
                    {
                        httpCookie.Expires = DateTime.Now.AddDays(7.0);
                    }
                }
                HttpContext.Current.Response.Cookies.Add(httpCookie);
                userRef.LoginCount++;
                userRef.LastLoginIP   = IPUtils.GetIP();
                userRef.LastLoginTime = DateTime.Now;
                if (string.IsNullOrEmpty(userRef.Province))
                {
                    TaoBaoAreaInfo iPAreaFromTaoBao = IPUtils.GetIPAreaFromTaoBao(IPUtils.GetIP());
                    if (iPAreaFromTaoBao != null)
                    {
                        userRef.Country  = iPAreaFromTaoBao.data.country;
                        userRef.Province = iPAreaFromTaoBao.data.region;
                        userRef.City     = iPAreaFromTaoBao.data.city;
                        userRef.County   = iPAreaFromTaoBao.data.county;
                    }
                }
                User.Update(userRef);
                new LogManager().AddLoginLog(UserType.User, strLoginName, true);
                result = LoginStatus.Success;
            }
            return(result);
        }