...
|
...
|
@@ -21,10 +21,17 @@ const config = global.yoho.config; |
|
|
const helpers = global.yoho.helpers;
|
|
|
const cookie = global.yoho.cookie;
|
|
|
const logger = global.yoho.logger;
|
|
|
const cache = global.yoho.cache;
|
|
|
|
|
|
let siteUrl = config.siteUrl.indexOf('//') === 0 ? 'http:' + config.siteUrl : config.siteUrl;
|
|
|
|
|
|
|
|
|
function getLoginStat(ip) {
|
|
|
let errorLoginKey = 'loginErrorIp:' + ip;
|
|
|
|
|
|
return cache.get(errorLoginKey);
|
|
|
}
|
|
|
|
|
|
// 本地登录
|
|
|
passport.use('local', new LocalStrategy({
|
|
|
usernameField: 'account',
|
...
|
...
|
@@ -33,6 +40,19 @@ passport.use('local', new LocalStrategy({ |
|
|
}, (req, username, password, done) => {
|
|
|
let area = req.body.areaCode || '86';
|
|
|
let type = req.body.loginType;
|
|
|
let clientIp = req.yoho.clientIp;
|
|
|
let errorLoginKey = 'loginErrorIp:' + clientIp;
|
|
|
|
|
|
return getLoginStat(clientIp).then((times) => {
|
|
|
let errLoginTimes = _.parseInt(times) || 0;
|
|
|
let verifyCode = req.body.captcha;
|
|
|
|
|
|
if (errLoginTimes > 0 && type !== 'SMSLogin') {
|
|
|
if (!verifyCode || verifyCode !== req.session.captcha) {
|
|
|
return done({message: '验证码不正确或验证码过期', needCaptcha: true}, null);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
if (isNaN(_.parseInt(area)) || _.isEmpty(username) || _.isEmpty(password)) {
|
|
|
logger.info(`【Passport Login】bad params, area:${area} account:${username} password:${password}`);
|
...
|
...
|
@@ -53,9 +73,8 @@ passport.use('local', new LocalStrategy({ |
|
|
return done({message: '页面停留时间过长,请刷新页面'}, null);
|
|
|
}
|
|
|
|
|
|
let verifyCode = req.body.captcha;
|
|
|
|
|
|
if (verifyCode && verifyCode !== req.session.captcha) {
|
|
|
if (type !== 'SMSLogin' && verifyCode && verifyCode !== req.session.captcha) {
|
|
|
return done({message: '验证码不正确或验证码过期', needCaptcha: true}, null);
|
|
|
}
|
|
|
|
...
|
...
|
@@ -63,8 +82,10 @@ passport.use('local', new LocalStrategy({ |
|
|
|
|
|
return LoginService.signin(type, area, username, password, shoppingKey, req).then((result) => {
|
|
|
if (result.code && result.code === 200 && result.data.uid) {
|
|
|
cache.del(errorLoginKey).catch(() => {});
|
|
|
done(null, result.data);
|
|
|
} else {
|
|
|
cache.set(errorLoginKey, errLoginTimes + 1, 3600).catch(() => {});
|
|
|
done({
|
|
|
message: '请输入正确的账号或密码',
|
|
|
needCaptcha: true
|
...
|
...
|
@@ -74,6 +95,12 @@ passport.use('local', new LocalStrategy({ |
|
|
logger.error('call the signin service fail,', e);
|
|
|
done('登录失败,请稍后重试', null);
|
|
|
});
|
|
|
}).catch(e => {
|
|
|
logger.error('call the signin service fail,', e);
|
|
|
return done('登录失败,请稍后重试', null);
|
|
|
});
|
|
|
|
|
|
|
|
|
}));
|
|
|
|
|
|
/**
|
...
|
...
|
|