Exemple #1
0
 /// <summary>
 /// 重写虚方法,此方法将在Init事件前执行
 /// </summary>
 protected override void ShowPage()
 {
     action   = PLRequest.GetQueryString("action");
     username = PLRequest.GetQueryString("username");
     username = Utils.DropHTML(username);
     //检查是否关闭会员注册服务
     if (action == "" && uconfig.regstatus == 0)
     {
         HttpContext.Current.Response.Redirect(linkurl("register", "?action=close"));
         return;
     }
     //Email验证
     if (action == "checkmail")
     {
         string          code  = PLRequest.GetQueryString("code");
         BLL.user_code   bll   = new BLL.user_code();
         Model.user_code model = bll.GetModel(code);
         if (model == null) //返回出错
         {
             HttpContext.Current.Response.Redirect(linkurl("register", "?action=checkerror"));
             return;
         }
         //修改申请码状态
         model.status = 1;
         bll.Update(model);
         //修改用户状态
         new BLL.users().UpdateField(model.user_id, "status=0");
     }
 }
 private string verify_invite_reg(string user_name, string invite_code)
 {
     if (string.IsNullOrEmpty(invite_code))
     {
         return("{\"status\":0, \"msg\":\"邀请码不能为空!\"}");
     }
     BLL.user_code   codeBll   = new BLL.user_code();
     Model.user_code codeModel = codeBll.GetModel(invite_code);
     if (codeModel == null)
     {
         return("{\"status\":0, \"msg\":\"邀请码不正确或已过期!\"}");
     }
     if (userConfig.invitecodecount > 0)
     {
         if (codeModel.count >= userConfig.invitecodecount)
         {
             codeModel.status = 1;
             return("{\"status\":0, \"msg\":\"该邀请码已经被使用!\"}");
         }
     }
     //检查是否给邀请人增加积分
     if (userConfig.pointinvitenum > 0)
     {
         new BLL.user_point_log().Add(codeModel.user_id, codeModel.user_name, userConfig.pointinvitenum, "邀请用户【" + user_name + "】注册获得积分", true);
     }
     //更改邀请码状态
     codeModel.count += 1;
     codeBll.Update(codeModel);
     return("success");
 }
Exemple #3
0
 /// <summary>
 /// 重写虚方法,此方法将在Init事件前执行
 /// </summary>
 protected override void ShowPage()
 {
     action = DTRequest.GetQueryString("action");
     username = DTRequest.GetQueryString("username");
     //检查是否关闭会员注册服务
     if (action == "" && uconfig.regstatus == 0)
     {
         HttpContext.Current.Response.Redirect(linkurl("register") + "?action=close");
         return;
     }
     //Email验证
     if (action == "checkmail")
     {
         string strcode = DTRequest.GetQueryString("strcode");
         BLL.user_code bll = new BLL.user_code();
         Model.user_code model = bll.GetModel(strcode);
         if (model == null) //返回出错
         {
             HttpContext.Current.Response.Redirect(linkurl("register") + "?action=checkerror");
             return;
         }
         //修改申请码状态
         model.status = 1;
         bll.Update(model);
         //修改用户状态
         new BLL.users().UpdateField(model.user_id, "is_lock=0");
     }
 }
Exemple #4
0
 /// <summary>
 /// 返回邀请码状态
 /// </summary>
 /// <param name="str_code">邀请码</param>
 /// <returns>bool</returns>
 protected bool get_invite_status(string str_code)
 {
     Model.user_code model = new BLL.user_code().GetModel(str_code);
     if (model != null)
     {
         return(true);
     }
     return(false);
 }
Exemple #5
0
 /// <summary>
 /// 返回邀请码状态
 /// </summary>
 /// <param name="str_code">邀请码</param>
 /// <returns>bool</returns>
 public bool get_invite_status(string str_code)
 {
     Model.user_code model = new BLL.user_code().GetModel("status=0 and datediff(d,eff_time,getdate())<=0 and str_code='" + str_code + "'", "top 1 *", "");
     if (model != null)
     {
         return(true);
     }
     return(false);
 }
