|
@@ -10,10 +10,12 @@ const passport = require('passport'); |
|
@@ -10,10 +10,12 @@ const passport = require('passport'); |
10
|
|
10
|
|
11
|
// const md5 = require('yoho-md5');
|
11
|
// const md5 = require('yoho-md5');
|
12
|
const uuid = require('uuid');
|
12
|
const uuid = require('uuid');
|
|
|
13
|
+const co = Promise.coroutine;
|
13
|
const cookie = global.yoho.cookie;
|
14
|
const cookie = global.yoho.cookie;
|
14
|
const helpers = global.yoho.helpers;
|
15
|
const helpers = global.yoho.helpers;
|
15
|
const log = global.yoho.logger;
|
16
|
const log = global.yoho.logger;
|
16
|
const config = global.yoho.config;
|
17
|
const config = global.yoho.config;
|
|
|
18
|
+const cache = global.yoho.cache.master;
|
17
|
const utils = require(global.utils);
|
19
|
const utils = require(global.utils);
|
18
|
const RegService = require('../models/reg-service');
|
20
|
const RegService = require('../models/reg-service');
|
19
|
const AuthHelper = require('../models/auth-helper');
|
21
|
const AuthHelper = require('../models/auth-helper');
|
|
@@ -122,21 +124,10 @@ const local = { |
|
@@ -122,21 +124,10 @@ const local = { |
122
|
req.session.captchaValidCount = 5;
|
124
|
req.session.captchaValidCount = 5;
|
123
|
}
|
125
|
}
|
124
|
|
126
|
|
125
|
- // 先清除cookie
|
|
|
126
|
- // res.clearCookie('LE' + md5('_LOGIN_EXPIRE'), {
|
|
|
127
|
- // domain: 'yohobuy.com'
|
|
|
128
|
- // });
|
|
|
129
|
-
|
|
|
130
|
- // 设置登录有效时间30分钟, 防机器刷,cache不稳定,改为cookie
|
|
|
131
|
- // res.cookie('LE' + md5('_LOGIN_EXPIRE'), (new Date()).getTime() / 1000 + 1800);
|
|
|
132
|
-
|
|
|
133
|
- // 170406 账户密码方式登录可以选择是否开启验证码,默认开关是关闭状态,此时开启验证码,开关开启,无需验证
|
|
|
134
|
- let captchaShow = _.get(req.app.locals.wap, 'close.loginValidation', false);
|
|
|
135
|
-
|
|
|
136
|
res.render('login', {
|
127
|
res.render('login', {
|
137
|
width750: true,
|
128
|
width750: true,
|
138
|
loginIndex: true, // 模板中使用JS的标识
|
129
|
loginIndex: true, // 模板中使用JS的标识
|
139
|
- captchaShow: !captchaShow, // 170306 因为暴力破解密码问题,要求每次都展示验证码
|
130
|
+ captchaShow: req.yoho.captchaShow,
|
140
|
backUrl: 'javascript:history.go(-1)', // eslint-disable-line
|
131
|
backUrl: 'javascript:history.go(-1)', // eslint-disable-line
|
141
|
showHeaderImg: true, // 控制显示头部图片
|
132
|
showHeaderImg: true, // 控制显示头部图片
|
142
|
isPassportPage: true, // 模板中模块标识
|
133
|
isPassportPage: true, // 模板中模块标识
|
|
@@ -166,22 +157,11 @@ const local = { |
|
@@ -166,22 +157,11 @@ const local = { |
166
|
req.session.captchaValidCount = 5;
|
157
|
req.session.captchaValidCount = 5;
|
167
|
}
|
158
|
}
|
168
|
|
159
|
|
169
|
- // 先清除cookie
|
|
|
170
|
- // res.clearCookie('LE' + md5('_LOGIN_EXPIRE'), {
|
|
|
171
|
- // domain: 'yohobuy.com'
|
|
|
172
|
- // });
|
|
|
173
|
-
|
|
|
174
|
- // 设置登录有效时间30分钟, 防机器刷,cache不稳定,改为cookie
|
|
|
175
|
- // res.cookie('LE' + md5('_LOGIN_EXPIRE'), (new Date()).getTime() / 1000 + 1800);
|
|
|
176
|
-
|
|
|
177
|
- // 170406 账户密码方式登录可以选择是否开启验证码,默认开关是关闭状态,此时开启验证码,开关开启,无需验证
|
|
|
178
|
- let captchaShow = _.get(req.app.locals.wap, 'close.loginValidation', false);
|
|
|
179
|
-
|
|
|
180
|
res.render('international', {
|
160
|
res.render('international', {
|
181
|
width750: true,
|
161
|
width750: true,
|
182
|
backUrl: 'javascript:history.go(-1)', // eslint-disable-line
|
162
|
backUrl: 'javascript:history.go(-1)', // eslint-disable-line
|
183
|
loginInternational: true, // 模板中使用JS的标识
|
163
|
loginInternational: true, // 模板中使用JS的标识
|
184
|
- captchaShow: !captchaShow, // 170306 因为暴力破解密码问题,要求每次都展示验证码
|
164
|
+ captchaShow: req.yoho.captchaShow,
|
185
|
isPassportPage: true, // 模板中模块标识
|
165
|
isPassportPage: true, // 模板中模块标识
|
186
|
headerText: '登录',
|
166
|
headerText: '登录',
|
187
|
areaCode: '+86', // 默认区号
|
167
|
areaCode: '+86', // 默认区号
|
|
@@ -411,7 +391,27 @@ exports.user = function(req, res, next) { |
|
@@ -411,7 +391,27 @@ exports.user = function(req, res, next) { |
411
|
* 根据用户登录是否成功决定是否展示验证码
|
391
|
* 根据用户登录是否成功决定是否展示验证码
|
412
|
*/
|
392
|
*/
|
413
|
exports.loginShowCaptchaByIp = function(req, res, next) {
|
393
|
exports.loginShowCaptchaByIp = function(req, res, next) {
|
414
|
- return next();
|
394
|
+ // 总开关状态
|
|
|
395
|
+ req.yoho.captchaShow = !_.get(req.app.locals.wap, 'close.loginValidation', false);
|
|
|
396
|
+
|
|
|
397
|
+ // 开关打开,不走任何验证逻辑
|
|
|
398
|
+ if (!req.yoho.captchaShow) {
|
|
|
399
|
+ return next();
|
|
|
400
|
+ }
|
|
|
401
|
+
|
|
|
402
|
+ co(function*() {
|
|
|
403
|
+ let hasErrorLog = yield cache.getAsync(`loginErrorIp:${req.yoho.clientIp}`);
|
|
|
404
|
+
|
|
|
405
|
+ log.info(`clientip ${req.yoho.clientIp} status is ` + cache.get(`loginErrorIp:${req.yoho.clientIp}`));
|
|
|
406
|
+
|
|
|
407
|
+ if (hasErrorLog) {
|
|
|
408
|
+ req.yoho.captchaShow = true;
|
|
|
409
|
+ }
|
|
|
410
|
+ next();
|
|
|
411
|
+ })().catch(function(e) {
|
|
|
412
|
+ req.yoho.captchaShow = true;
|
|
|
413
|
+ next();
|
|
|
414
|
+ });
|
415
|
};
|
415
|
};
|
416
|
|
416
|
|
417
|
exports.common = common;
|
417
|
exports.common = common;
|