Пример #1
0
 public UsersEntity GetPartUserByUidAndPwd(Guid uid)
 {
     UsersEntity entity = new UsersEntity();
     entity = UsersDAL.GetUsersEntityByID(uid, null);
     if (entity != null)
         return entity;
     else
         return null;
 }
Пример #2
0
 protected void Session_End(object sender, EventArgs e)
 {
     var user = new UsersEntity();
     if (Session["User"] != null) {
         user = Session["User"] as UsersEntity;
     }
     UsersBLL uBll = new UsersBLL();
     if (user != null)
     {
         user.IsOnline = 0;
         uBll.Update(user, null);
     }
 }
Пример #3
0
        public JsonResult LoadUserTalk(string uid)
        {
            List<ChatContent> chats = new List<ChatContent>();
            string to = string.Empty;
            UsersEntity user = new UsersEntity();
            ChatBLL cbll = new ChatBLL();
            if (Session["User"] != null)
            {
                user = Session["User"] as UsersEntity;
                //uid ==fromuid ,user.id ==currentuser
                chats = cbll.GetUserChat(uid,user.Id);
            }

               return this.Json(chats, JsonRequestBehavior.AllowGet);
        }
Пример #4
0
        public ActionResult DoLogin(LoginModel users)
        {
            try
            {
                var loginName = WebHelper.GetFormString("loginName", string.Empty);
                var password = WebHelper.GetFormString("password", string.Empty);
                UsersBLL bll = new UsersBLL();
                var user = new UsersEntity();
                //首先判断是邮箱还是电话:
                if (ValidateHelper.IsEmail(loginName))
                {
                    user = bll.GetUsersEntityByEmail1(loginName, null).TData;
                }
                else
                {
                    if (ValidateHelper.IsPhone(loginName))
                    {
                        user = bll.GetUsersEntityByMobile1(loginName, null).TData;
                    }
                    else
                    {
                        return Content("<script>alert('请输入正确的邮箱或者电话号码!!');location.href = '/shop/admin/login';</script>");

                    }
                }
                if (user != null && user.Password.Equals(SecurityUtil.HashPassword(password)))
                {
                    //统一存cookie
                    ShopUtils.SetUserCookie(user, 2);
                    Session["User"] = user;
                    user.IsOnline = 1;
                    bll.Update(user, null);
                    return Content("<script>location.href = '/shop/admin/pass';</script>");

                }

                else
                    return Content("<script>alert('用户名或密码不正确!!');location.href = '/shop/admin/login';</script>");

            }
            catch (Exception ex)
            {
                return Content("<script>alert('登陆出错!!');location.href = '/shop/admin/login';</script>");

                throw;
            }
        }
Пример #5
0
        public ActionResult Login()
        {
            try
            {
                var loginName = WebHelper.GetFormString("loginName", string.Empty);
                var password = WebHelper.GetFormString("password", string.Empty);
                UsersBLL bll = new UsersBLL();
                var user = new UsersEntity();
                //首先判断是邮箱还是电话:
                if (ValidateHelper.IsEmail(loginName))
                {
                    user = bll.GetUsersEntityByEmail(loginName, null).TData;
                }
                else
                {
                    if (ValidateHelper.IsPhone(loginName))
                    {
                        user = bll.GetUsersEntityByMobile(loginName, null).TData;
                    }
                    else
                    {
                        return AjaxResult("valicationErr", "请输入正确的邮箱或者电话号码!!", false);
                    }
                }
                if (user != null && user.Password.Equals(SecurityUtil.HashPassword(password)))
                {
                    //统一存cookie
                    ShopUtils.SetUserCookie(user, 2);
                    Session["User"] = user;
                    user.IsOnline = 1;
                    bll.Update(user,null);

                    return AjaxResult("success", "登录成功!!", false);
                }

                else
                    return AjaxResult("error", "用户名或密码不正确!!", false);
            }
            catch (Exception ex)
            {
                return AjaxResult("error", ex.ToString(), false);
                throw;
            }
        }
