Beispiel #1
0
 public bool AddNew(Member member)
 {
     try
     {
         db.Members.Add(member);
         db.SaveChanges();
         return true;
     }
     catch
     {
         return false;
     }
 }
Beispiel #2
0
        /// <summary>
        /// 保存用户信息 
        /// </summary>
        /// <param name="context"></param>
        public string SaveMemberInfo()
        {
            string errorString = bll.WriteJsonForReturn(false, "");
            try
            {
                //表单读取
                string txtUserName = Request["txtUserName"];
                string txtPwd = Request["txtPwd"];
                string txtEmail = Request["txtEmail"];
                string txtCheckCode = Request["txtCheckCode"];
                //验证码校验
                //if (!txtCheckCode.Equals(Session["checkcode"].ToString()))
                //{
                //    Response.Write(bll.WriteJsonForReturn(false, ""));
                //}
                //字符串sql注入检测
                if (Tools.IsValidInput(ref txtUserName, true) && Tools.IsValidInput(ref txtPwd, true) && Tools.IsValidInput(ref txtEmail, true))
                {
                    Member info = new Member();
                    info.UserName = txtUserName;
                    info.Password = Tools.GetMD5(txtPwd);
                    info.Email = txtEmail;
                    info.States = "0";

                    //加随机验证码
                    info.VCode = Guid.NewGuid().ToString("N");
                    //验证失效(1小时以内激活有效)
                    info.VTime = DateTime.Now.AddHours(1);

                    //验证用户名
                    if (!bll.CheckExistUserName(info.UserName))
                    {
                        return errorString;
                    }
                    if (bll.AddNew(info))
                    {
                        string activationUrl = Request.Url.Scheme + "://" + Request.Url.Authority + System.Web.VirtualPathUtility.ToAbsolute("~/Member/EmailChecking") + "?UserName="******"&YZM=" + info.VCode;
                        string body = "尊敬的" + info.UserName + "用户:请点击些链接激活:";
                        body += "<a href=" + activationUrl + ">" + activationUrl + "</a>";

                        //    SMTP smtp = new SMTP(info.Email);
                        //if (smtp.sendemail("用户激活",body))

                        RogerSMTP roger = new RogerSMTP(info.Email, "会员激活", body);
                        if (roger.Send())
                        {
                            return bll.WriteJsonForReturn(true, Tools.GetEmail(info.Email));
                        }
                        else
                        {
                            return errorString;
                        }
                        //SMTP smtp = new SMTP(info.Email);
                        ////激活网址生成
                        //string webpath = Request.Url.Scheme + "://" + Request.Url.Authority + System.Web.VirtualPathUtility.ToAbsolute("~/Member/EmailChecking.aspx") + "?UserName="******"&YZM=" + info.VCode;
                        ////发送激活邮件
                        //if (smtp.Activation(webpath, info.UserName))
                        //{
                        //    return bll.WriteJsonForReturn(true, Tools.GetEmail(info.Email));

                        //}
                        //else
                        //{
                        //    return errorString;
                        //}
                    }
                    else
                    {
                        return errorString;
                    }
                }
                else
                {
                    return errorString;
                }
            }
            catch (Exception ex)
            {
                //logger.Error("错误!", ex);
                return errorString;
            }
        }
Beispiel #3
0
 /// <summary>
 /// 用户登录
 /// </summary>
 /// <param name="info">会员model</param>
 /// <returns></returns>
 public bool MemberLogin(Member info)
 {
     return db.Members.Count(s => s.UserName == info.UserName && s.Password == info.Password && s.States == "1") > 0;
 }
Beispiel #4
0
        //避免与上面MemberLogin重名出错
        public string MemberAjaxLogin()
        {
            try
            {
                //获取数据
                string Name = Request["Name"];
                string Pwd = Request["Pwd"];
                string IsSaveName = Request["cbName"];
                string IsSavePwd = Request["cbPwd"];
                //用户登录状态
                bool Status = false;
                //返回给客户端的json数据
                string ReturnJson = "";
                //sql注入检测
                if (Tools.IsValidInput(ref Name, true) && (Tools.IsValidInput(ref Pwd, true)) && (Tools.IsValidInput(ref IsSaveName, true)) && (Tools.IsValidInput(ref IsSavePwd, true)))
                {
                    Member info = new Member();
                    MemberBLL bll = new MemberBLL();
                    info.UserName = Name;
                    info.Password = Pwd;
                    ReturnJson = bll.ReturnJson(info, out Status);
                    if (Status) //如果成功登陆
                    {
                        //记住帐号和密码
                        bll.RememberUserInfo(info, bll.GetRememberType(IsSaveName, IsSavePwd));

                        //保存登录状态
                        Session["UserName"] = info.UserName;
                        //如果登录成功,则把用户ID放在Session中
                        if (Tools.IsNullOrEmpty(Session["UserId"]))
                        {
                            Session["UserId"] = bll.GetMemberId(info.UserName);
                        }
                    }
                }

                return ReturnJson;
            }
            catch (Exception ex)
            {
                //logger.Error("会员登录出错!", ex);
                return string.Empty;
            }
        }
Beispiel #5
0
 /// <summary>
 /// 增加member
 /// </summary>
 /// <param name="model">tableName实体</param>
 /// <returns>执行状态</returns>
 public bool AddNew(Member model)
 {
     return mdal.AddNew(model);
 }
Beispiel #6
0
 /// <summary>
 /// 返回给客户端的json格式数据(用于根据用户登录状态决定)
 /// </summary>
 /// <param name="info"></param>
 /// <returns></returns>
 public string ReturnJson(Member info, out bool Status)
 {
     //登录状态
     Status = MemberLogin(info);
     //生成json格式数据
     return WriteJsonForReturn(Status, info.UserName);
 }
Beispiel #7
0
        /// <summary>
        /// 记住用户信息
        /// </summary>
        /// <param name="Type">记住用户信息类别</param>
        /// <returns></returns>
        public bool RememberUserInfo(Member info, RememberType type)
        {
            if (type == RememberType.RememberName)
            {
                //记住帐号7天
                CookieHelper.SetCookie("UserName", info.UserName, DateTime.Now.AddDays(7));
            }
            else if (type == RememberType.RememberNameAndPwd)
            {

                //md5哈希加密
                string sercret = Tools.GetMD5(info.Password);
                //同时记住帐号和密码7天
                CookieHelper.SetCookie("UserName", info.UserName, DateTime.Now.AddDays(7));
                CookieHelper.SetCookie("Pwd", sercret, DateTime.Now.AddDays(7));
            }
            else
            {
                return false;
            }
            return true;
        }
Beispiel #8
0
 /// <summary>
 /// 用户登录
 /// </summary>
 /// <param name="info">会员model</param>
 /// <returns></returns>
 public bool MemberLogin(Member info)
 {
     info.Password = Tools.GetMD5(info.Password);
     return mdal.MemberLogin(info);
 }