Authored by 毕凯

Merge branch 'feature/passport' of git.yoho.cn:fe/yohobuy-node into feature/passport

... ... @@ -73,9 +73,9 @@ passport.use(new LocalStrategy({
console.log(errLoginTimes);
if (accountTimes >= 10) {
done('您的账号已被暂时锁定,请稍后再试', null);
done({ message: '您的账号已被暂时锁定,请稍后再试' }, null);
} else if (ipTimes >= 100) {
done('您尝试的次数过多,账号已被暂时锁定,请稍后再试', null);
done({ message: '您尝试的次数过多,账号已被暂时锁定,请稍后再试' }, null);
} else {
return AuthHelper.signin(area, username, password, shoppingKey).then((result) => {
console.log(result);
... ... @@ -93,17 +93,21 @@ passport.use(new LocalStrategy({
// 再次校验
if (ipTimes >= 100) {
done('您尝试的次数过多,账号已被暂时锁定,请稍后再试', null);
done({ message: '您尝试的次数过多,账号已被暂时锁定,请稍后再试' }, null);
} else if (accountTimes >= 10) {
done('您的账号已被暂时锁定,请稍后再试', null);
done({ message: '您的账号已被暂时锁定,请稍后再试' }, null);
} else if (errLoginTimes >= 3) {
done(`您输入的密码及账户名不匹配,
done({
message: `您输入的密码及账户名不匹配,
是否<a href="${helpers.urlFormat('/passport/back/index')}" target="_blank">忘记密码?</a>`,
{ needCaptcha: true });
needCaptcha: true
});
} else {
done(`您输入的密码及账户名不匹配,
done({
message: `您输入的密码及账户名不匹配,
是否<a href="${helpers.urlFormat('/passport/back/index')}" target="_blank">忘记密码?</a>`,
{ needCaptcha: false });
needCaptcha: false
});
}
}
});
... ...
/**
* 第三方登录后绑定
*
* @author: jiangfeng<jeff.jiang@yoho.cn>
*/
'use strict';
const bind = {
};
module.exports = bind;
... ...
... ... @@ -83,6 +83,25 @@ const common = {
domain: 'yohobuy.com'
});
next();
},
needCaptcha: (req, res, next) => {
let account = req.query.account;
let result = {code: 400, message: '', data: ''};
if (account) {
let errorLoginKey = 'account_errorlogin_' + account;
cache.get(errorLoginKey).then(errloginTimes => {
errloginTimes = parseInt(errloginTimes, 0);
console.log(errloginTimes);
if (!isNaN(errloginTimes) && errloginTimes >= 3) {
result.data = {needCaptcha: true};
}
res.json(result);
}).catch(next);
} else {
res.json(result);
}
}
};
... ... @@ -133,8 +152,10 @@ const local = {
if (err) {
res.json({
code: 400,
message: err,
data: user || {}
message: err.message,
data: {
needCaptcha: err.needCaptcha
}
});
} else {
let isRemember = req.body.isRemember;
... ... @@ -299,10 +320,11 @@ const alipay = {
}
};
exports.common = common;
exports.wechat = wechat;
exports.local = local;
exports.sina = sina;
exports.qq = qq;
exports.alipay = alipay;
module.exports = {
common: common,
wechat: wechat,
local: local,
sina: sina,
qq: qq,
alipay: alipay
};
... ...
... ... @@ -37,6 +37,9 @@ router.get('/login/qq/callback', login.qq.callback);
router.get('/autosign/alipay', login.common.beforeLogin, login.alipay.login);
router.get('/login/alipay/callback', login.alipay.callback);
router.get('/login/account', login.common.needCaptcha);
/**
* 注册页面路由
*/
... ...