Пример #6
0
        /// <summary>
        /// 实体集合Reader
        /// </summary>
        /// <returns>实体集合</returns>
        protected static List<UsersEntity> GetBindTDataList(SqlDataReader dataReader)
        {
            List< UsersEntity> usersList = new List< UsersEntity>();

            while (dataReader.Read())
            {
                 UsersEntity usersEntity = new  UsersEntity();

                if (dataReader["Id"] != DBNull.Value)
                {
                usersEntity.Id = new Guid(dataReader["Id"].ToString());
                }
                if (dataReader["Email"] != DBNull.Value)
                {
                usersEntity.Email = Convert.ToString(dataReader["Email"]);
                }
                if (dataReader["NickName"] != DBNull.Value)
                {
                usersEntity.NickName = Convert.ToString(dataReader["NickName"]);
                }
                if (dataReader["Password"] != DBNull.Value)
                {
                usersEntity.Password = Convert.ToString(dataReader["Password"]);
                }
                if (dataReader["Contactqq"] != DBNull.Value)
                {
                usersEntity.Contactqq = Convert.ToString(dataReader["Contactqq"]);
                }
                if (dataReader["Contactaddr"] != DBNull.Value)
                {
                usersEntity.Contactaddr = Convert.ToString(dataReader["Contactaddr"]);
                }
                if (dataReader["UserName"] != DBNull.Value)
                {
                usersEntity.UserName = Convert.ToString(dataReader["UserName"]);
                }
                if (dataReader["Mobile"] != DBNull.Value)
                {
                usersEntity.Mobile = Convert.ToString(dataReader["Mobile"]);
                }
                if (dataReader["avatar"] != DBNull.Value)
                {
                usersEntity.Avatar = Convert.ToString(dataReader["avatar"]);
                }
                if (dataReader["RankCredits"] != DBNull.Value)
                {
                usersEntity.RankCredits = Convert.ToInt32(dataReader["RankCredits"]);
                }
                if (dataReader["IsOnline"] != DBNull.Value)
                {
                usersEntity.IsOnline = Convert.ToByte(dataReader["IsOnline"]);
                }
                if (dataReader["AddTime"] != DBNull.Value)
                {
                usersEntity.AddTime = Convert.ToDateTime(dataReader["AddTime"]);
                }
                if (dataReader["HeadImage"] != DBNull.Value)
                {
                usersEntity.HeadImage = Convert.ToString(dataReader["HeadImage"]);
                }
                if (dataReader["HeadSmallImage"] != DBNull.Value)
                {
                usersEntity.HeadSmallImage = Convert.ToString(dataReader["HeadSmallImage"]);
                }

                usersList.Add(usersEntity);
            }

            dataReader.Close();
            dataReader.Dispose();

            return usersList;
        }
Пример #7
0
        /// <summary>
        /// 更新
        /// </summary>
        /// <param name="usersEntity">实体</param>
        /// <param name="tran">事务</param>
        /// <returns>是否成功</returns> 
        public static bool Update( UsersEntity usersEntity , SqlTransaction tran)
        {
            List<SqlParameter> parameters = new List<SqlParameter>();

                parameters.Add(SqlServerHelper.CreateInputParameter("@Id", SqlDbType.UniqueIdentifier, usersEntity.Id));
                parameters.Add(SqlServerHelper.CreateInputParameter("@Email", SqlDbType.Char, usersEntity.Email));
                parameters.Add(SqlServerHelper.CreateInputParameter("@NickName", SqlDbType.NChar, usersEntity.NickName));
                parameters.Add(SqlServerHelper.CreateInputParameter("@Password", SqlDbType.Char, usersEntity.Password));
                parameters.Add(SqlServerHelper.CreateInputParameter("@Contactqq", SqlDbType.Char, usersEntity.Contactqq));
                parameters.Add(SqlServerHelper.CreateInputParameter("@Contactaddr", SqlDbType.Char, usersEntity.Contactaddr));
                parameters.Add(SqlServerHelper.CreateInputParameter("@UserName", SqlDbType.NChar, usersEntity.UserName));
                parameters.Add(SqlServerHelper.CreateInputParameter("@Mobile", SqlDbType.Char, usersEntity.Mobile));
                parameters.Add(SqlServerHelper.CreateInputParameter("@avatar", SqlDbType.Char, usersEntity.Avatar));
                parameters.Add(SqlServerHelper.CreateInputParameter("@RankCredits", SqlDbType.Int, usersEntity.RankCredits));
                parameters.Add(SqlServerHelper.CreateInputParameter("@IsOnline", SqlDbType.TinyInt, usersEntity.IsOnline));
                parameters.Add(SqlServerHelper.CreateInputParameter("@AddTime", SqlDbType.DateTime, usersEntity.AddTime));
                parameters.Add(SqlServerHelper.CreateInputParameter("@HeadImage", SqlDbType.NVarChar, usersEntity.HeadImage));
                parameters.Add(SqlServerHelper.CreateInputParameter("@HeadSmallImage", SqlDbType.NVarChar, usersEntity.HeadSmallImage));

            if (tran == null)
            {
                SqlServerHelper.ExecuteNonQuery(CommandType.Text, SqlUpdate, parameters.ToArray());
                return true;
            }

            SqlServerHelper.ExecuteNonQuery(tran, CommandType.Text, SqlUpdate, parameters.ToArray());
            return true;
        }
