Exemplo n.º 1
0
    protected void btnQuestion_Click(object sender, EventArgs e)
    {
        M_User model = bll.GetUser(txtUserName.Text);
        if (model != null)
        {
            if (Function.MD5Encrypt(txtAnswer.Text.Trim()) == model.Answer)
            {
                B_SiteInfo site = new B_SiteInfo();
                M_Site siteModel = site.GetSiteModel();
                //产生随机密码
                //更新数据库
                string Pwd = Function.GetRndNum(8);
                string newPwd = Function.MD5Encrypt(Pwd);
                bll.ModifyPwd(model.UserID, newPwd);

                if (siteModel != null)
                {
                    StringBuilder sb = new StringBuilder();
                    sb.Append(txtUserName.Text + ",您好!您在本站 (");
                    sb.Append(siteModel.SiteName + ")");
                    sb.Append("使用了找回密码功能.这是您的新密码:");
                    sb.Append(Pwd);
                    sb.Append("祝您健康愉快!");
                    sb.Append(siteModel.SiteName);
                    sb.Append(DateTime.Now);
                    try
                    {
                        B_SendMail mail = new B_SendMail(siteModel.EmailServerAddress, model.Email, txtUserName.Text + "您好!这是您的新密码", sb.ToString(), true, System.Text.Encoding.UTF8);
                        mail.Send();
                        Function.ShowMsg(1, "<li>恭喜!找回密码成功。您的新密码已经发送到您的邮箱,请注意查收!</li><li><a href='Login.aspx'>登录</a></li><li><a href='" + IndexUrl + "'>返回网站首页</a></li>");
                    }
                    catch
                    {
                        Function.ShowMsg(1, "<li>恭喜!找回密码成功。这是您的新密码:"+Pwd+"</li><li><a href='Login.aspx'>登录</a></li><li><a href='" + IndexUrl + "'>返回网站首页</a></li>");
                    }

                }
            }
            else
            {
                Function.ShowMsg(0, "<li>对不起,您的答案不正确!</li><li><a href='javascript:window.history.back()'>返回上一步</a></li>");
            }
        }
        else
        {
            //无此用户
            Function.ShowMsg(0, "<li>无此用户</li><li><a href='Reg.aspx'>注册一个新帐户</a></li><li><a href='" + IndexUrl + "'>返回网站首页</a></li>");
        }
    }
