Esempio n. 1
0
        protected void btnDelete_Click(object sender, EventArgs e)
        {
            this.ChkAdminLevel("user_mail_template", DTEnums.ActionEnum.Delete.ToString());
            int           num1         = 0;
            int           num2         = 0;
            mail_template mailTemplate = new mail_template();

            for (int index = 0; index < this.rptList.Items.Count; ++index)
            {
                int int32 = Convert.ToInt32(((HiddenField)this.rptList.Items[index].FindControl("hidId")).Value);
                if (((CheckBox)this.rptList.Items[index].FindControl("chkId")).Checked)
                {
                    if (mailTemplate.Delete(int32))
                    {
                        ++num1;
                    }
                    else
                    {
                        ++num2;
                    }
                }
            }
            this.AddAdminLog(DTEnums.ActionEnum.Delete.ToString(), "删除邮件模板成功" + (object)num1 + "条,失败" + (object)num2 + "条");
            this.JscriptMsg("删除成功" + (object)num1 + "条,失败" + (object)num2 + "条!", Utils.CombUrlTxt("mail_template_list.aspx", "keywords={0}", this.keywords));
        }
        private void SendVerifyEmail(int userId, string email, Action <int, string> callback, string templateName = "emailverify")
        {
            if (userId <= 0 || string.IsNullOrWhiteSpace(email))
            {
                callback((int)HttpStatusCode.BadRequest, "缺少参数");
                return;
            }
            // verifying_email : string | last_send_verifying_mail_at : DateTime? | verifying_email_code : string
            // 限制发送的时间间隔
            var lastSendVerifyingMailAt = (DateTime?)SessionHelper.Get("last_send_verifying_mail_at");

            if (lastSendVerifyingMailAt != null && DateTime.Now.Subtract(lastSendVerifyingMailAt.Value).TotalSeconds < 60)
            {
                callback(429, "发送邮件间隔为 60 秒,您刚才已经发送过啦,休息一下再来吧!");
                return;
            }
            var context = new Agp2pDataContext();
            // 检查是否有其他用户验证过此邮箱
            var count = context.dt_users.Count(u => u.email == email);

            if (count != 0)
            {
                callback((int)HttpStatusCode.Conflict, "这个电子邮箱已经被其他用户绑定了");
                return;
            }

            var strCode = Utils.GetCheckCode(5);

            SessionHelper.Set("verifying_email", email);
            SessionHelper.Set("last_send_verifying_mail_at", DateTime.Now);
            SessionHelper.Set("verifying_email_code", strCode);

            var user = context.dt_users.Single(u => u.id == userId);

            //获得邮件内容
            var mailModel = new mail_template().GetModel(templateName);

            if (mailModel == null)
            {
                callback((int)HttpStatusCode.Gone, "邮件发送失败,邮件模板内容不存在!");
                return;
            }
            //替换模板内容
            var siteConfig = new siteconfig().loadConfig();
            var titletxt   = mailModel.maill_title
                             .Replace("{webname}", siteConfig.webname)
                             .Replace("{username}", user.user_name);
            var bodytxt = mailModel.content
                          .Replace("{webname}", siteConfig.webname)
                          .Replace("{webtel}", siteConfig.webtel)
                          .Replace("{username}", user.user_name)
                          .Replace("{valid}", SessionHelper.GetSessionTimeout().ToString())
                          .Replace("{linkurl}",
                                   "http://" + HttpContext.Current.Request.Url.Authority.ToLower() +
                                   "/user/center/index.html#/safe?action=verifyEmail&code=" + strCode)
                          .Replace("{verifyCode}", strCode);

            try
            {
                DTMail.sendMail(siteConfig.emailsmtp,
                                siteConfig.emailusername,
                                DESEncrypt.Decrypt(siteConfig.emailpassword),
                                siteConfig.emailnickname,
                                siteConfig.emailfrom,
                                email,
                                titletxt, bodytxt); //发送邮件
                callback((int)HttpStatusCode.OK, "邮件发送成功,请查收!");
            }
            catch (Exception e)
            {
                callback((int)HttpStatusCode.InternalServerError, "邮件发送失败,请联系本站管理员!");
            }
        }