...
|
...
|
@@ -21,7 +21,6 @@ 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;
|
|
|
|
...
|
...
|
@@ -62,53 +61,19 @@ passport.use('local', new LocalStrategy({ |
|
|
|
|
|
let shoppingKey = cookie.getShoppingKey(req);
|
|
|
|
|
|
let account = req.body.account;
|
|
|
|
|
|
let errorLoginKey = 'account_errorlogin_' + account;
|
|
|
let accountKey = 'account_signin_' + account;
|
|
|
|
|
|
let cacheGet = [cache.get(errorLoginKey), cache.get(accountKey)];
|
|
|
|
|
|
Promise.all(cacheGet).then(times => {
|
|
|
let errLoginTimes = _.parseInt(times[0]) || 0;
|
|
|
let accountTimes = _.parseInt(times[1]) || 0;
|
|
|
|
|
|
if (accountTimes >= 10) {
|
|
|
done({ message: '您的账号已被暂时锁定,请30分钟后再试' }, null);
|
|
|
return LoginService.signin(type, area, username, password, shoppingKey, req).then((result) => {
|
|
|
if (result.code && result.code === 200 && result.data.uid) {
|
|
|
done(null, result.data);
|
|
|
} else {
|
|
|
return LoginService.signin(type, area, username, password, shoppingKey, req).then((result) => {
|
|
|
if (result.code && result.code === 200 && result.data.uid) {
|
|
|
cache.del(errorLoginKey);
|
|
|
|
|
|
done(null, result.data);
|
|
|
} else {
|
|
|
errLoginTimes = errLoginTimes + 1;
|
|
|
accountTimes = accountTimes + 1;
|
|
|
cache.set(errorLoginKey, errLoginTimes);
|
|
|
cache.set(accountKey, accountTimes, 1800);
|
|
|
|
|
|
// 再次校验
|
|
|
if (accountTimes >= 10) {
|
|
|
done({message: '您的账号已被暂时锁定,请稍后再试'}, null);
|
|
|
} else if (errLoginTimes >= 3) {
|
|
|
done({
|
|
|
message: '请输入正确的账号或密码',
|
|
|
needCaptcha: true
|
|
|
});
|
|
|
} else {
|
|
|
done({
|
|
|
message: '请输入正确的账号或密码',
|
|
|
needCaptcha: false
|
|
|
});
|
|
|
}
|
|
|
}
|
|
|
done({
|
|
|
message: '请输入正确的账号或密码',
|
|
|
needCaptcha: true
|
|
|
});
|
|
|
}
|
|
|
}).catch(e => {
|
|
|
logger.error('call the signin service fail,', e);
|
|
|
done('登录失败,请稍后重试', null);
|
|
|
});
|
|
|
|
|
|
}));
|
|
|
|
|
|
/**
|
...
|
...
|
|