Authored by ccbikai(👎🏻🍜)

Merge branch 'hotfix/login' of git.yoho.cn:fe/yohobuywap-node into hotfix/login

... ... @@ -130,11 +130,13 @@ const local = {
// 设置登录有效时间30分钟, 防机器刷,cache不稳定,改为cookie
// res.cookie('LE' + md5('_LOGIN_EXPIRE'), (new Date()).getTime() / 1000 + 1800);
// 170406 账户密码方式登录可以选择是否开启验证码,默认开关是关闭状态,此时开启验证码,开关开启,无需验证
let captchaShow = _.get(req.app.locals.wap, 'close.loginValidation', false);
res.render('login', {
width750: true,
loginIndex: true, // 模板中使用JS的标识
captchaShow: true, // 170306 因为暴力破解密码问题,要求每次都展示验证码
captchaShow: !captchaShow, // 170306 因为暴力破解密码问题,要求每次都展示验证码
backUrl: 'javascript:history.go(-1)', // eslint-disable-line
showHeaderImg: true, // 控制显示头部图片
isPassportPage: true, // 模板中模块标识
... ...
... ... @@ -20,6 +20,11 @@ const check = (req, res, next) => {
return next();
}
// 170406 采用账号密码方式登录验证码可以配置关闭,默认开关是关闭状态,这时需要验证,开关开启,无需验证
if (_.get(req.app.locals.wap, 'close.loginValidation', false) && req.path === '/passport/login/auth') {
return next();
}
// 使用极验证
let useGeetest = !_.get(req.app.locals.wap, 'geetest.validation', false);
... ...
... ... @@ -9,7 +9,7 @@
<input id="pwd" class="pwd input" type="password" placeholder="密码">
</div>
{{!--图片验证--}}
<div data-geetest="{{useGeetest}}" id="js-img-check"></div>
<div data-userverify="{{captchaShow}}" data-geetest="{{useGeetest}}" id="js-img-check"></div>
<span id="btn-login" class="btn btn-login disable">登录</span>
<p class="op-container">
<a class="op-item internat" href={{internationalUrl}}>海外手机</a>
... ...
... ... @@ -14,6 +14,7 @@ let $account = $('#account'),
$ways = $('#retrive-pwd-ways'),
$captcha = $('#js-img-check'),
useVerify = $captcha.data('userverify'), // 170406 是否使用验证
accPass = false,
pwdPass = false;
... ... @@ -25,14 +26,18 @@ let trim = $.trim;
let showErrTip = tip.show;
let validate = new Validate($captcha, {
useREM: {
rootFontSize: 40,
picWidth: 150
}
});
let validate = {};
if (useVerify) {
validate = new Validate($captcha, {
useREM: {
rootFontSize: 40,
picWidth: 150
}
});
validate.init();
validate.init();
}
// 登录按钮状态切换
function switchLoginBtnStatus() {
... ... @@ -60,6 +65,62 @@ function hideRetrivePanel() {
$ways.hide();
}
/**
* 登录校验
*/
function loginAuth(params, acc) {
$.ajax({
type: 'POST',
url: '/passport/login/auth',
data: params,
success: function(data) {
let res,
LOGI_TYPE;
if (acc.indexOf('@') > 0) {
LOGI_TYPE = 8;
} else {
LOGI_TYPE = 5;
}
if (window._yas && window._yas.sendCustomInfo) {
window._yas.sendCustomInfo({
op: 'YB_MY_LOGIN_C',
param: JSON.stringify({
C_ID: window._ChannelVary[window.cookie('_Channel')],
LOGI_TYPE: LOGI_TYPE
})
}, true);
}
validate && validate.type === 2 && validate.refresh();
if (data.code === 200) {
res = data.data;
showErrTip('登录成功');
location.href = res.href;
$loginBtn.text('登录成功');
} else {
if (useVerify && data.captchaShow) {
((data.changeCaptcha && validate.type !== 2) && validate.refresh());
}
showErrTip(data.message);
resetForm();
}
return data;
},
error: function() {
showErrTip('网络断开连接啦~');
validate && validate.refresh();
},
complete: function() {
$loginBtn.text('登录').removeClass('disable');
}
});
}
// 密码显示与隐藏
api.bindEyesEvt();
... ... @@ -95,67 +156,23 @@ $loginBtn.on('touchstart', function() {
// 验证账号(数字或者邮箱)和密码合理性
if ((/^[0-9]+$/.test(acc) || api.emailRegx.test(acc)) && api.pwdValidate(pwd)) {
validate.getResults().then((result) => {
$loginBtn.text('正在登录...').addClass('disable');
let params = {
account: acc,
password: pwd
};
$.extend(params, result);
$.ajax({
type: 'POST',
url: '/passport/login/auth',
data: params,
success: function(data) {
let res,
LOGI_TYPE;
if (acc.indexOf('@') > 0) {
LOGI_TYPE = 8;
} else {
LOGI_TYPE = 5;
}
if (window._yas && window._yas.sendCustomInfo) {
window._yas.sendCustomInfo({
op: 'YB_MY_LOGIN_C',
param: JSON.stringify({
C_ID: window._ChannelVary[window.cookie('_Channel')],
LOGI_TYPE: LOGI_TYPE
})
}, true);
}
validate.type === 2 && validate.refresh();
if (data.code === 200) {
res = data.data;
showErrTip('登录成功');
location.href = res.href;
$loginBtn.text('登录成功');
} else {
if (data.captchaShow) {
((data.changeCaptcha && validate.type !== 2) && validate.refresh());
}
showErrTip(data.message);
resetForm();
}
return data;
},
error: function() {
showErrTip('网络断开连接啦~');
validate.refresh();
},
complete: function() {
$loginBtn.text('登录').removeClass('disable');
}
});
}, () => {});
let params = {
account: acc,
password: pwd
};
if (useVerify) {
validate.getResults().then((result) => {
$loginBtn.text('正在登录...').addClass('disable');
$.extend(params, result);
// auth
loginAuth(params, acc);
}, () => {});
} else {
loginAuth(params, acc);
}
} else {
showErrTip('账号或密码有错误,请重新输入');
$loginBtn.text('登录').removeClass('disable');
... ...