57 lines
2.1 KiB
JavaScript
57 lines
2.1 KiB
JavaScript
function getCookie(name) {
|
|
var cookieValue = null;
|
|
if (document.cookie && document.cookie !== '') {
|
|
var cookies = document.cookie.split(';');
|
|
for (var i = 0; i < cookies.length; i++) {
|
|
var cookie = jQuery.trim(cookies[i]);
|
|
// Does this cookie string begin with the name we want?
|
|
if (cookie.substring(0, name.length + 1) === (name + '=')) {
|
|
cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
return cookieValue;
|
|
}
|
|
var csrftoken = getCookie('csrftoken');
|
|
|
|
//刷新验证码
|
|
function refresh_captcha(event){
|
|
$.get("/captcha/refresh/?"+Math.random(), function(result){
|
|
$('#'+event.data.form_id+' .captcha').attr("src",result.image_url);
|
|
$('#'+event.data.form_id+' .form-control-captcha[type="hidden"]').attr("value",result.key);
|
|
});
|
|
return false;
|
|
}
|
|
|
|
function send_email_capter(){
|
|
var email = $("#id_email").val();
|
|
if (email == null || email == undefined || email.trim() == '') {
|
|
alert("邮箱不能为空");
|
|
return;
|
|
}
|
|
|
|
$.ajax({
|
|
cache: false,
|
|
type: "POST",
|
|
url: '/users/send_email_code/',
|
|
data: { 'email':email },
|
|
dataType: 'json',
|
|
async: true,
|
|
beforeSend: function (xhr, settings) {
|
|
xhr.setRequestHeader("X-CSRFToken", csrftoken);
|
|
},
|
|
success: function (data) {
|
|
console.log(data.msg)
|
|
}
|
|
});
|
|
}
|
|
|
|
//注册刷新验证码点击事件
|
|
$('#email_register_form .captcha-refresh').click({'form_id':'email_register_form'},refresh_captcha);
|
|
$('#email_register_form .captcha').click({'form_id':'email_register_form'},refresh_captcha);
|
|
$('#mobile_register_form .captcha').click({'form_id':'jsRefreshCode'},refresh_captcha);
|
|
$('#changeCode').click({'form_id':'jsRefreshCode'},refresh_captcha);
|
|
$('#jsFindPwdForm .captcha-refresh').click({'form_id':'jsFindPwdForm'},refresh_captcha);
|
|
$('#jsFindPwdForm .captcha').click({'form_id':'jsFindPwdForm'},refresh_captcha);
|
|
$('#jsChangePhoneForm .captcha').click({'form_id':'jsChangePhoneForm'},refresh_captcha); |