인증 코드 효과와 백엔드 코드 가져오기

8567 단어
클라이언트 js+html 코드
<script type="text/javascript">
        var tcode = 0;//       
     //     
        function GetVerifyCodeAction() {
            var email = $("#email").val();
            if (!checkEmail(email)) {
                $("#area_error").addClass("log-tips").show().text(EmailFormatIsFault);//      
            }
            else {
                $.ajax({
                    type: "post",
                    async: false,
                    url: "/Handler/SendMsgToMail.ashx",
                    data: { op: 12, email: email },
                    success: function (result) {
                        var data = parseInt(result);
                        switch (data) {
                            case 1:
                                $("#area_error").addClass("log-tips").show().text(CheckVerifyCode);//      ,     
                                $("#btnSendCode").removeAttr("onclick");//        click  
                                tcode = setInterval("ReSend()", 1000);//     ,60        
                                break;
                            case -1:
                                $("#area_error").addClass("log-tips").show().text(FillEmail);//     
                                break;
                            case -2:
                                $("#area_error").addClass("log-tips").show().text(MailNotReg);//      
                                break;
                            case -3:
                                $("#area_error").addClass("log-tips").show().text(OperateException);//    
                                break;
                            case -4:
                                $("#area_error").addClass("log-tips").show().text(OperateException);//    
                                break;
                            case -5:
                                $("#area_error").addClass("log-tips").show().text(OnceMinute);//         
                                break;
                            default:
                                $("#area_error").addClass("log-tips").show().text(OperateException);//    
                                break;
                        }
                    }
                });
            }
            return false;
        }
    //       
        function GoNext() {
            $("#area_error").removeClass("log-tips").text("").hide();
            var email = $("#email").val();
            if (!checkEmail(email)) {
                $("#area_error").addClass("log-tips").show().text(EmailFormatIsFault);//       
                return false;
            }
            var vcode = $("#verify").val();
            if (vcode == "") {
                $("#area_error").addClass("log-tips").show().text(FillVerifyCode);//      
                return false;
            }
        //         
            $.ajax({
                type: "post",
                url: "/Handler/Members.ashx",
                data: { op: 14, email: email, vcode: vcode },
                success: function (result) {
                    if (result == "-1") {
                        $("#area_error").addClass("log-tips").show().text(VCodeIsNotAvailable);//      
                    }
                    if (result == "1") {
                        window.location = "forgot_password.aspx?email=" + email + "&vcode=" + vcode;
                    }
                }
            });
        }
     //   
        function ReSend() {
       var Wait60Second="60    ";
            var TotalCount = $("#hf_timecount").val();
            TotalCount = TotalCount - 1;
            $("#hf_timecount").val(TotalCount);

            if (TotalCount == 0) {
                ReSetSendMail();
            }
            else {
                $("#btnSendCode").text(Wait60Second.replace("60", TotalCount));
            }
        }
     // function ReSetSendMail() { clearInterval(tcode); $("#hf_timecount").val("60"); $("#btnSendCode").text(" "); $("#btnSendCode").attr("onclick", "GetVerifyCodeAction()"); } </script>
<input id="hf_timecount" value="60" type="hidden" />
<input type="text" name="email" id="email" />
<button type="button" id="btnSendCode" onclick="GetVerifyCodeAction()"> </button>
<input type="text" name="verify" id="verify" />
<input type="button" id="btn_next" value=" " onclick="GoNext()"/>

  
서버 코드:
/// <summary>
        ///     
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public string SendMail(HttpContext context)
        {
            try
            {
                if (!string.IsNullOrEmpty(CookiesHelper.getCookie("send_mail_limit")))
                {
                    return "-5";//         
                }
                string email = context.Request["email"];
                if (string.IsNullOrEmpty(email) || !CommonHelper.IsValidEmail(email))
                {
                    return "-1";//    
                }
                //        
                BLL.Web.Member bllMember = new BLL.Web.Member();
                int mailCount = bllMember.GetCountByEmail(email);
                Models.Web.Member member = bllMember.GetModelByEmail(email);

                if (mailCount == 0 || member == null)
                {
                    return "-2";//   
                }

                string vcode = CommonHelper.RandCode(8);

                Models.Web.VerifyCode model = new Models.Web.VerifyCode();
                model.v_code = vcode;
                model.v_createdate = DateTime.Now;
                model.v_enddate = DateTime.Now.AddHours(2);
                model.v_status = 0;
                model.v_email = email;

                BLL.Web.VerifyCode bllVC = new BLL.Web.VerifyCode();
                int no = bllVC.Append(model);
                if (no > 0)
                {
                    string sendText = "";
                    string tempPath = context.Server.MapPath("~/EmailTemp/ModifyPwd.txt");

                    using (StreamReader sr = new StreamReader(tempPath))
                    {
                        sendText = sr.ReadToEnd();
                    }
                    sendText = sendText.Replace("{UserName_CH}", member.PersnalName);
                    sendText = sendText.Replace("{UserName_EN}", member.PersnalName);
                    sendText = sendText.Replace("{VCode}", vcode);

                    CommonHelper.SendEmail(email, sendText, Resource.Lang.RetrievePassword);
                    CookiesHelper.setCookie("send_mail_limit", "SendMail", 1.00);
                }
                else
                {
                    return "-3";//       ,   !
                }

                return "1";//  
            }
            catch (Exception)
            {
                return "-4";//  
            }
        }

  

좋은 웹페이지 즐겨찾기