实现效果展示:

 

 前台表单页面:

<form action="" method="POST" role="form"   id="form">
        <!-- <form action="/Home/Download/reset.html" method="POST" role="form"  class="login-form"> -->
        <legend>重置密码</legend>
        <p class="yanzheng">
            <span>1</span>邮箱验证
        </p>

        <div class="form-group yzm">
            <input type="text"  class="email" id="email"  name="email"  placeholder="请输入邮箱" required />
            <div>
                <button type="button" style="margin-bottom: 10px" class="btn btn-primary send" >邮箱验证</button>
            </div>
        </div>

        <div class="form-group yzm">
            <input type="text" class="focus_input" name="cen-code" id="cen-code" placeholder="邮箱验证码"  >
        </div>

        <p class="yanzheng">
            <span>2</span>重新设置密码
        </p>
        <div class="form-group mm">
            <input type="password" class="focus_input" id="password"  name="password" required placeholder="请设置新的密码" >
        </div>
        <div class="form-group mm">
            <input type="password" class="focus_input" id="repassword"  name="repassword"  required  placeholder="请再次设置新的密码" >
        </div> 

        <button type="button" class="btn btn-primary chongzhi " >确定重置</button>

    </form>


<script >

$('.chongzhi').click(function(){

if(!$('#cen-code').val()){
layer.msg('请输入验证码');
$('#cen-code').focus();
return false;
}
if(!$('#password').val()){
layer.msg('请输入密码');
$('#password').focus();
return false;
}
if($('#password').val() != $('#repassword').val()){
layer.msg('两次密码不一样');
return false;
}
$.ajax({
type: "POST",
dataType: "json",
url: '/Download/reset',
data: $('#form').serialize(),
success: function (data) {
layer.alert(data.msg)
$('.chongzhi').html('确定重置');
$('.chongzhi').removeAttr('disabled');
if(data.code == 1){
window.location.href = '/download/login';
}
},
beforeSend: function () {
$('.chongzhi').html('提交中...');
$('.chongzhi').attr('disabled',true);
},
error: function (data) {
layer.msg("error:" + data.responseText);

}

});
})

$('.send').click(function () {
if(!$('#email').val()){
layer.msg('请输入邮箱');
$('#email').focus();
return false;
}
$.ajax({
type: "POST",
dataType: "json",
url: '/Download/yanzheng',
data: $('#form').serialize(),
success: function (data) {
layer.msg(data.msg)
$('.send').html('邮箱验证');
$('.send').removeAttr('disabled');
},
beforeSend: function () {
$('.send').html('邮件发送中...');
$('.send').attr('disabled',true);
},
error: function (data) {
layer.msg("error:" + data.responseText);

}

});
})

</script>



后台处理:

 public function reset() {
        if (IS_POST) {
            $email = I('email');
            $code = I('cen-code');
            $password = I('password');
            $repassword = I('repassword');

            if ($_SESSION[$email]['yanzhengma'] != $code) {
                $this->ajaxReturn([
                    'code' => '-1',
                    'msg' => '验证码错误',
                ]);
            }
            if ($password != $repassword) {
                $this->ajaxReturn([
                    'code' => '-1',
                    'msg' => '两次密码不一致',
                ]);
            }

            $user = M('Member')->where(['email' => $email])->find();
            if (!$user) {
                $this->ajaxReturn([
                    'code' => '-1',
                    'msg' => '用户不存在',
                ]);
            }
            // $password = $this->frontthinkUcenterMd5($password, C(DATA_AUTH_KEY));
            $res = M("Member")->where(['email' => $email])->save(array('password' => $password));
            unset($_SESSION[$email]);
            if ($res !== false) {
                $this->ajaxReturn([
                    'code' => '1',
                    'msg' => '重置成功',
                ]);
            }
        }
        $this->display();
    }

//验证邮箱
    public function yanzheng() {
        $email = I('email');
        $user = M('Member')->where(['email' => $email])->find();

        if (!$email) {
            $this->ajaxReturn([
                'code' => -1,
                'msg' => '请输入邮箱',
            ]);
            return;
        }

        if (!$user) {
            $this->ajaxReturn([
                'code' => -1,
                'msg' => '邮箱不存在',
            ]);
            return;
        }

        $mixNum = range(100001, 999999);
        shuffle($mixNum);
        $randNum = $mixNum[0]; //随机生成六位数
        // 邮件标题
        $title = '您有一条新邮件';
        // 邮件内容
        $content = "您的验证码是:<font style='font-size:30px;fonta-weight:bold;'>{$randNum}</font>";
        $res = think_send_mail($email, $title, $title, $content);

        if ($res == false) {
            $this->ajaxReturn([
                'code' => -1,
                'msg' => "发送邮件失败",
            ]);
            return;
        }
        $_SESSION[$email] = [
            'yanzhengma' => $randNum
        ];
        $this->ajaxReturn([
            'code' => 1,
            'msg' => "验证码已发送,请登录邮箱获取验证码!",
        ]);
    }