Пример #8
0
        /// <summary>
        /// 创建
        /// </summary>
        /// <param name="usersEntity">实体</param>
        /// <param name="tran">事务</param>
        /// <returns>是否成功</returns> 
        public static Guid InsertReturnID( UsersEntity usersEntity , SqlTransaction tran)
        {
            List<SqlParameter> parameters = new List<SqlParameter>();

                parameters.Add(SqlServerHelper.CreateInputParameter("@Email", SqlDbType.Char, usersEntity.Email));
                parameters.Add(SqlServerHelper.CreateInputParameter("@NickName", SqlDbType.NChar, usersEntity.NickName));
                parameters.Add(SqlServerHelper.CreateInputParameter("@Password", SqlDbType.Char, usersEntity.Password));
                parameters.Add(SqlServerHelper.CreateInputParameter("@Contactqq", SqlDbType.Char, usersEntity.Contactqq));
                parameters.Add(SqlServerHelper.CreateInputParameter("@Contactaddr", SqlDbType.Char, usersEntity.Contactaddr));
                parameters.Add(SqlServerHelper.CreateInputParameter("@UserName", SqlDbType.NChar, usersEntity.UserName));
                parameters.Add(SqlServerHelper.CreateInputParameter("@Mobile", SqlDbType.Char, usersEntity.Mobile));
                parameters.Add(SqlServerHelper.CreateInputParameter("@avatar", SqlDbType.Char, usersEntity.Avatar));
                parameters.Add(SqlServerHelper.CreateInputParameter("@RankCredits", SqlDbType.Int, usersEntity.RankCredits));
                parameters.Add(SqlServerHelper.CreateInputParameter("@IsOnline", SqlDbType.TinyInt, usersEntity.IsOnline));
                parameters.Add(SqlServerHelper.CreateInputParameter("@AddTime", SqlDbType.DateTime, usersEntity.AddTime));
                parameters.Add(SqlServerHelper.CreateInputParameter("@HeadImage", SqlDbType.NVarChar, usersEntity.HeadImage));
                parameters.Add(SqlServerHelper.CreateInputParameter("@HeadSmallImage", SqlDbType.NVarChar, usersEntity.HeadSmallImage));

            Guid result = Guid.Empty;

            if (tran == null)
            {
                Guid.TryParse(SqlServerHelper.ExecuteScalar(CommandType.Text, SqlInsertReturnID, parameters.ToArray()).ToString(), out result);
            }
            else
            {
                Guid.TryParse(SqlServerHelper.ExecuteScalar(tran, CommandType.Text, SqlInsertReturnID, parameters.ToArray()).ToString(), out result);
            }

            return result;
        }
Пример #9
0
        /// <summary>
        /// 更新
        /// </summary>
        /// <param name=" usersEntity">实体</param>
        /// <param name="tran">事务</param>
        /// <returns>是否成功</returns> 
		public bool Update( UsersEntity usersEntity , SqlTransaction tran)
		{
            return  UsersDAL.Update(usersEntity, tran);
		}
Пример #10
0
        /// <summary>
        /// 创建
        /// </summary>
        /// <param name=" usersEntity">实体</param>
        /// <param name="tran">事务</param>
        /// <returns>是否成功</returns> 
		public Guid InsertReturnID( UsersEntity usersEntity , SqlTransaction tran)
		{
            return  UsersDAL.InsertReturnID(usersEntity, tran);
		}
Пример #11
0
		/// <summary>
        /// 创建
        /// </summary>
        /// <param name=" usersEntity">实体</param>
        /// <param name="tran">事务</param>
        /// <returns>是否成功</returns> 
		public bool Insert( UsersEntity usersEntity , SqlTransaction  tran)
		{
            return  UsersDAL.Insert(usersEntity, tran);
		}
Пример #12
0
        /// <summary>
        /// 设置用户
        /// </summary>
        /// <param name="uid">用户id</param>
        /// <param name="password">密码</param>
        /// <param name="sid">sid</param>
        /// <param name="expires">过期时间</param>
        public static void SetUserCookie(UsersEntity partUserInfo, int expires)
        {
            HttpCookie cookie = HttpContext.Current.Request.Cookies["bsp"];
            if (cookie == null)
                cookie = new HttpCookie("bsp");

            cookie.Values["uid"] = partUserInfo.Id.ToString();
            cookie.Values["password"] = WebHelper.UrlEncode(AESEncrypt(partUserInfo.Password));
            if (expires > 0)
            {
                cookie.Values["expires"] = expires.ToString();
                cookie.Expires = DateTime.Now.AddDays(expires);
            }
            //string cookieDomain = "";
            //if (cookieDomain.Length != 0)
            //    cookie.Domain = cookieDomain;

            HttpContext.Current.Response.AppendCookie(cookie);
        }