Exemple #6
0
 /// <summary>
 /// 返回邀请码状态
 /// </summary>
 /// <param name="str_code">邀请码</param>
 /// <returns>bool</returns>
 protected bool get_invite_status(string str_code)
 {
     Model.user_code model = new BLL.user_code().GetModel(str_code);
     if (model != null)
     {
         return true;
     }
     return false;
 }
        private string verify_email(Model.users userModel)
        {
            BLL.user_code   codeBll = new BLL.user_code();
            Model.user_code codeModel;
            //检查是否重复提交
            codeModel = codeBll.GetModel(userModel.user_name, Vincent._DTcms.DTEnums.CodeEnum.RegVerify.ToString(), "d");
            if (codeModel == null)
            {
                codeModel           = new Model.user_code();
                codeModel.user_id   = userModel.id;
                codeModel.user_name = userModel.user_name;
                codeModel.type      = Vincent._DTcms.DTEnums.CodeEnum.RegVerify.ToString();
                codeModel.str_code  = userModel.strcode;
                codeModel.eff_time  = DateTime.Now.AddDays(userConfig.regemailexpired);
                codeModel.add_time  = DateTime.Now;
                new BLL.user_code().Add(codeModel);
            }
            //获得邮件内容
            Model.mail_template mailModel = new BLL.mail_template().GetModel("regverify");
            if (mailModel == null)
            {
                return("{\"status\":0, \"msg\":\"邮件发送失败,邮件模板内容不存在!\"}");
            }
            //替换模板内容
            string titletxt = mailModel.maill_title;
            string bodytxt  = mailModel.content;

            titletxt = titletxt.Replace("{webname}", siteConfig.webname);
            titletxt = titletxt.Replace("{username}", userModel.user_name);
            bodytxt  = bodytxt.Replace("{webname}", siteConfig.webname);
            bodytxt  = bodytxt.Replace("{webtel}", siteConfig.webtel);
            bodytxt  = bodytxt.Replace("{weburl}", siteConfig.weburl);
            bodytxt  = bodytxt.Replace("{username}", userModel.user_name);
            bodytxt  = bodytxt.Replace("{valid}", userConfig.regemailexpired.ToString());
            bodytxt  = bodytxt.Replace("{linkurl}", "http://" + HttpContext.Current.Request.Url.Authority.ToLower()
                                       + "/checkemail.aspx?action=checkmail&userid=" + userModel.id + "&strcode=" + userModel.strcode);
            //发送邮件
            try
            {
                _Email.SendMail(siteConfig.emailsmtp,
                                siteConfig.emailusername,
                                _DESEncrypt.Decrypt(siteConfig.emailpassword),
                                siteConfig.emailnickname,
                                siteConfig.emailfrom,
                                userModel.email,
                                titletxt, bodytxt);
            }
            catch (Exception)
            {
                //return "{\"status\":0, \"msg\":\""+ex.Message+"\"}";
                return("{\"status\":0, \"msg\":\"邮件发送失败,请联系本站管理员!\"}");
            }
            return("success");
        }
        private string verify_mobile(Model.users userModel)
        {
            //生成随机码
            string strcode = Vincent._DTcms.Utils.Number(4);

            BLL.user_code   codeBll = new BLL.user_code();
            Model.user_code codeModel;
            //检查是否重复提交
            codeModel = codeBll.GetModel(userModel.user_name, Vincent._DTcms.DTEnums.CodeEnum.RegVerify.ToString(), "n");
            if (codeModel == null)
            {
                codeModel           = new Model.user_code();
                codeModel.user_id   = userModel.id;
                codeModel.user_name = userModel.user_name;
                codeModel.type      = Vincent._DTcms.DTEnums.CodeEnum.RegVerify.ToString();
                codeModel.str_code  = strcode;
                codeModel.eff_time  = DateTime.Now.AddMinutes(userConfig.regsmsexpired);
                codeModel.add_time  = DateTime.Now;
                new BLL.user_code().Add(codeModel);
            }
            //获得短信模板内容
            Model.sms_template smsModel = new BLL.sms_template().GetModel("usercode");
            if (smsModel == null)
            {
                return("{\"status\":0, \"msg\":\"发送失败,短信模板内容不存在!\"}");
            }
            //替换模板内容
            string msgContent = smsModel.content;

            msgContent = msgContent.Replace("{webname}", siteConfig.webname);
            msgContent = msgContent.Replace("{webtel}", siteConfig.webtel);
            msgContent = msgContent.Replace("{weburl}", siteConfig.weburl);
            msgContent = msgContent.Replace("{username}", userModel.user_name);
            msgContent = msgContent.Replace("{code}", codeModel.str_code);
            msgContent = msgContent.Replace("{valid}", userConfig.regsmsexpired.ToString());
            //发送短信
            string tipMsg     = string.Empty;
            bool   sendStatus = new BLL.sms_message().Send(userModel.mobile, msgContent, 2, out tipMsg);

            if (!sendStatus)
            {
                return("{\"status\": 0, \"msg\": \"短信发送失败," + tipMsg + "\"}");
            }
            return("success");
        }
        private void user_invite_code(HttpContext context)
        {
            //检查用户是否登录
            Model.users model = new BasePage().GetUserInfo();
            if (model == null)
            {
                context.Response.Write("{\"status\":0, \"msg\":\"对不起,用户尚未登录或已超时!\"}");
                return;
            }
            //检查是否开启邀请注册
            if (userConfig.regstatus != 2)
            {
                context.Response.Write("{\"status\":0, \"msg\":\"对不起,系统不允许通过邀请注册!\"}");
                return;
            }
            BLL.user_code codeBll = new BLL.user_code();
            //检查申请是否超过限制
            if (userConfig.invitecodenum > 0)
            {
                int result = codeBll.GetCount("user_name='" + model.user_name + "' and type='" + Vincent._DTcms.DTEnums.CodeEnum.Register.ToString() + "' and datediff(d,add_time,getdate())=0");
                if (result >= userConfig.invitecodenum)
                {
                    context.Response.Write("{\"status\":0, \"msg\":\"对不起,您申请邀请码的数量已超过每天限制!\"}");
                    return;
                }
            }
            //删除过期的邀请码
            codeBll.Delete("type='" + Vincent._DTcms.DTEnums.CodeEnum.Register.ToString() + "' and status=1 or datediff(d,eff_time,getdate())>0");
            //随机取得邀请码
            string str_code = Vincent._DTcms.Utils.GetCheckCode(8);

            Model.user_code codeModel = new Model.user_code();
            codeModel.user_id   = model.id;
            codeModel.user_name = model.user_name;
            codeModel.type      = Vincent._DTcms.DTEnums.CodeEnum.Register.ToString();
            codeModel.str_code  = str_code;
            if (userConfig.invitecodeexpired > 0)
            {
                codeModel.eff_time = DateTime.Now.AddDays(userConfig.invitecodeexpired);
            }
            codeBll.Add(codeModel);
            context.Response.Write("{\"status\":1, \"msg\":\"恭喜您,申请邀请码已成功!\"}");
            return;
        }
