Merge branch 'feature/passport' of git.yoho.cn:fe/yohobuy-node into feature/passport
Showing
4 changed files
with
59 additions
and
17 deletions
@@ -73,9 +73,9 @@ passport.use(new LocalStrategy({ | @@ -73,9 +73,9 @@ passport.use(new LocalStrategy({ | ||
73 | console.log(errLoginTimes); | 73 | console.log(errLoginTimes); |
74 | 74 | ||
75 | if (accountTimes >= 10) { | 75 | if (accountTimes >= 10) { |
76 | - done('您的账号已被暂时锁定,请稍后再试', null); | 76 | + done({ message: '您的账号已被暂时锁定,请稍后再试' }, null); |
77 | } else if (ipTimes >= 100) { | 77 | } else if (ipTimes >= 100) { |
78 | - done('您尝试的次数过多,账号已被暂时锁定,请稍后再试', null); | 78 | + done({ message: '您尝试的次数过多,账号已被暂时锁定,请稍后再试' }, null); |
79 | } else { | 79 | } else { |
80 | return AuthHelper.signin(area, username, password, shoppingKey).then((result) => { | 80 | return AuthHelper.signin(area, username, password, shoppingKey).then((result) => { |
81 | console.log(result); | 81 | console.log(result); |
@@ -93,17 +93,21 @@ passport.use(new LocalStrategy({ | @@ -93,17 +93,21 @@ passport.use(new LocalStrategy({ | ||
93 | 93 | ||
94 | // 再次校验 | 94 | // 再次校验 |
95 | if (ipTimes >= 100) { | 95 | if (ipTimes >= 100) { |
96 | - done('您尝试的次数过多,账号已被暂时锁定,请稍后再试', null); | 96 | + done({ message: '您尝试的次数过多,账号已被暂时锁定,请稍后再试' }, null); |
97 | } else if (accountTimes >= 10) { | 97 | } else if (accountTimes >= 10) { |
98 | - done('您的账号已被暂时锁定,请稍后再试', null); | 98 | + done({ message: '您的账号已被暂时锁定,请稍后再试' }, null); |
99 | } else if (errLoginTimes >= 3) { | 99 | } else if (errLoginTimes >= 3) { |
100 | - done(`您输入的密码及账户名不匹配, | 100 | + done({ |
101 | + message: `您输入的密码及账户名不匹配, | ||
101 | 是否<a href="${helpers.urlFormat('/passport/back/index')}" target="_blank">忘记密码?</a>`, | 102 | 是否<a href="${helpers.urlFormat('/passport/back/index')}" target="_blank">忘记密码?</a>`, |
102 | - { needCaptcha: true }); | 103 | + needCaptcha: true |
104 | + }); | ||
103 | } else { | 105 | } else { |
104 | - done(`您输入的密码及账户名不匹配, | 106 | + done({ |
107 | + message: `您输入的密码及账户名不匹配, | ||
105 | 是否<a href="${helpers.urlFormat('/passport/back/index')}" target="_blank">忘记密码?</a>`, | 108 | 是否<a href="${helpers.urlFormat('/passport/back/index')}" target="_blank">忘记密码?</a>`, |
106 | - { needCaptcha: false }); | 109 | + needCaptcha: false |
110 | + }); | ||
107 | } | 111 | } |
108 | } | 112 | } |
109 | }); | 113 | }); |
apps/passport/controllers/bind.js
0 → 100644
@@ -83,6 +83,25 @@ const common = { | @@ -83,6 +83,25 @@ const common = { | ||
83 | domain: 'yohobuy.com' | 83 | domain: 'yohobuy.com' |
84 | }); | 84 | }); |
85 | next(); | 85 | next(); |
86 | + }, | ||
87 | + needCaptcha: (req, res, next) => { | ||
88 | + let account = req.query.account; | ||
89 | + let result = {code: 400, message: '', data: ''}; | ||
90 | + | ||
91 | + if (account) { | ||
92 | + let errorLoginKey = 'account_errorlogin_' + account; | ||
93 | + | ||
94 | + cache.get(errorLoginKey).then(errloginTimes => { | ||
95 | + errloginTimes = parseInt(errloginTimes, 0); | ||
96 | + console.log(errloginTimes); | ||
97 | + if (!isNaN(errloginTimes) && errloginTimes >= 3) { | ||
98 | + result.data = {needCaptcha: true}; | ||
99 | + } | ||
100 | + res.json(result); | ||
101 | + }).catch(next); | ||
102 | + } else { | ||
103 | + res.json(result); | ||
104 | + } | ||
86 | } | 105 | } |
87 | }; | 106 | }; |
88 | 107 | ||
@@ -133,8 +152,10 @@ const local = { | @@ -133,8 +152,10 @@ const local = { | ||
133 | if (err) { | 152 | if (err) { |
134 | res.json({ | 153 | res.json({ |
135 | code: 400, | 154 | code: 400, |
136 | - message: err, | ||
137 | - data: user || {} | 155 | + message: err.message, |
156 | + data: { | ||
157 | + needCaptcha: err.needCaptcha | ||
158 | + } | ||
138 | }); | 159 | }); |
139 | } else { | 160 | } else { |
140 | let isRemember = req.body.isRemember; | 161 | let isRemember = req.body.isRemember; |
@@ -299,10 +320,11 @@ const alipay = { | @@ -299,10 +320,11 @@ const alipay = { | ||
299 | } | 320 | } |
300 | }; | 321 | }; |
301 | 322 | ||
302 | - | ||
303 | -exports.common = common; | ||
304 | -exports.wechat = wechat; | ||
305 | -exports.local = local; | ||
306 | -exports.sina = sina; | ||
307 | -exports.qq = qq; | ||
308 | -exports.alipay = alipay; | 323 | +module.exports = { |
324 | + common: common, | ||
325 | + wechat: wechat, | ||
326 | + local: local, | ||
327 | + sina: sina, | ||
328 | + qq: qq, | ||
329 | + alipay: alipay | ||
330 | +}; |
@@ -37,6 +37,9 @@ router.get('/login/qq/callback', login.qq.callback); | @@ -37,6 +37,9 @@ router.get('/login/qq/callback', login.qq.callback); | ||
37 | router.get('/autosign/alipay', login.common.beforeLogin, login.alipay.login); | 37 | router.get('/autosign/alipay', login.common.beforeLogin, login.alipay.login); |
38 | router.get('/login/alipay/callback', login.alipay.callback); | 38 | router.get('/login/alipay/callback', login.alipay.callback); |
39 | 39 | ||
40 | + | ||
41 | +router.get('/login/account', login.common.needCaptcha); | ||
42 | + | ||
40 | /** | 43 | /** |
41 | * 注册页面路由 | 44 | * 注册页面路由 |
42 | */ | 45 | */ |
-
Please register or login to post a comment