...
|
...
|
@@ -5,8 +5,7 @@ |
|
|
|
|
|
var $ = require('yoho-jquery'),
|
|
|
regValidate = require('../common/mail-phone-regx'),
|
|
|
computeComplex = require('../common/pwd-strength'),
|
|
|
Captcha = require('../../plugins/captcha');
|
|
|
computeComplex = require('../common/pwd-strength');
|
|
|
|
|
|
var $registerPage = $('.register-page'),
|
|
|
$pwdTips = $('#pwd-tips'),
|
...
|
...
|
@@ -16,19 +15,18 @@ var $registerPage = $('.register-page'), |
|
|
$countDown = $('#count-down'),
|
|
|
$successBtn = $('.success-btn'),
|
|
|
countDown = 5,
|
|
|
clearT,
|
|
|
captchaImage = new Captcha('#captcha-img').init();
|
|
|
clearT;
|
|
|
|
|
|
var $sendCaptcha = $('#send-captcha'),
|
|
|
caCount = 4,
|
|
|
validateResult = [];
|
|
|
|
|
|
var $pn = $('#phone-num'),
|
|
|
$mc = $('#msg-captcha'),
|
|
|
$pwd = $('#pwd'),
|
|
|
getCaptchaImageVal = function() {
|
|
|
return captchaImage.getResults();
|
|
|
},
|
|
|
timeSecond = 0;
|
|
|
$repwd = $('#repwd'),
|
|
|
$ca = $('#captcha'),
|
|
|
timeResidue = 0;
|
|
|
|
|
|
// 密码强度验证
|
|
|
var $pwdIntensity = $('.pwd-intensity'),
|
...
|
...
|
@@ -38,6 +36,9 @@ var $pwdIntensity = $('.pwd-intensity'), |
|
|
var $region = $('#country-code'),
|
|
|
$regionSelect = $('#region');
|
|
|
|
|
|
var isPwd = false,
|
|
|
pwdVal;
|
|
|
|
|
|
var pwdReg = regValidate.pwdValidateRegx;
|
|
|
|
|
|
var $curErrContainer;
|
...
|
...
|
@@ -47,13 +48,20 @@ var oldPhone = ''; // 如果手机号改变时刷新验证码 |
|
|
require('../../simple-header');
|
|
|
require('yoho-jquery-placeholder');
|
|
|
|
|
|
// 验证码位数
|
|
|
$ca.attr('maxlength', caCount);
|
|
|
|
|
|
// 密码规则提示
|
|
|
$pwd.focus(function() {
|
|
|
$pwdTips.removeClass('hide');
|
|
|
isPwd = true;
|
|
|
pwdVal = $(this).val();
|
|
|
}).blur(function() {
|
|
|
$pwdTips.addClass('hide');
|
|
|
isPwd = false;
|
|
|
});
|
|
|
|
|
|
|
|
|
// IE8 placeholder
|
|
|
$('[placeholder]').placeholder();
|
|
|
|
...
|
...
|
@@ -65,7 +73,7 @@ validateResult = [ |
|
|
status: false // 当前的状态
|
|
|
},
|
|
|
{
|
|
|
id: 'captcha-img',
|
|
|
id: 'captcha',
|
|
|
message: '',
|
|
|
status: false
|
|
|
},
|
...
|
...
|
@@ -86,14 +94,13 @@ validateResult = [ |
|
|
}
|
|
|
];
|
|
|
|
|
|
captchaImage.onRefresh(function() {
|
|
|
validateResult[1].message = 'err';
|
|
|
validateResult[1].status = false;
|
|
|
});
|
|
|
|
|
|
// 刷新图形验证码
|
|
|
function refreshPic() {
|
|
|
captchaImage.refresh();
|
|
|
var time = new Date(),
|
|
|
$captchaImg = $('.captcha-img'),
|
|
|
captchaImgSrc = $captchaImg.attr('src').split('?')[0];
|
|
|
|
|
|
$captchaImg.attr('src', captchaImgSrc + '?t=' + time.getTime());
|
|
|
}
|
|
|
|
|
|
// 手机号ajax校验
|
...
|
...
|
@@ -120,17 +127,13 @@ function phoneAjaxFn(page, callback) { |
|
|
validateResult[0].message = 'err';
|
|
|
validateResult[0].status = false;
|
|
|
|
|
|
return $.ajax({
|
|
|
$.ajax({
|
|
|
url: url,
|
|
|
type: 'POST',
|
|
|
data: data
|
|
|
}).then(function(res) {
|
|
|
var defer = $.Deferred();
|
|
|
|
|
|
defer.always(callback);
|
|
|
|
|
|
if (!res) {
|
|
|
return defer.reject().promise();
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
switch (res.code) {
|
...
|
...
|
@@ -140,7 +143,8 @@ function phoneAjaxFn(page, callback) { |
|
|
|
|
|
// 如果手机号发生改变则刷新验证码并且更新状态
|
|
|
refreshPic();
|
|
|
validateResult[1].message = 'err';
|
|
|
$sendCaptcha.addClass('disable').attr('disabled', 'disabled');
|
|
|
validateResult[1].message = '图形验证码错误';
|
|
|
validateResult[1].status = false;
|
|
|
}
|
|
|
|
...
|
...
|
@@ -148,28 +152,58 @@ function phoneAjaxFn(page, callback) { |
|
|
|
|
|
validateResult[0].message = '';
|
|
|
validateResult[0].status = true;
|
|
|
|
|
|
return defer.resolve().promise();
|
|
|
break;
|
|
|
case 400:
|
|
|
refreshPic();
|
|
|
validateResult[0].message = res.message;
|
|
|
validateResult[0].status = false;
|
|
|
return defer.reject().promise();
|
|
|
break;
|
|
|
default:
|
|
|
return defer.reject().promise();
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
callback();
|
|
|
});
|
|
|
}
|
|
|
|
|
|
// 图形验证码ajax校验
|
|
|
function picCaptchaAjaxFn(callback) {
|
|
|
return captchaImage.check().then(function() {
|
|
|
validateResult[1].message = '';
|
|
|
validateResult[1].status = true;
|
|
|
}).fail(function() {
|
|
|
validateResult[1].message = 'err';
|
|
|
validateResult[1].status = false;
|
|
|
}).always(callback);
|
|
|
function picCaptchaAjaxFn(page, callback) {
|
|
|
var url;
|
|
|
|
|
|
if (page === 'reg') {
|
|
|
url = '/passport/reg/piccaptcha';
|
|
|
} else if (page === 'third') {
|
|
|
url = '/passport/autouserinfo/checkPicCode';
|
|
|
}
|
|
|
$.ajax({
|
|
|
type: 'POST',
|
|
|
url: url,
|
|
|
data: {
|
|
|
verifyCode: $ca.val()
|
|
|
|
|
|
// mobile: $pn.val(),
|
|
|
// area: $region.text().split('+')[1]
|
|
|
}
|
|
|
}).then(function(data) {
|
|
|
if (!data) {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
switch (data.code) {
|
|
|
case 200:
|
|
|
validateResult[1].message = '';
|
|
|
validateResult[1].status = true;
|
|
|
break;
|
|
|
case 400:
|
|
|
refreshPic();
|
|
|
validateResult[1].message = '图形验证码错误';
|
|
|
validateResult[1].status = false;
|
|
|
break;
|
|
|
default:
|
|
|
break;
|
|
|
}
|
|
|
callback();
|
|
|
});
|
|
|
}
|
|
|
|
|
|
// 短信验证码ajax校验
|
...
|
...
|
@@ -181,8 +215,7 @@ function msgCaptchaAjaxFn(page, callback) { |
|
|
} else if (page === 'third') {
|
|
|
url = '/passport/autouserinfo/checkBindMsg';
|
|
|
}
|
|
|
|
|
|
return $.ajax({
|
|
|
$.ajax({
|
|
|
type: 'POST',
|
|
|
url: url,
|
|
|
data: {
|
...
|
...
|
@@ -191,26 +224,24 @@ function msgCaptchaAjaxFn(page, callback) { |
|
|
area: $region.text().split('+')[1]
|
|
|
}
|
|
|
}).then(function(data) {
|
|
|
var defer = $.Deferred();
|
|
|
|
|
|
defer.always(callback);
|
|
|
|
|
|
if (!data) {
|
|
|
return defer.reject().promise();
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
switch (data.code) {
|
|
|
case 200:
|
|
|
validateResult[2].message = '';
|
|
|
validateResult[2].status = true;
|
|
|
return defer.resolve().promise();
|
|
|
break;
|
|
|
case 400:
|
|
|
validateResult[2].message = '短信验证码错误';
|
|
|
validateResult[2].status = false;
|
|
|
return defer.reject().promise();
|
|
|
break;
|
|
|
default:
|
|
|
return defer.reject().promise();
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
callback();
|
|
|
});
|
|
|
}
|
|
|
|
...
|
...
|
@@ -220,68 +251,80 @@ function validateRule(page, $element, callback) { |
|
|
var val = $.trim($element.val()),
|
|
|
regionCode;
|
|
|
|
|
|
|
|
|
// 根据需求http://redmine.yoho.cn/issues/3117改成上边的正则
|
|
|
// 对应的错误提示语也改了,感觉要不了多久就会改回来
|
|
|
// pwdReg = /^([a-zA-Z0-9\-\+_!@\#$%\^&\*\(\)\:\;\.=\[\]\\\',\?]){6,20}$/gi;
|
|
|
|
|
|
var defer = $.Deferred();
|
|
|
|
|
|
defer.always(callback);
|
|
|
|
|
|
// 手机号校验
|
|
|
if ($element.hasClass('phone-num')) {
|
|
|
|
|
|
regionCode = $region.text();
|
|
|
|
|
|
|
|
|
if (val === '') {
|
|
|
validateResult[0].message = '请输入手机号码';
|
|
|
validateResult[0].status = false;
|
|
|
return defer.reject().promise();
|
|
|
return callback();
|
|
|
|
|
|
} else {
|
|
|
if (!/^[0-9]+$/.test(val) ||
|
|
|
(regionCode === '+86' && !regValidate.phoneRegx[regionCode].test(val))) {
|
|
|
validateResult[0].message = '手机号码格式不正确,请重新输入';
|
|
|
validateResult[0].status = false;
|
|
|
return defer.reject().promise();
|
|
|
|
|
|
return callback();
|
|
|
} else {
|
|
|
return phoneAjaxFn(page, callback);
|
|
|
phoneAjaxFn(page, callback);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// 图形验证码校验
|
|
|
} else if ($element.hasClass('w330')) {
|
|
|
// 并且手机号正确
|
|
|
if (validateResult[0].status) {
|
|
|
return picCaptchaAjaxFn(callback);
|
|
|
} else if ($element.hasClass('captcha')) {
|
|
|
if (val === '') {
|
|
|
validateResult[1].message = '请输入图形验证码';
|
|
|
validateResult[1].status = false;
|
|
|
return callback();
|
|
|
|
|
|
} else {
|
|
|
validateResult[1].message = 'err';
|
|
|
} else if (val.length <= 3) {
|
|
|
validateResult[1].message = '图形验证码为4位';
|
|
|
validateResult[1].status = false;
|
|
|
return defer.reject().promise();
|
|
|
return callback();
|
|
|
|
|
|
} else {
|
|
|
|
|
|
// 并且手机号正确
|
|
|
if (validateResult[0].status) {
|
|
|
picCaptchaAjaxFn(page, callback);
|
|
|
} else {
|
|
|
validateResult[1].message = '图形验证码错误';
|
|
|
validateResult[1].status = false;
|
|
|
return callback();
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
// 短信验证码校验
|
|
|
} else if ($element.hasClass('msg-captcha')) {
|
|
|
|
|
|
if (val === '') {
|
|
|
validateResult[2].message = '请输入短信验证码';
|
|
|
validateResult[2].status = false;
|
|
|
return defer.reject().promise();
|
|
|
return callback();
|
|
|
|
|
|
} else if (val.length <= 3) {
|
|
|
validateResult[2].message = '短信验证码错误';
|
|
|
validateResult[2].status = false;
|
|
|
return defer.reject().promise();
|
|
|
return callback();
|
|
|
|
|
|
} else {
|
|
|
|
|
|
// 并且图形验证码正确
|
|
|
if (validateResult[1].status) {
|
|
|
return msgCaptchaAjaxFn(page, callback);
|
|
|
msgCaptchaAjaxFn(page, callback);
|
|
|
} else {
|
|
|
validateResult[2].message = '短信验证码错误';
|
|
|
validateResult[2].status = false;
|
|
|
return defer.reject().promise();
|
|
|
return callback();
|
|
|
}
|
|
|
}
|
|
|
|
...
|
...
|
@@ -290,23 +333,39 @@ function validateRule(page, $element, callback) { |
|
|
if (val === '') {
|
|
|
validateResult[3].message = '请输入密码';
|
|
|
validateResult[3].status = false;
|
|
|
return defer.reject().promise();
|
|
|
|
|
|
} else if (val.length < 6 || val.length > 20) {
|
|
|
validateResult[3].message = '密码只支持6-20位字符';
|
|
|
validateResult[3].status = false;
|
|
|
return defer.reject().promise();
|
|
|
|
|
|
} else if (!pwdReg.test($element.val())) {
|
|
|
validateResult[3].message = '密码须字母和数字组合';
|
|
|
validateResult[3].status = false;
|
|
|
return defer.reject().promise();
|
|
|
|
|
|
} else {
|
|
|
validateResult[3].message = '';
|
|
|
validateResult[3].status = true;
|
|
|
return defer.resolve().promise();
|
|
|
}
|
|
|
}
|
|
|
return callback();
|
|
|
|
|
|
// 二次密码校验
|
|
|
} else if ($element.hasClass('repwd')) {
|
|
|
if (val === '') {
|
|
|
validateResult[4].message = '请输入密码确认';
|
|
|
validateResult[4].status = false;
|
|
|
|
|
|
} else if ($pwd.val() !== val) {
|
|
|
validateResult[4].message = '与密码不一致,请重新输入';
|
|
|
validateResult[4].status = false;
|
|
|
|
|
|
} else {
|
|
|
validateResult[4].message = '';
|
|
|
validateResult[4].status = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
return defer.promise();
|
|
|
return callback();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
function posErrTip() {
|
...
|
...
|
@@ -352,7 +411,7 @@ function showBorder() { |
|
|
validateResultLen = validateResult.length;
|
|
|
|
|
|
for (i = 0; i < validateResultLen; i++) {
|
|
|
if (validateResult[i].message && validateResult[i].message !== 'err') {
|
|
|
if (validateResult[i].message) {
|
|
|
|
|
|
// 显示红色边框
|
|
|
$errInput = $('#' + validateResult[i].id);
|
...
|
...
|
@@ -430,8 +489,6 @@ $(window).resize(function() { |
|
|
// ( ▼-▼ )注册页和信息完善页面接口不同
|
|
|
exports.init = function(page) {
|
|
|
|
|
|
captchaImage.refresh();
|
|
|
|
|
|
$('#agree-terms').click(function() {
|
|
|
|
|
|
var $this = $(this),
|
...
|
...
|
@@ -494,6 +551,16 @@ exports.init = function(page) { |
|
|
} else {
|
|
|
$registerBtn.addClass('disable').attr('disabled', 'disabled');
|
|
|
}
|
|
|
|
|
|
// 图形验证通过时,发送短信按钮可点击
|
|
|
if (validateResult[1].status && timeResidue <= 0) {
|
|
|
$sendCaptcha.removeClass('disable').removeAttr('disabled');
|
|
|
} else {
|
|
|
$sendCaptcha.addClass('disable').attr('disabled', 'disabled');
|
|
|
}
|
|
|
|
|
|
// 图形验证通过时,发送短信按钮可点击 end
|
|
|
|
|
|
});
|
|
|
|
|
|
// 如果是密码则校验强度
|
...
|
...
|
@@ -501,6 +568,12 @@ exports.init = function(page) { |
|
|
pwdFn($that);
|
|
|
}
|
|
|
|
|
|
}).blur(function() {
|
|
|
|
|
|
/* validateRule($(this), function() {
|
|
|
showErrTip();
|
|
|
showBorder(); // 显示红色边框
|
|
|
});*/
|
|
|
});
|
|
|
|
|
|
$regionSelect.change(function() {
|
...
|
...
|
@@ -525,49 +598,37 @@ exports.init = function(page) { |
|
|
url = '/passport/autouserinfo/sendBindMsg';
|
|
|
}
|
|
|
|
|
|
// 1.验证图形验证码是否正确
|
|
|
// 2.验证手机号被注册过
|
|
|
// 3.发送短信
|
|
|
validateRule(page, $('#captcha-img'), function() {
|
|
|
showErrTip(); // 显示错误提示
|
|
|
showBorder(); // 显示红色边框
|
|
|
}).then(function() {
|
|
|
return validateRule(page, $pn, function() {
|
|
|
showErrTip(); // 显示错误提示
|
|
|
showBorder(); // 显示红色边框
|
|
|
});
|
|
|
}).then(function() {
|
|
|
return $.ajax({
|
|
|
type: 'POST',
|
|
|
url: url,
|
|
|
data: {
|
|
|
area: $region.text().split('+')[1],
|
|
|
mobile: $pn.val(),
|
|
|
verifyCode: getCaptchaImageVal()
|
|
|
}
|
|
|
}).then(function(result) {
|
|
|
if (result.code !== 200) {
|
|
|
validateResult[0].message = result.message;
|
|
|
validateResult[0].status = false;
|
|
|
// todo ajax 发送验证码
|
|
|
$.ajax({
|
|
|
type: 'POST',
|
|
|
url: url,
|
|
|
data: {
|
|
|
area: $region.text().split('+')[1],
|
|
|
mobile: $pn.val(),
|
|
|
verifyCode: $ca.val()
|
|
|
}
|
|
|
}).then(function(result) {
|
|
|
if (result.code !== 200) {
|
|
|
validateResult[0].message = result.message;
|
|
|
validateResult[0].status = false;
|
|
|
|
|
|
showErrTip();
|
|
|
return;
|
|
|
}
|
|
|
showErrTip();
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
$('#msg-tip').removeClass('hide');
|
|
|
timeSecond = 60;
|
|
|
$sendCaptcha.addClass('disable').attr('disabled', 'disabled');
|
|
|
$sendCaptcha.val('60秒可重新发送');
|
|
|
$('#msg-tip').removeClass('hide');
|
|
|
timeResidue = 60;
|
|
|
$sendCaptcha.addClass('disable').attr('disabled', 'disabled');
|
|
|
$sendCaptcha.val('60秒可重新发送');
|
|
|
|
|
|
t = setInterval(function() {
|
|
|
if (timeSecond <= 0) {
|
|
|
$sendCaptcha.removeClass('disable').removeAttr('disabled').val('获取短信验证码');
|
|
|
clearInterval(t);
|
|
|
return;
|
|
|
}
|
|
|
$sendCaptcha.val(timeSecond-- + '秒可重新发送');
|
|
|
}, 1000);
|
|
|
});
|
|
|
t = setInterval(function() {
|
|
|
if (timeResidue <= 0) {
|
|
|
$sendCaptcha.removeClass('disable').removeAttr('disabled').val('获取短信验证码');
|
|
|
clearInterval(t);
|
|
|
return;
|
|
|
}
|
|
|
$sendCaptcha.val(timeResidue-- + '秒可重新发送');
|
|
|
}, 1000);
|
|
|
});
|
|
|
});
|
|
|
|
...
|
...
|
@@ -599,7 +660,7 @@ exports.init = function(page) { |
|
|
data: {
|
|
|
area: $region.text().split('+')[1],
|
|
|
mobile: $pn.val(),
|
|
|
verifyCode: getCaptchaImageVal(),
|
|
|
verifyCode: $ca.val(),
|
|
|
code: $mc.val(),
|
|
|
password: $pwd.val()
|
|
|
}
|
...
|
...
|
@@ -635,13 +696,17 @@ exports.init = function(page) { |
|
|
} else {
|
|
|
|
|
|
// todo
|
|
|
alert(data.message); //eslint-disable-line
|
|
|
console.log('网络超时~');
|
|
|
}
|
|
|
|
|
|
});
|
|
|
}
|
|
|
});
|
|
|
|
|
|
$('.change-captcha').click(function() {
|
|
|
refreshPic();
|
|
|
});
|
|
|
|
|
|
// 注册成功页面5秒后跳转
|
|
|
if ($('.success-box').length > 0) {
|
|
|
clearT = setInterval(function() {
|
...
|
...
|
@@ -655,15 +720,4 @@ exports.init = function(page) { |
|
|
$countDown.text(countDown--);
|
|
|
}, 1000);
|
|
|
}
|
|
|
|
|
|
// 设置 refer 信息
|
|
|
(function() {
|
|
|
var refer = queryString().refer || ''; // eslint-disable-line
|
|
|
|
|
|
if (refer) {
|
|
|
setCookie('refer', refer); // eslint-disable-line
|
|
|
} else {
|
|
|
setCookie('refer', ''); // eslint-disable-line
|
|
|
}
|
|
|
}());
|
|
|
}; |
...
|
...
|
|