Exemple #10
0
 /// <summary>
 /// 重写父类的虚方法,此方法将在Init事件前执行
 /// </summary>
 protected override void ShowPage()
 {
     action = DTRequest.GetQueryString("action");
     if (action == "mobile")
     {
         username = DTRequest.GetQueryString("username");
     }
     else if (action == "email")
     {
         code = DTRequest.GetQueryString("code");
         Model.user_code model = new BLL.user_code().GetModel(code);
         if (model == null)
         {
             HttpContext.Current.Response.Redirect(linkurl("repassword", "?action=error"));
             return;
         }
         username = model.user_name;
     }
 }
Exemple #11
0
 /// <summary>
 /// 重写父类的虚方法,此方法将在Init事件前执行
 /// </summary>
 protected override void ShowPage()
 {
     action = DTRequest.GetQueryString("action");
     if (action == "mobile")
     {
         username = DTRequest.GetQueryString("username");
     }
     else if (action == "email")
     {
         code = DTRequest.GetQueryString("code");
         Model.user_code model = new BLL.user_code().GetModel(code);
         if (model == null)
         {
             HttpContext.Current.Response.Redirect(linkurl("repassword", "?action=error"));
             return;
         }
         username = model.user_name;
     }
 }
Exemple #12
0
        public static string GetInviteCode(Agp2pDataContext context = null)
        {
            if (context == null)
            {
                context = new Agp2pDataContext();
            }
            var userInfo = GetUserInfoByLinq(context);

            HttpContext.Current.Response.TrySkipIisCustomErrors = true;
            if (userInfo == null)
            {
                HttpContext.Current.Response.StatusCode = (int)HttpStatusCode.Unauthorized;
                return("请先登录");
            }

            var userCode = context.dt_user_code.FirstOrDefault(u => u.user_id == userInfo.id && u.type == DTEnums.CodeEnum.Register.ToString());

            //新增一个邀请码
            if (userCode == null)
            {
                var codeBll   = new BLL.user_code();
                var strCode   = Utils.GetCheckCode(8);
                var codeModel = new Model.user_code
                {
                    user_id   = userInfo.id,
                    user_name = userInfo.user_name,
                    type      = DTEnums.CodeEnum.Register.ToString(),
                    str_code  = strCode,
                    eff_time  = DateTime.Now.AddDays(1)
                };

                codeBll.Add(codeModel);
                return(strCode);
            }
            return(userCode.str_code);
        }
        private void user_repassword(HttpContext context)
        {
            string strcode = DTRequest.GetFormString("hideCode"); //取回密码字符串
            string password = DTRequest.GetFormString("txtPassword"); //重设后的密码

            //检查验证字符串
            if (string.IsNullOrEmpty(strcode))
            {
                context.Response.Write("{\"status\":0, \"msg\":\"对不起,校检码字符串不能为空!\"}");
                return;
            }
            //检查输入的新密码
            if (string.IsNullOrEmpty(password))
            {
                context.Response.Write("{\"status\":0, \"msg\":\"对不起,请输入您的新密码!\"}");
                return;
            }

            BLL.user_code codeBll = new BLL.user_code();
            Model.user_code codeModel = codeBll.GetModel(strcode);
            if (codeModel == null)
            {
                context.Response.Write("{\"status\":0, \"msg\":\"对不起,校检码不存在或已过期!\"}");
                return;
            }
            //验证用户是否存在
            BLL.users userBll = new BLL.users();
            if (!userBll.Exists(codeModel.user_id))
            {
                context.Response.Write("{\"status\":0, \"msg\":\"对不起,该用户不存在或已被删除!\"}");
                return;
            }
            Model.users userModel = userBll.GetModel(codeModel.user_id);
            //执行修改操作
            userModel.password = DESEncrypt.Encrypt(password, userModel.salt);
            userBll.Update(userModel);
            //更改验证字符串状态
            codeModel.count = 1;
            codeModel.status = 1;
            codeBll.Update(codeModel);
            context.Response.Write("{\"status\":1, \"msg\":\"修改密码成功,请记住新密码!\"}");
            return;
        }
 private void user_invite_code(HttpContext context)
 {
     //检查用户是否登录
     Model.users model = new BasePage().GetUserInfo();
     if (model == null)
     {
         context.Response.Write("{\"msg\":0, \"msgbox\":\"对不起,用户没有登录或登录超时啦!\"}");
         return;
     }
     //检查是否开启邀请注册
     if (userConfig.regstatus != 2)
     {
         context.Response.Write("{\"msg\":0, \"msgbox\":\"对不起,系统不允许通过邀请注册!\"}");
         return;
     }
     BLL.user_code codeBll = new BLL.user_code();
     //检查申请是否超过限制
     if (userConfig.invitecodenum > 0)
     {
         int result = codeBll.GetCount("user_name='" + model.user_name + "' and type='" + DTEnums.CodeEnum.Register.ToString() + "' and datediff(d,add_time,getdate())=0");
         if (result >= userConfig.invitecodenum)
         {
             context.Response.Write("{\"msg\":0, \"msgbox\":\"对不起,您申请的邀请码数量已超过每天的限制!\"}");
             return;
         }
     }
     //删除过期的邀请码
     codeBll.Delete("type='" + DTEnums.CodeEnum.Register.ToString() + "' and status=1 or datediff(d,eff_time,getdate())>0");
     //随机取得邀请码
     string str_code = Utils.GetCheckCode(8);
     Model.user_code codeModel = new Model.user_code();
     codeModel.user_id = model.id;
     codeModel.user_name = model.user_name;
     codeModel.type = DTEnums.CodeEnum.Register.ToString();
     codeModel.str_code = str_code;
     if (userConfig.invitecodeexpired > 0)
     {
         codeModel.eff_time = DateTime.Now.AddDays(userConfig.invitecodeexpired);
     }
     codeBll.Add(codeModel);
     context.Response.Write("{\"msg\":1, \"msgbox\":\"恭喜您,申请邀请码已成功!\"}");
     return;
 }
 private void user_getpassword(HttpContext context)
 {
     string code = DTRequest.GetFormString("txtCode");
     string username = DTRequest.GetFormString("txtUserName").Trim();
     //检查用户名是否正确
     if (string.IsNullOrEmpty(username))
     {
         context.Response.Write("{\"msg\":0, \"msgbox\":\"对不起,用户名不可为空!\"}");
         return;
     }
     //校检验证码
     string result = verify_code(context, code);
     if (result != "success")
     {
         context.Response.Write(result);
         return;
     }
     //检查用户信息
     BLL.users bll = new BLL.users();
     Model.users model = bll.GetModel(username);
     if (model == null)
     {
         context.Response.Write("{\"msg\":0, \"msgbox\":\"对不起,您输入的用户名不存在!\"}");
         return;
     }
     if (string.IsNullOrEmpty(model.email))
     {
         context.Response.Write("{\"msg\":0, \"msgbox\":\"您尚未设置邮箱地址,无法使用取回密码功能!\"}");
         return;
     }
     //生成随机码
     string strcode = Utils.GetCheckCode(20);
     //获得邮件内容
     Model.mail_template mailModel = new BLL.mail_template().GetModel("getpassword");
     if (mailModel == null)
     {
         context.Response.Write("{\"msg\":0, \"msgbox\":\"邮件发送失败,邮件模板内容不存在!\"}");
         return;
     }
     //检查是否重复提交
     BLL.user_code codeBll = new BLL.user_code();
     Model.user_code codeModel;
     codeModel = codeBll.GetModel(username, DTEnums.CodeEnum.RegVerify.ToString());
     if (codeModel == null)
     {
         codeModel = new Model.user_code();
         //写入数据库
         codeModel.user_id = model.id;
         codeModel.user_name = model.user_name;
         codeModel.type = DTEnums.CodeEnum.Password.ToString();
         codeModel.str_code = strcode;
         codeModel.eff_time = DateTime.Now.AddDays(1);
         codeModel.add_time = DateTime.Now;
         codeBll.Add(codeModel);
     }
     //替换模板内容
     string titletxt = mailModel.maill_title;
     string bodytxt = mailModel.content;
     titletxt = titletxt.Replace("{webname}", siteConfig.webname);
     titletxt = titletxt.Replace("{username}", model.user_name);
     bodytxt = bodytxt.Replace("{webname}", siteConfig.webname);
     bodytxt = bodytxt.Replace("{username}", model.user_name);
     bodytxt = bodytxt.Replace("{linkurl}", Utils.DelLastChar(siteConfig.weburl, "/") + new BasePage().linkurl("repassword1", "reset", strcode)); //此处需要修改
     //发送邮件
     try
     {
         DTMail.sendMail(siteConfig.emailstmp,
             siteConfig.emailusername,
             DESEncrypt.Decrypt(siteConfig.emailpassword),
             siteConfig.emailnickname,
             siteConfig.emailfrom,
             model.email,
             titletxt, bodytxt);
     }
     catch
     {
         context.Response.Write("{\"msg\":0, \"msgbox\":\"邮件发送失败,请联系本站管理员!\"}");
         return;
     }
     context.Response.Write("{\"msg\":1, \"msgbox\":\"邮件发送成功,请登录您的邮箱找回登录密码!\"}");
     return;
 }
 private string verify_invite_reg(string user_name, string invite_code)
 {
     if (string.IsNullOrEmpty(invite_code))
     {
         return "{\"msg\":0, \"msgbox\":\"邀请码不能为空!\"}";
     }
     BLL.user_code codeBll = new BLL.user_code();
     Model.user_code codeModel = codeBll.GetModel(invite_code);
     if (codeModel == null)
     {
         return "{\"msg\":0, \"msgbox\":\"邀请码不正确或已过期啦!\"}";
     }
     if (userConfig.invitecodecount > 0)
     {
         if (codeModel.count >= userConfig.invitecodecount)
         {
             codeModel.status = 1;
             return "{\"msg\":0, \"msgbox\":\"该邀请码已经被使用啦!\"}";
         }
     }
     //检查是否给邀请人增加积分
     if (userConfig.pointinvitenum > 0)
     {
         new BLL.point_log().Add(codeModel.user_id, codeModel.user_name, userConfig.pointinvitenum, "邀请用户【" + user_name + "】注册获得积分");
     }
     //更改邀请码状态
     codeModel.count += 1;
     codeBll.Update(codeModel);
     return "success";
 }
 private string verify_email(Model.users userModel)
 {
     //生成随机码
     string strcode = Utils.GetCheckCode(20);
     BLL.user_code codeBll = new BLL.user_code();
     Model.user_code codeModel;
     //检查是否重复提交
     codeModel = codeBll.GetModel(userModel.user_name, DTEnums.CodeEnum.RegVerify.ToString());
     if (codeModel == null)
     {
         codeModel = new Model.user_code();
         codeModel.user_id = userModel.id;
         codeModel.user_name = userModel.user_name;
         codeModel.type = DTEnums.CodeEnum.RegVerify.ToString();
         codeModel.str_code = strcode;
         codeModel.eff_time = DateTime.Now.AddDays(userConfig.regemailexpired);
         codeModel.add_time = DateTime.Now;
         new BLL.user_code().Add(codeModel);
     }
     //获得邮件内容
     Model.mail_template mailModel = new BLL.mail_template().GetModel("regverify");
     if (mailModel == null)
     {
         return "{\"msg\":0, \"msgbox\":\"邮件发送失败,邮件模板内容不存在!\"}";
     }
     //替换模板内容
     string titletxt = mailModel.maill_title;
     string bodytxt = mailModel.content;
     titletxt = titletxt.Replace("{webname}", siteConfig.webname);
     titletxt = titletxt.Replace("{username}", userModel.user_name);
     bodytxt = bodytxt.Replace("{webname}", siteConfig.webname);
     bodytxt = bodytxt.Replace("{username}", userModel.user_name);
     bodytxt = bodytxt.Replace("{linkurl}", Utils.DelLastChar(siteConfig.weburl, "/") + new Web.UI.BasePage().linkurl("register")+"?action=checkmail&strcode=" + codeModel.str_code);
     //发送邮件
     try
     {
         DTMail.sendMail(siteConfig.emailstmp,
             siteConfig.emailusername,
             DESEncrypt.Decrypt(siteConfig.emailpassword),
             siteConfig.emailnickname,
             siteConfig.emailfrom,
             userModel.email,
             titletxt, bodytxt);
     }
     catch
     {
         return "{\"msg\":0, \"msgbox\":\"邮件发送失败,请联系本站管理员!\"}";
     }
     return "success";
 }
        private void user_repassword(HttpContext context)
        {
            string code = context.Request.Form["txtCode"];
            string strcode = context.Request.Form["hideCode"];
            string password = context.Request.Form["txtPassword"];

            //校检验证码
            string result = verify_code(context, code);
            if (result != "success")
            {
                context.Response.Write(result);
                return;
            }
            //检查验证字符串
            if (string.IsNullOrEmpty(strcode))
            {
                context.Response.Write("{\"msg\":0, \"msgbox\":\"系统找不到邮件验证的字符串!\"}");
                return;
            }
            //检查输入的新密码
            if (string.IsNullOrEmpty(password))
            {
                context.Response.Write("{\"msg\":0, \"msgbox\":\"请输入您的新密码!\"}");
                return;
            }

            BLL.user_code codeBll = new BLL.user_code();
            Model.user_code codeModel = codeBll.GetModel(strcode);
            if (codeModel == null)
            {
                context.Response.Write("{\"msg\":0, \"msgbox\":\"邮件验证的字符串不存在或已过期!\"}");
                return;
            }
            //验证用户是否存在
            BLL.users userBll = new BLL.users();
            if (!userBll.Exists(codeModel.user_id))
            {
                context.Response.Write("{\"msg\":0, \"msgbox\":\"该用户不存在或已被删除!\"}");
                return;
            }
            Model.users userModel = userBll.GetModel(codeModel.user_id);
            //执行修改操作
            userModel.password = DESEncrypt.Encrypt(password);
            userBll.Update(userModel);
            //更改验证字符串状态
            codeModel.count = 1;
            codeModel.status = 1;
            codeBll.Update(codeModel);
            context.Response.Write("{\"msg\":1, \"msgbox\":\"修改密码成功,请记住您的新密码!\"}");
            return;
        }
