Exemple #1
0
    protected void Page_Load(object sender, EventArgs e)
    {
        string strUsername     = QS("Username");
        string strActivateCode = QS("ActivateCode");

        if (string.IsNullOrEmpty(strUsername) || string.IsNullOrEmpty(strActivateCode))
        {
            AlertAndGo(" 激活失败,URL不合法!o(╯□╰)o", GetIndexURL());
        }


        LFL.Favorite.BLL.UserBll bll   = new LFL.Favorite.BLL.UserBll();
        LFL.Favorite.Model.User  model = null;

        model = bll.GetModel(strUsername);
        if (model == null)
        {
            AlertAndGo(" 不存在该用户!o(╯□╰)o", GetIndexURL());
        }

        int iResult = -1;

        try
        {
            iResult = bll.UserAcivate(strUsername, strActivateCode);
        }
        catch (Exception ex)
        {
            WebLog.WriteErrLog("激活用户名:" + strUsername + ",验证码:" + strActivateCode + "失败,原因:" + ex.Message);
            AlertAndGo("对不起激活失败!原因:" + ex.Message, GetIndexURL());
        }
        //判断是否成功
        if (iResult == 1)
        {
            try
            {
                Email email = new Email();
                email.SendMail(model.Email, "您的帐户" + model.Username + "已激活", GetActivateOKConent(model.Username, model.Email));
            }
            catch (Exception ex)
            {
                WebLog.WriteErrLog("发送已经激活用户" + strUsername + "邮件失败:" + ex.Message);
            }
            AlertAndGo("恭喜,您的账号:" + strUsername + "激活成功!", GetIndexURL());
        }
        else if (iResult == 2)
        {
            AlertAndGo("您的账号:" + strUsername + "已激活,无需重复激活!", GetIndexURL());
        }
        else if (iResult == 0)
        {
            AlertAndGo("对不起,激活失败!用户不存在或者激活码错误!", GetIndexURL());
        }
        else
        {
            AlertAndGo("对不起,激活失败!", GetIndexURL());
        }
    }
Exemple #2
0
    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        string chkCode = txtChkCode.Value + "";
        string valCode = hdValCode.Value + "";

        if (chkCode != "")
        {
            if (valCode == "")
            {
                return;
            }
            if (LFL.Utility.Security.MD5Util.ToMD5(valCode).Replace("-", "").Replace("A", "").Replace("B", "").Replace("C", "").Replace("D", "").Replace("E", "").Replace("F", "").Substring(0, 4) != chkCode)
            {
                AlertAndBack("验证码错误!");
            }
        }

        LFL.Favorite.Model.User user = new LFL.Favorite.Model.User();


        string strUsername, strPassword, strRePassword, strEmail;

        strUsername = txtUsername.Value.Trim();
        if (string.IsNullOrEmpty(strUsername) || strUsername.Length < 4 || strUsername.Length > 20)
        {
            AlertAndBack("用户名不能为空且长度于5-20之间!");
        }
        strPassword = txtPassword.Value.Trim();
        if (string.IsNullOrEmpty(strPassword) || strPassword.Length < 6 || strPassword.Length > 50)
        {
            AlertAndBack("密码不能为空且长度于6-50之间!");
        }
        strRePassword = txtRePassword.Value.Trim();
        if (string.IsNullOrEmpty(strRePassword) || !strPassword.Equals(strRePassword))
        {
            AlertAndBack("两次密码不一致!");
        }
        strEmail = txtEmail.Value.Trim();
        if (string.IsNullOrEmpty(strEmail))
        {
            AlertAndBack("邮箱不能为空!");
        }

        if (!chkAgreement.Checked)
        {
            AlertAndBack("请仔细阅读注册协议。");
        }

        LFL.Favorite.BLL.UserBll bll = new LFL.Favorite.BLL.UserBll();
        if (bll.Exists(strUsername, strEmail))
        {
            AlertAndBack("该用户名或邮箱已经被注册!");
        }


        DateTime dtmNow          = DateTime.Now;
        string   strActivateCode = MD5Util.ToMD5(dtmNow.ToString("yyyyss7MMddongmmHH"));

        user.Username     = strUsername;
        user.Nickname     = strUsername;
        user.Password     = MD5Util.ToMD5(strPassword);
        user.Email        = strEmail;
        user.Sex          = "保密";
        user.ActivateCode = strActivateCode;
        user.RegTime      = dtmNow;
        user.RegIP        = WebAgent.GetIP();
        user.LoginCount   = 0;
        user.Level        = 0;
        user.Credit       = 0;
        user.Status       = 0; //


        try
        {
            bll = new LFL.Favorite.BLL.UserBll();
            bll.Add(user);
        }
        catch (Exception ex)
        {
            WebLog.WriteErrLog("注册失败!原因:" + ex.Message);
            AlertAndBack("注册失败!原因:" + ex.Message);
        }

        try
        {
            SendActiveCodeEmail(strEmail, strUsername, strPassword, strActivateCode);
        }
        catch (Exception ex)
        {
            WebLog.WriteErrLog("发送注册邮件失败!原因:" + ex.Message);
            AlertAndBack("发送注册邮件失败!原因:" + ex.Message);
        }

        WebLog.WriteInfoLog("注册用户名:" + user.Username + ", Email:" + user.Email + "成功!");


        //成功
        lblUsername.Text = strUsername;
        lblPassword.Text = strPassword;
        hdRegTime.Value  = dtmNow.ToString("yyyyss7MMddongmmHH");
        regForm.Visible  = false;
        regOk.Visible    = true;
    }