Пример #13
0
        public ActionResult Register(UserRegister userReg)
        {
            BLL.UsersBLL userBll = new BLL.UsersBLL();
            string returnUrl = WebHelper.GetQueryString("returnUrl", string.Empty);
            if (returnUrl.Length <= 0)
                returnUrl = "/";
            //1.0判断用户是否重复:
            if ((userBll.GetUsersEntityByEmail(userReg.Email, null).TData) != null)//
            {
                ModelState.AddModelError("Email", "该邮箱已注册");
            }
            //if (string.IsNullOrWhiteSpace(userReg.Mobile) && (userBll.GetUsersEntityByMobile(userReg.Mobile, null).TData) != null)//
            //{
            //    ModelState.AddModelError("Mobile", "该电话号码已注册");
            //}
            //判断昵称是否重复:
            if (!(userBll.GetListByNickName(userReg.Nickname).IsSuccess))
            {
                ModelState.AddModelError("Nickname", "该昵称已经存在");
            }
            if (ModelState.IsValid)//
            {//2.0保存数据
                var user = new UsersEntity()
                {
                    Email = userReg.Email,
                    Password = SecurityUtil.HashPassword(userReg.Password),
                    Mobile = userReg.Mobile,
                    NickName = userReg.Nickname.Trim(),
                    Contactaddr = userReg.Contactaddr,
                    HeadImage = userReg.ImageUrl,
                    HeadSmallImage = string.Empty,
                    UserName = string.Empty,
                    AddTime = DateTime.Now,
                    Avatar = string.Empty,
                    IsOnline=1,
                    Contactqq = userReg.Contactqq,
                    RankCredits = 0,

                };
                Guid userId = userBll.InsertReturnID(user, null);
                if (!Guid.Empty.Equals(userId))
                {
                    user.Id = userId;
                    //数据存于cookie中
                    //将用户信息写入cookie
                    ShopUtils.SetUserCookie(user, 2);
                    //3.0注册成功跳转
                    WorkContext.Uid = userId;
                    WorkContext.UserEmail = user.Email;
                     Session["User"] = user;
                    return Redirect(returnUrl);
                }
                return AjaxResult("fail", "注册失败!", false);
            }
            return View();
        }
Пример #14
0
        /// <summary>
        /// 说明:初始化调用构造函数后可能不可用的数据。
        /// </summary>
        /// <param name="requestContext"></param>
        protected override void Initialize(RequestContext requestContext)
        {
            base.Initialize(requestContext);
            SpeechInfoBLL bll = new SpeechInfoBLL();
            citys = bll.GetCitys();

            WorkContext.IsHttpAjax = WebHelper.IsAjax();
            WorkContext.Url = WebHelper.GetUrl();
            WorkContext.UrlReferrer = WebHelper.GetUrlReferrer();
            WorkContext.IP = WebHelper.GetIP();
            // WebHelper.GetIP();

            if (string.IsNullOrWhiteSpace(WorkContext.IP) || WorkContext.IP == "127.0.0.1")
            {
                WorkContext.CityName = "重庆市";
            }
            else
            {
                //测试地址搜索#region 测试地址搜索
                IPScaner objScan = new IPScaner();
                string ip = Request.UserHostAddress.ToString();
                objScan.DataPath = Server.MapPath("/App_data/qqwry.Dat");
                objScan.IP = WorkContext.IP;
                //"113.200.29.90";
                string addre = objScan.IPLocation();
                int IndexofA = addre.IndexOf("省") + 1;
                WorkContext.CityName = addre.Substring(IndexofA);
            }
            UsersEntity userInfo = new UsersEntity();
            Guid uid = ShopUtils.GetUidCookie();
            //获得保存在cookie中的密码
            string encryptPwd = ShopUtils.GetCookiePassword();
            UsersBLL userBll = new UsersBLL();
            if (Session["User"] != null)
            {
                CurrentUser = Session["User"] as UsersEntity;
                userInfo = CurrentUser;
            }
            else
            {

                userInfo = userBll.GetPartUserByUidAndPwd(uid);
              //  requestContext.HttpContext.Response.Write("<script>alert('登录超时!');window.location.reload();</script>");
            }

            if (userInfo != null && !Guid.Empty.Equals(userInfo.Id))
            {
                WorkContext.Uid = userInfo.Id;
                WorkContext.Password = userInfo.Password;
                WorkContext.UserEmail = userInfo.Email;
                WorkContext.NickName = string.IsNullOrWhiteSpace(userInfo.NickName) ? userInfo.Email : userInfo.NickName;
            }

            //从cookie中获取用户的基本信息
        }