...
|
...
|
@@ -26,6 +26,16 @@ const cache = global.yoho.cache; |
|
|
let siteUrl = config.siteUrl.indexOf('//') === 0 ? 'http:' + config.siteUrl : config.siteUrl;
|
|
|
|
|
|
|
|
|
function getLoginStat(account) {
|
|
|
let errorLoginKey = 'account_errorlogin_' + account;
|
|
|
let accountKey = 'account_signin_' + account;
|
|
|
let cacheGet = [cache.get(errorLoginKey), cache.get(accountKey)];
|
|
|
|
|
|
return Promise.all(cacheGet).catch(() => {
|
|
|
return [0, 0];
|
|
|
});
|
|
|
}
|
|
|
|
|
|
// 本地登录
|
|
|
passport.use('local', new LocalStrategy({
|
|
|
usernameField: 'account',
|
...
|
...
|
@@ -54,9 +64,7 @@ passport.use('local', new LocalStrategy({ |
|
|
let errorLoginKey = 'account_errorlogin_' + account;
|
|
|
let accountKey = 'account_signin_' + account;
|
|
|
|
|
|
let cacheGet = [cache.get(errorLoginKey), cache.get(accountKey)];
|
|
|
|
|
|
Promise.all(cacheGet).then(times => {
|
|
|
getLoginStat(account).then(times => {
|
|
|
let errLoginTimes = _.parseInt(times[0]) || 0;
|
|
|
let accountTimes = _.parseInt(times[1]) || 0;
|
|
|
|
...
|
...
|
@@ -65,14 +73,14 @@ passport.use('local', new LocalStrategy({ |
|
|
} else {
|
|
|
return LoginApi.signin(type, area, username, password, shoppingKey).then((result) => {
|
|
|
if (result.code && result.code === 200 && result.data.uid) {
|
|
|
cache.del(errorLoginKey);
|
|
|
cache.del(errorLoginKey).catch(() => {});
|
|
|
|
|
|
done(null, result.data);
|
|
|
} else {
|
|
|
errLoginTimes = errLoginTimes + 1;
|
|
|
accountTimes = accountTimes + 1;
|
|
|
cache.set(errorLoginKey, errLoginTimes);
|
|
|
cache.set(accountKey, accountTimes, 1800);
|
|
|
cache.set(errorLoginKey, errLoginTimes).catch(() => {});
|
|
|
cache.set(accountKey, accountTimes, 1800).catch(() => {});
|
|
|
|
|
|
// 再次校验
|
|
|
if (accountTimes >= 10) {
|
...
|
...
|
|