Authored by ccbikai(👎🏻🍜)

Merge remote-tracking branch 'origin/feature/geetest' into gray

'use strict';
const _ = require('lodash');
const Geetest = require('geetest');
const logger = global.yoho.logger;
const captcha = new Geetest({
geetest_id: 'bce95d796bc3058615fdf2ec2c0aef29',
... ... @@ -50,8 +51,10 @@ const geetest = {
seccode
}).then(function(success) {
if (success) {
logger.info('geetest success');
return next();
}
logger.info('geetest faild');
return res.send(errRes);
});
}
... ...
... ... @@ -144,6 +144,16 @@ const local = {
});
},
international: (req, res) => {
// 是否关闭账号登录
let closePassword = _.get(req.app.locals.wap, 'close.passwordLogin', false);
if (closePassword) {
return res.redirect(`/signin.html?refer=${req.query.refer || ''}`);
}
if (req.session.captchaValidCount == null) { // eslint-disable-line
req.session.captchaValidCount = 5;
}
// 先清除cookie
// res.clearCookie('LE' + md5('_LOGIN_EXPIRE'), {
// domain: 'yohobuy.com'
... ...
... ... @@ -4,7 +4,7 @@
* @date: 2015/10/8
*/
var $ = require('yoho-jquery');
var ImgCheck = require('plugin/img-check');
var Validate = require('plugin/validata');
var $phoneNum = $('#phone-num'),
$countrySelect = $('#country-select'),
... ... @@ -23,7 +23,7 @@ var tip = require('plugin/tip');
var trim = $.trim;
var showErrTip = tip.show;
var imgCheck = new ImgCheck($captcha, {
var validate = new Validate($captcha, {
useREM: {
rootFontSize: 40,
picWidth: 150
... ... @@ -31,7 +31,7 @@ var imgCheck = new ImgCheck($captcha, {
});
if ($captcha.data('init') != null) { //eslint-disable-line
imgCheck.init();
validate.init();
}
... ... @@ -85,82 +85,68 @@ $countrySelect.change(function() {
$loginBtn.on('touchstart', function() {
var pn = trim($phoneNum.val()),
areaCode = $countrySelect.val(),
pwd = trim($pwd.val()),
captcha = null;
pwd = trim($pwd.val());
if ($loginBtn.hasClass('disable')) {
return;
}
if (imgCheck.atWorking) {
captcha = imgCheck.getResults();
if (captcha === '0000') {
return tip.show(' 请将图片旋转到正确方向');
}
}
if ((api.phoneRegx[areaCode].test(pn) || areaCode !== '+86') && api.pwdValidate(pwd)) {
$loginBtn.text('正在登录...').addClass('disable');
let validResult = validate.getResults();
if ((api.phoneRegx[areaCode].test(pn) || areaCode !== '+86') && api.pwdValidate(pwd)) {
let data = {
areaCode: areaCode.replace('+', ''),
account: pn,
password: pwd
};
if (imgCheck.atWorking) {
$.extend(data, {captcha});
if (typeof validResult === 'string') {
if (validResult === '0000') {
return tip.show(' 请将图片旋转到正确方向');
}
validResult = Promise.resolve({captcha: validResult});
}
validResult.then((captcha) => {
$loginBtn.text('正在登录...').addClass('disable');
let data = {
areaCode: areaCode.replace('+', ''),
account: pn,
password: pwd
};
if (validate.atWorking) {
$.extend(data, captcha);
}
$.ajax({
type: 'POST',
url: '/passport/login/auth',
data,
success: function(data) {
var res,
time;
if (data.code === 200) {
res = data.data;
showErrTip('登录成功');
$.ajax({
url: res.session,
dataType: 'jsonp',
success: function() {
clearTimeout(time);
// Cookie写入成功后,1s后跳转页面
setTimeout(function() {
location.href = res.href;
}, 1000);
$.ajax({
type: 'POST',
url: '/passport/login/auth',
data,
success: function(data) {
var res;
if (data.code === 200) {
res = data.data;
showErrTip('登录成功');
// 3秒后强制跳转
setTimeout(function() {
location.href = res.href;
}, 1500);
$loginBtn.text('登录成功').off();
showErrTip('登录成功');
} else {
if (data.captchaShow) {
validate.atWorking ? ((data.changeCaptcha || validate.type === 2) && validate.refresh()) : validate.init();
}
});
// 3秒后强制跳转
time = setTimeout(function() {
location.href = res.href;
}, 3000);
$loginBtn.text('登录成功').off();
showErrTip('登录成功');
} else {
if (data.captchaShow) {
imgCheck.atWorking ? imgCheck.refresh() : imgCheck.init();
showErrTip(data.message);
resetForm();
}
},
error: function() {
showErrTip('网络断开连接啦~');
$loginBtn.text('登录');
showErrTip(data.message);
resetForm();
validate.atWorking && validate.refresh();
}
},
error: function() {
showErrTip('网络断开连接啦~');
$loginBtn.text('登录');
imgCheck.atWorking && imgCheck.refresh();
}
});
});
} else {
showErrTip('账号或密码有错误,请重新输入');
... ...