Exemple #19
0
 private string verify_mobile(Model.users userModel)
 {
     //生成随机码
     string strcode = Utils.Number(4);
     BLL.user_code codeBll = new BLL.user_code();
     Model.user_code codeModel;
     //检查是否重复提交
     codeModel = codeBll.GetModel(userModel.user_name, DTEnums.CodeEnum.RegVerify.ToString(), "n");
     if (codeModel == null)
     {
         codeModel = new Model.user_code();
         codeModel.user_id = userModel.id;
         codeModel.user_name = userModel.user_name;
         codeModel.type = DTEnums.CodeEnum.RegVerify.ToString();
         codeModel.str_code = strcode;
         codeModel.eff_time = DateTime.Now.AddMinutes(userConfig.regsmsexpired);
         codeModel.add_time = DateTime.Now;
         new BLL.user_code().Add(codeModel);
     }
     //获得短信模板内容
     Model.sms_template smsModel = new BLL.sms_template().GetModel("usercode");
     if (smsModel == null)
     {
         return "{\"status\":0, \"msg\":\"发送失败,短信模板内容不存在!\"}";
     }
     //替换模板内容
     string msgContent = smsModel.content;
     msgContent = msgContent.Replace("{webname}", siteConfig.webname);
     msgContent = msgContent.Replace("{webtel}", siteConfig.webtel);
     msgContent = msgContent.Replace("{weburl}", siteConfig.weburl);
     msgContent = msgContent.Replace("{username}", userModel.user_name);
     msgContent = msgContent.Replace("{code}", codeModel.str_code);
     msgContent = msgContent.Replace("{valid}", userConfig.regsmsexpired.ToString());
     //发送短信
     string tipMsg = string.Empty;
     bool sendStatus = new BLL.sms_message().Send(userModel.mobile, msgContent, 2, out tipMsg);
     if (!sendStatus)
     {
         return "{\"status\": 0, \"msg\": \"短信发送失败," + tipMsg + "\"}";
     }
     return "success";
 }
 private string send_verify_email(string site, Model.users userModel)
 {
     //生成随机码
     string strcode = Utils.GetCheckCode(20);
     BLL.user_code codeBll = new BLL.user_code();
     Model.user_code codeModel;
     //检查是否重复提交
     codeModel = codeBll.GetModel(userModel.user_name, DTEnums.CodeEnum.RegVerify.ToString(), "d");
     if (codeModel == null)
     {
         codeModel = new Model.user_code();
         codeModel.user_id = userModel.id;
         codeModel.user_name = userModel.user_name;
         codeModel.type = DTEnums.CodeEnum.RegVerify.ToString();
         codeModel.str_code = strcode;
         codeModel.eff_time = DateTime.Now.AddDays(userConfig.regemailexpired);
         codeModel.add_time = DateTime.Now;
         new BLL.user_code().Add(codeModel);
     }
     //获得邮件内容
     Model.mail_template mailModel = new BLL.mail_template().GetModel("regverify");
     if (mailModel == null)
     {
         return "{\"status\":0, \"msg\":\"邮件发送失败,邮件模板内容不存在!\"}";
     }
     //替换模板内容
     string titletxt = mailModel.maill_title;
     string bodytxt = mailModel.content;
     titletxt = titletxt.Replace("{webname}", siteConfig.webname);
     titletxt = titletxt.Replace("{username}", userModel.user_name);
     bodytxt = bodytxt.Replace("{webname}", siteConfig.webname);
     bodytxt = bodytxt.Replace("{webtel}", siteConfig.webtel);
     bodytxt = bodytxt.Replace("{weburl}", siteConfig.weburl);
     bodytxt = bodytxt.Replace("{username}", userModel.user_name);
     bodytxt = bodytxt.Replace("{valid}", userConfig.regemailexpired.ToString());
     bodytxt = bodytxt.Replace("{linkurl}", "http://" + HttpContext.Current.Request.Url.Authority.ToLower()
         + new Web.UI.BasePage().getlink(site, new Web.UI.BasePage().linkurl("register", "?action=checkmail&code=" + codeModel.str_code)));
     //发送邮件
     try
     {
         DTMail.sendMail(siteConfig.emailsmtp, siteConfig.emailssl,
             siteConfig.emailusername,
             DESEncrypt.Decrypt(siteConfig.emailpassword),
             siteConfig.emailnickname,
             siteConfig.emailfrom,
             userModel.email,
             titletxt, bodytxt);
     }
     catch
     {
         return "{\"status\":0, \"msg\":\"邮件发送失败,请联系本站管理员!\"}";
     }
     return "success";
 }
 private void user_getpassword(HttpContext context)
 {
     string site = DTRequest.GetQueryString("site");
     string code = DTRequest.GetFormString("txtCode");
     string type = DTRequest.GetFormString("txtType");
     string username = DTRequest.GetFormString("txtUserName").Trim();
     //检查站点目录
     if (string.IsNullOrEmpty(site))
     {
         context.Response.Write("{\"status\":0, \"msg\":\"对不起,网站传输参数有误!\"}");
         return;
     }
     //检查用户名
     if (string.IsNullOrEmpty(username))
     {
         context.Response.Write("{\"status\":0, \"msg\":\"对不起,用户名不可为空!\"}");
         return;
     }
     //检查取回密码类型
     if (string.IsNullOrEmpty(type))
     {
         context.Response.Write("{\"status\":0, \"msg\":\"对不起,请选择取回密码类型!\"}");
         return;
     }
     //校检验证码
     string result = verify_code(context, code);
     if (result != "success")
     {
         context.Response.Write(result);
         return;
     }
     //检查用户信息
     BLL.users bll = new BLL.users();
     Model.users model = bll.GetModel(username);
     if (model == null)
     {
         context.Response.Write("{\"status\":0, \"msg\":\"对不起,您输入的用户名不存在!\"}");
         return;
     }
     //发送取回密码的短信或邮件
     if (type.ToLower() == "mobile") //使用手机取回密码
     {
         #region 发送短信==================
         if (string.IsNullOrEmpty(model.mobile))
         {
             context.Response.Write("{\"status\":0, \"msg\":\"您尚未绑定手机号码,无法取回密码!\"}");
             return;
         }
         Model.sms_template smsModel = new BLL.sms_template().GetModel("usercode"); //取得短信内容
         if (smsModel == null)
         {
             context.Response.Write("{\"status\":0, \"msg\":\"发送失败,短信模板不存在,请联系管理员!\"}");
         }
         string strcode = Utils.Number(4); //随机验证码
         //检查是否重复提交
         BLL.user_code codeBll = new BLL.user_code();
         Model.user_code codeModel;
         codeModel = codeBll.GetModel(username, DTEnums.CodeEnum.RegVerify.ToString(), "d");
         if (codeModel == null)
         {
             codeModel = new Model.user_code();
             //写入数据库
             codeModel.user_id = model.id;
             codeModel.user_name = model.user_name;
             codeModel.type = DTEnums.CodeEnum.Password.ToString();
             codeModel.str_code = strcode;
             codeModel.eff_time = DateTime.Now.AddMinutes(userConfig.regsmsexpired);
             codeModel.add_time = DateTime.Now;
             codeBll.Add(codeModel);
         }
         //替换标签
         string msgContent = smsModel.content;
         msgContent = msgContent.Replace("{webname}", siteConfig.webname);
         msgContent = msgContent.Replace("{weburl}", siteConfig.weburl);
         msgContent = msgContent.Replace("{webtel}", siteConfig.webtel);
         msgContent = msgContent.Replace("{code}", codeModel.str_code);
         msgContent = msgContent.Replace("{valid}", userConfig.regsmsexpired.ToString());
         //发送短信
         string tipMsg = string.Empty;
         bool result1 = new BLL.sms_message().Send(model.mobile, msgContent, 1, out tipMsg);
         if (!result1)
         {
             context.Response.Write("{\"status\":0, \"msg\":\"发送失败," + tipMsg + "\"}");
             return;
         }
         context.Response.Write("{\"status\":1, \"msg\":\"手机验证码发送成功!\", \"url\":\""
             + new BasePage().getlink(site, new BasePage().linkurl("repassword", "?action=mobile&username="******"\"}");
         return;
         #endregion
     }
     else if (type.ToLower() == "email") //使用邮箱取回密码
     {
         #region 发送邮件==================
         if (string.IsNullOrEmpty(model.email))
         {
             context.Response.Write("{\"status\":0, \"msg\":\"您尚未绑定邮箱,无法取回密码!\"}");
             return;
         }
         //生成随机码
         string strcode = Utils.GetCheckCode(20);
         //获得邮件内容
         Model.mail_template mailModel = new BLL.mail_template().GetModel("getpassword");
         if (mailModel == null)
         {
             context.Response.Write("{\"status\":0, \"msg\":\"邮件发送失败,邮件模板内容不存在!\"}");
             return;
         }
         //检查是否重复提交
         BLL.user_code codeBll = new BLL.user_code();
         Model.user_code codeModel;
         codeModel = codeBll.GetModel(username, DTEnums.CodeEnum.RegVerify.ToString(), "d");
         if (codeModel == null)
         {
             codeModel = new Model.user_code();
             //写入数据库
             codeModel.user_id = model.id;
             codeModel.user_name = model.user_name;
             codeModel.type = DTEnums.CodeEnum.Password.ToString();
             codeModel.str_code = strcode;
             codeModel.eff_time = DateTime.Now.AddDays(userConfig.regemailexpired);
             codeModel.add_time = DateTime.Now;
             codeBll.Add(codeModel);
         }
         //替换模板内容
         string titletxt = mailModel.maill_title;
         string bodytxt = mailModel.content;
         titletxt = titletxt.Replace("{webname}", siteConfig.webname);
         titletxt = titletxt.Replace("{username}", model.user_name);
         bodytxt = bodytxt.Replace("{webname}", siteConfig.webname);
         bodytxt = bodytxt.Replace("{weburl}", siteConfig.weburl);
         bodytxt = bodytxt.Replace("{webtel}", siteConfig.webtel);
         bodytxt = bodytxt.Replace("{valid}", userConfig.regemailexpired.ToString());
         bodytxt = bodytxt.Replace("{username}", model.user_name);
         bodytxt = bodytxt.Replace("{linkurl}", "http://" + HttpContext.Current.Request.Url.Authority.ToLower()
             + new BasePage().getlink(site, new BasePage().linkurl("repassword", "?action=email&code=" + codeModel.str_code)));
         //发送邮件
         try
         {
             DTMail.sendMail(siteConfig.emailsmtp,
                 siteConfig.emailssl,
                 siteConfig.emailusername,
                 DESEncrypt.Decrypt(siteConfig.emailpassword),
                 siteConfig.emailnickname,
                 siteConfig.emailfrom,
                 model.email,
                 titletxt, bodytxt);
         }
         catch
         {
             context.Response.Write("{\"status\":0, \"msg\":\"邮件发送失败,请联系本站管理员!\"}");
             return;
         }
         context.Response.Write("{\"status\":1, \"msg\":\"邮件发送成功,请登录邮箱查看邮件!\"}");
         return;
         #endregion
     }
     context.Response.Write("{\"status\":0, \"msg\":\"发生未知错误,请检查参数是否正确!\"}");
     return;
 }