312 lines
13 KiB
JavaScript
312 lines
13 KiB
JavaScript
var $lost_psd_valid = false;
|
||
var lost_psd_time = 60;
|
||
|
||
$(function(){
|
||
$("#change_user_email").on("click", function(){
|
||
$("#change_user_email_block").toggle();
|
||
});
|
||
|
||
$("#lost_psd_input").on("blur", function(){
|
||
if (/^1\d{10}$/.test($("#lost_psd_input").val())){
|
||
$.get(
|
||
'/account/valid_register_user',
|
||
{ valid: "phone",
|
||
value: $("#lost_psd_input").val() },
|
||
function (data) {
|
||
if (data.valid) {
|
||
$('#user_phone_notice').html('');
|
||
$('#user_phone_notice').parent().hide();
|
||
$("#user_phone_check").removeClass("fa-times-circle").removeClass("color-orenge").addClass("fa-check").addClass("color-light-green");
|
||
$lost_psd_valid = true;
|
||
} else {
|
||
$('#user_phone_notice').html(data.message);
|
||
$('#user_phone_notice').parent().show();
|
||
$("#user_phone_check").removeClass("fa-check").removeClass("color-light-green").addClass("fa-times-circle").addClass("color-orenge");
|
||
$lost_psd_valid = false;
|
||
}
|
||
});
|
||
} else if(/^[a-zA-Z0-9]+([._\\]*[a-z0-9])*@([a-z0-9]+[-a-z0-9]*[a-z0-9]+.){1,63}[a-z0-9]+$/.test($("#lost_psd_input").val())){
|
||
$.get('/account/valid_register_user',
|
||
{ valid: "mail",
|
||
value: $("#lost_psd_input").val() },
|
||
function (data) {
|
||
if (data.valid) {
|
||
$('#user_phone_notice').html('');
|
||
$('#user_phone_notice').parent().hide();
|
||
$("#user_phone_check").removeClass("fa-times-circle").removeClass("color-orenge").addClass("fa-check").addClass("color-light-green");
|
||
$lost_psd_valid = true;
|
||
} else {
|
||
$('#user_phone_notice').html(data.message);
|
||
$('#user_phone_notice').parent().show();
|
||
$("#user_phone_check").removeClass("fa-check").removeClass("color-light-green").addClass("fa-times-circle").addClass("color-orenge");
|
||
$lost_psd_valid = false;
|
||
}
|
||
});
|
||
} else{
|
||
$lost_psd_valid = false;
|
||
$('#user_phone_notice').html('请输入有效的邮箱或手机号');
|
||
$('#user_phone_notice').parent().show();
|
||
$("#user_phone_check").removeClass("fa-check").removeClass("color-light-green").addClass("fa-times-circle").addClass("color-orenge");
|
||
return false;
|
||
}
|
||
});
|
||
|
||
$("#new_psd_submit").on("click", function(){
|
||
var length = parseInt($("#password_min_length").val());
|
||
if($("#new_password").val().length < length){
|
||
$('#new_password_notice').parent().show();
|
||
} else{
|
||
$('#new_password_notice').parent().hide();
|
||
if($("#new_password").val() != $("#new_password_confirmation").val()) {
|
||
$('#new_password_confirmation_notice').parent().show();
|
||
} else{
|
||
$('#new_password_confirmation_notice').parent().hide();
|
||
$("#new_psd_submit").parent().parent().parent().submit();
|
||
}
|
||
}
|
||
});
|
||
});
|
||
|
||
function settime(btn){
|
||
if (lost_psd_time==0) {
|
||
$(btn).removeClass("rest-btn-ver");
|
||
btn.removeAttribute("disabled");
|
||
btn.innerHTML = "获取验证码";
|
||
lost_psd_time = 60;
|
||
return;
|
||
}else{
|
||
$(btn).addClass("rest-btn-ver");
|
||
btn.setAttribute("disabled", "disabled");
|
||
btn.innerHTML = lost_psd_time + "s后重试";
|
||
lost_psd_time--;
|
||
}
|
||
setTimeout(function(){
|
||
settime(btn);
|
||
},1000);
|
||
}
|
||
|
||
function get_psd_verification_code(btn){
|
||
if($lost_psd_valid){
|
||
if($('.drag_text').html() == "验证通过") {
|
||
btn.setAttribute("disabled", "disabled");
|
||
$.get(
|
||
'/account/get_verification_code',
|
||
{ value: $('#lost_psd_input').val().trim(),
|
||
type: 2},
|
||
function (data) {
|
||
if (data.status == "2") {
|
||
$('#user_phone_notice').html('该手机号或邮箱未注册');
|
||
$('#user_phone_notice').parent().show();
|
||
btn.removeAttribute("disabled");
|
||
} else {
|
||
$('#user_phone_notice').html('');
|
||
$('#user_phone_notice').parent().hide();
|
||
settime(btn);
|
||
if(data.status == "3"){
|
||
$("#ver_code_type").val(3);
|
||
$("#send_success_notice").html("验证码已发送到您的邮箱,去<a href='http://mail." + data.link + "' style='color: #6a8abe; text-decoration: underline;' target='_blank'>查收</a>");
|
||
$("#send_success_notice").show();
|
||
} else{
|
||
$("#ver_code_type").val(2);
|
||
$("#send_success_notice").html("验证码已发送到您的手机,请注意查收");
|
||
$("#send_success_notice").show();
|
||
}
|
||
}
|
||
});
|
||
} else{
|
||
$("#user_verification_notice").html("请先拖动滑块完成验证");
|
||
$('#user_verification_notice').parent().show();
|
||
}
|
||
}
|
||
}
|
||
|
||
function lost_psd_next(){
|
||
if($("#lost_psd_next_a").hasClass('new_login_submit_disable')){
|
||
return;
|
||
}
|
||
if($lost_psd_valid){
|
||
if($('.drag_text').html() == "验证通过"){
|
||
if($("#psd_verification_code").val().trim() == ""){
|
||
$("#psd_verification_code").html("请输入验证码");
|
||
$("#phone_verification_code_notice").parent().show();
|
||
} else{
|
||
$("#phone_verification_code_notice").html("");
|
||
$("#phone_verification_code_notice").parent().hide();
|
||
$.get(
|
||
'/account/valid_verification_code',
|
||
{ phone: $("#lost_psd_input").val().trim(),
|
||
code: $("#psd_verification_code").val().trim(),
|
||
type: $("#ver_code_type").val()},
|
||
function (data) {
|
||
if (data.valid) {
|
||
$("#phone_verification_code_notice").html("");
|
||
$("#phone_verification_code_notice").parent().hide();
|
||
$("#lost_psd_next_a").addClass("new_login_submit_disable");
|
||
window.location.href = "/account/reset_psd?value="+$("#lost_psd_input").val().trim();
|
||
} else {
|
||
$("#phone_verification_code_notice").html("手机验证码错误或过期");
|
||
$("#phone_verification_code_notice").parent().show();
|
||
}
|
||
});
|
||
}
|
||
} else{
|
||
$("#user_verification_notice").html("请先拖动滑块完成验证");
|
||
$('#user_verification_notice').parent().show();
|
||
}
|
||
} else{
|
||
$('#lost_psd_input').blur();
|
||
}
|
||
}
|
||
|
||
function submit_user_emails(id){
|
||
if (/^[a-zA-Z0-9]+([._\\]*[a-z0-9])*@([a-z0-9]+[-a-z0-9]*[a-z0-9]+.){1,63}[a-z0-9]+$/.test($("#user_new_email").val()) == false){
|
||
$('#mail_req').html("请输入有效的邮箱地址").show();
|
||
return ;
|
||
} else{
|
||
$.get('/account/valid_ajax',
|
||
{ valid: "mail",
|
||
value: $("#user_new_email").val() },
|
||
function (data) {
|
||
if (data.valid) {
|
||
$('#mail_req').html("");
|
||
$.get('/account/change_email',
|
||
{ valid: "mail",
|
||
value: $("#user_new_email").val(),
|
||
user_id: id
|
||
},
|
||
function (change_data){
|
||
$("#user_email_show").html(change_data.email);
|
||
$("#user_email_link").attr('href', 'http://mail.' + change_data.email_link);
|
||
$("#user_new_email").val("");
|
||
$("#change_user_email_block").toggle();
|
||
return;
|
||
});
|
||
} else {
|
||
$('#mail_req').html("该邮箱已注册");
|
||
}
|
||
$('#mail_req').show();
|
||
});
|
||
}
|
||
}
|
||
|
||
function loginin(){
|
||
$('#main_login_form').submit(); //表单提交没有任何反应的原因:js冲突
|
||
}
|
||
|
||
function phone_register(){
|
||
if($("#regist_btn_phone").hasClass('new_login_submit_disable')){
|
||
return;
|
||
}
|
||
if($phone_correct && $passwd_1_correct){
|
||
if($("#phone_verification_code").val().trim() == ""){
|
||
$("#phone_verification_code_notice").html("请输入手机验证码");
|
||
$("#phone_verification_code_notice").parent().show();
|
||
} else{
|
||
$("#phone_verification_code_notice").html("");
|
||
$("#phone_verification_code_notice").parent().hide();
|
||
if($("#read_and_confirm_1").attr("checked") == 'checked'){
|
||
$("#user_aggre_1_notice").html("");
|
||
$("#user_aggre_1_notice").parent().hide();
|
||
$.get(
|
||
'/account/valid_verification_code',
|
||
{ phone: $("#user_phone_num").val().trim(),
|
||
code: $("#phone_verification_code").val().trim(),
|
||
type: 1},
|
||
function (data) {
|
||
if (data.valid) {
|
||
$("#phone_verification_code_notice").html("");
|
||
$("#phone_verification_code_notice").parent().hide();
|
||
$("#main_reg_form").submit();
|
||
$("#regist_btn_phone").addClass("new_login_submit_disable");
|
||
} else {
|
||
$("#phone_verification_code_notice").html("手机验证码错误或过期");
|
||
$("#phone_verification_code_notice").parent().show();
|
||
}
|
||
});
|
||
} else{
|
||
$("#user_aggre_1_notice").html("如果要继续请选中此框");
|
||
$("#user_aggre_1_notice").parent().show();
|
||
}
|
||
}
|
||
}else{
|
||
$('#user_phone_num').blur();
|
||
$('#user_password_1').blur();
|
||
}
|
||
}
|
||
|
||
function email_register(){
|
||
if($("#regist_btn_email").hasClass('new_login_submit_disable')){
|
||
return;
|
||
}
|
||
if($mail_correct && $passwd_2_correct){
|
||
if($("#read_and_confirm_2").attr("checked") == 'checked'){
|
||
$("#user_aggre_2_notice").html("");
|
||
$("#user_aggre_2_notice").parent().hide();
|
||
$("#main_reg_email_form").submit();
|
||
$("#regist_btn_email").addClass("new_login_submit_disable");
|
||
} else{
|
||
$("#user_aggre_2_notice").html("如果要继续请选中此框");
|
||
$("#user_aggre_2_notice").parent().show();
|
||
}
|
||
}else{
|
||
$('#user_email_addr').blur();
|
||
$('#user_password_2').blur();
|
||
}
|
||
}
|
||
|
||
(function($){
|
||
$.fn.drag = function(options){
|
||
var x, drag = this, isMove = false, defaults = {
|
||
};
|
||
var options = $.extend(defaults, options);
|
||
//添加背景,文字,滑块
|
||
var html = '<div class="drag_bg"></div>'+
|
||
'<div class="drag_text" onselectstart="return false;" unselectable="on">拖动滑块验证</div>'+
|
||
'<div class="handler handler_bg"></div>';
|
||
this.append(html);
|
||
|
||
var handler = drag.find('.handler');
|
||
var drag_bg = drag.find('.drag_bg');
|
||
var text = drag.find('.drag_text');
|
||
var maxWidth = drag.width() - handler.width(); //能滑动的最大间距
|
||
|
||
//鼠标按下时候的x轴的位置
|
||
handler.mousedown(function(e){
|
||
isMove = true;
|
||
x = e.pageX - parseInt(handler.css('left'), 10);
|
||
});
|
||
|
||
//鼠标指针在上下文移动时,移动距离大于0小于最大间距,滑块x轴位置等于鼠标移动距离
|
||
$(document).mousemove(function(e){
|
||
var _x = e.pageX - x;
|
||
if(isMove){
|
||
if(_x > 0 && _x <= maxWidth){
|
||
handler.css({'left': _x});
|
||
drag_bg.css({'width': _x});
|
||
}else if(_x > maxWidth){ //鼠标指针移动距离达到最大时清空事件
|
||
dragOk();
|
||
}
|
||
}
|
||
}).mouseup(function(e){
|
||
isMove = false;
|
||
var _x = e.pageX - x;
|
||
if(_x < maxWidth){ //鼠标松开时,如果没有达到最大距离位置,滑块就返回初始位置
|
||
handler.css({'left': 0});
|
||
drag_bg.css({'width': 0});
|
||
}
|
||
});
|
||
|
||
//清空事件
|
||
function dragOk(){
|
||
handler.removeClass('handler_bg').addClass('handler_ok_bg');
|
||
text.text('验证通过');
|
||
drag.css({'color': '#fff'});
|
||
handler.unbind('mousedown');
|
||
$(document).unbind('mousemove');
|
||
$(document).unbind('mouseup');
|
||
$("#user_verification_notice").html("");
|
||
$('#user_verification_notice').parent().hide();
|
||
}
|
||
};
|
||
})(jQuery);
|