Exemplo n.º 2
0
    /// <summary>
    /// 用户注册
    /// </summary>
    protected void txtSubmit_Click(object sender, EventArgs e)
    {
        if (IsValid && siteModel != null)
        {
            //验证
            CheckInput();

            M_User model = new M_User();
            model.LogName = txtUsername.Text;
            model.Email = txtEmail.Text;
            model.UserPwd = Function.MD5Encrypt(txtCnfmPwd.Text);
            model.Question = txtQuestion.Text;
            model.Answer = Function.MD5Encrypt(txtAnswer.Text);
            model.RegTime = DateTime.Now;
            model.Secret = 1;//部分公开
            model.ErrorTime = DateTime.Parse("2000/01/01");
            model.ErrorNum = 0;
            model.GroupID = MUserGroupModel.UserGroupId;
            model.TypeId = TypeId;

            if (siteModel.IsTestEmail == true)
            {
                model.IsLock = true;
            }
            else
            {
                model.IsLock = false;
            }

            B_UserGroup userGroupBll = new B_UserGroup();
            M_UserGroup userGroupModel = userGroupBll.GetModel(MUserGroupModel.UserGroupId);
            string userStatus = userGroupBll.Power_UserGroup("Status", 0, userGroupModel.GroupPower);
            model.Status = int.Parse(userStatus);

            string confirmCode = Guid.NewGuid().ToString();
            model.ConfirmRegCode = confirmCode;
            model.Integral = siteModel.LoginScore;
            model.LastLoginTime = DateTime.Now;
            int uid = Bll.Reg(model);

            //自定义字段
            //定义DataTable
            DataTable dt = new DataTable();
            dt.Columns.Add(new DataColumn("FieldName", typeof(string)));
            dt.Columns.Add(new DataColumn("FieldValue", typeof(string)));

            #region 系统默认字段
            DataRow dr1 = dt.NewRow();
            dr1[0] = "UId";
            dr1[1] = uid;
            dt.Rows.Add(dr1);

            DataRow dr2 = dt.NewRow();
            dr2[0] = "AddTime";
            dr2[1] = DateTime.Now.ToString();
            dt.Rows.Add(dr2);

            DataRow dr3 = dt.NewRow();
            dr3[0] = "UpdateTime";
            dr3[1] = DateTime.Now.ToString();
            dt.Rows.Add(dr3);
            #endregion

            //以下是自动添加字段获得值
            for (int i = 0; i < dtIsUser.Rows.Count; i++)
            {
                DataRow dr = dt.NewRow();
                dr[0] = dtIsUser.Rows[i]["Name"].ToString();

                //联动获取数据开始
                //二级联动
                if (dtIsUser.Rows[i]["Type"].ToString() == "ErLinkageType")
                {
                    dr[1] = Request.Form["txt_" + dtIsUser.Rows[i]["Name"].ToString()];
                    dt.Rows.Add(dr);

                    dr = dt.NewRow();
                    dr[0] = dtIsUser.Rows[i]["Name"].ToString() + "_Id";
                    dr[1] = Request.Form["txt_" + dtIsUser.Rows[i]["Name"].ToString() + "_Id"];
                    dt.Rows.Add(dr);

                    string SmallName = BModelField.GetFieldContent(dtIsUser.Rows[i]["Content"].ToString(), 2, 1);
                    dr = dt.NewRow();
                    dr[0] = SmallName;
                    dr[1] = Request.Form["txt_" + SmallName];
                    dt.Rows.Add(dr);

                    dr = dt.NewRow();
                    dr[0] = SmallName + "_Id";
                    dr[1] = Request.Form["txt_" + SmallName + "_Id"];
                    dt.Rows.Add(dr);
                }
                else
                {
                    switch (dtIsUser.Rows[i]["Type"].ToString())
                    {
                        case "ListBoxType":
                            if (Request.Form["txt_" + dtIsUser.Rows[i]["Name"].ToString() + ""] == "" || Request.Form["txt_" + dtIsUser.Rows[i]["Name"].ToString() + ""] == null)
                            {
                                dr[1] = Request.Form["txt_" + dtIsUser.Rows[i]["Name"].ToString() + ""];
                            }
                            else
                            {
                                dr[1] = Request.Form["txt_" + dtIsUser.Rows[i]["Name"].ToString() + ""].Replace(" ", "").ToString();
                            }
                            break;
                        case "MultipleTextType":
                            dr[1] = Request.Form["txt_" + dtIsUser.Rows[i]["Name"].ToString() + ""];
                            break;
                        default:
                            dr[1] = Request.Form["txt_" + dtIsUser.Rows[i]["Name"].ToString() + ""];
                            break;
                    }
                    dt.Rows.Add(dr);
                }
            }

            //添加信息
            BInfoModel.AddInfoModel(dt, MUserGroupModel.TableName);

            string bbsCookieStr = string.Empty;
            bbsCookieStr = bbsUserBll.BBS_User_Reg(model.LogName, txtCnfmPwd.Text, model.Email, true);

            if (uid > 0)
            {
                //如果是被已注册用户推荐过来的.那么验证推荐用户是否存在
                //如果存在
                //则给推荐者加上系统设置的推广积分
                if (siteModel.IsOpenInvite && Request.QueryString["recmd_uid"] != null && Function.CheckNumberNotZero(Request.QueryString["recmd_uid"]))
                {
                    int recmd_uid = int.Parse(Request.QueryString["recmd_uid"].ToString());
                    Bll.AddCmdUserIntegral(recmd_uid);
                }
                if (siteModel.IsTestEmail == true)
                {
                    StringBuilder sb = new StringBuilder();
                    sb.AppendLine(txtUsername.Text + ",您好!");
                    sb.AppendLine("感谢您注册为 " + siteModel.SiteName + " 的用户。");
                    sb.AppendLine("您只需点击下面的链接即可激活您的帐号:");
                    sb.Append("<a href='");
                    string url = "";
                    if (siteModel.Domain.EndsWith("/"))
                    {
                        url = siteModel.Domain + "user/activate.aspx?uid=" + uid + "&code=" + confirmCode;
                    }
                    else
                    {
                        url = siteModel.Domain + "/user/activate.aspx?uid=" + uid + "&code=" + confirmCode;
                    }
                    sb.Append(url);
                    sb.Append("'>");
                    sb.Append(url);
                    sb.Append("</a><br />");
                    sb.AppendLine("(如果您无法点击上面的链接,请将链接地址手工粘贴到浏览器地址栏后访问!)<br />");
                    sb.AppendLine("祝您健康愉快!<br />");
                    sb.AppendLine(siteModel.SiteName);
                    sb.AppendLine(DateTime.Now.ToShortDateString());
                    sb.AppendLine("<hr />");
                    sb.AppendLine("此邮件为系统自动发送,请勿回复。");
                    string body = sb.ToString();
                    try
                    {
                        B_SendMail mail = new B_SendMail(siteModel.EmailServerUserName.Trim(), txtEmail.Text, txtUsername.Text + ",您好!请激活您的账户。", body, true, System.Text.Encoding.UTF8);
                        mail.Send();
                        Function.ShowMsg(1, "<li>"+txtUsername.Text+",恭喜,注册成功!一封包含您帐号激活信息的邮件已发送到您的邮箱,请按邮件内的提示激活您的帐号</li><li><a href='main.aspx'>登录用户中心</a></li><li><a href='"+IndexUrl+"'>返回网站首页</a></li>");
                    }
                    catch
                    {
                        Function.ShowMsg(1, "<li>" + txtUsername.Text + ",恭喜,注册成功!点击下面的链接立即激活您的帐号</li><li><a href='"+url+"'>激活帐号</a></li><li><a href='" + IndexUrl + "'>返回网站首页</a></li>");
                    }
                }
                else
                {
                    if (model.Status == 1)
                    {
                        HttpCookie cookie = new HttpCookie("User");
                        cookie["uId"] = uid.ToString();
                        cookie["logN"] = Function.UrlEncode(txtUsername.Text);
                        cookie["pd"] = Function.MD5Encrypt(txtCnfmPwd.Text);
                        Response.Cookies.Add(cookie);
                        if (bbsCookieStr.Length != 0)
                        {
                            bbsUserBll.WriteUserCookie(bbsCookieStr);
                        }
                        if (returnUrl != string.Empty)
                        {
                            returnUrl2 = "<li><a href='" + returnUrl + "'>返回来源页面</a></li>";
                        }
                        Function.ShowMsg(1, "<li>" + txtUsername.Text + ",恭喜,注册成功!请选择您需要的操作</li>" + returnUrl2 + "<li><a href='main.aspx'>登录用户中心</a></li><li><a href='" + IndexUrl + "'>返回网站首页</a></li>");
                    }
                    else
                    {
                        Function.ShowMsg(1, "<li>" + txtUsername.Text + ",恭喜,注册成功!</li><li><a href='main.aspx'>登录用户中心</a></li>");
                    }

                }
            }
            else
            {
                Function.ShowMsg(0, "<li>对不起,注册失败!请稍后再试</li><li><a href='"+IndexUrl+"'>返回网站首页</a></li>");
            }
        }
    }