Merge branch 'gray' into 'master'
Gray See merge request !425
Showing
32 changed files
with
269 additions
and
418 deletions
@@ -10,7 +10,6 @@ exports.index = (req, res) => { | @@ -10,7 +10,6 @@ exports.index = (req, res) => { | ||
10 | }; | 10 | }; |
11 | 11 | ||
12 | exports.submit = (req, res) => { | 12 | exports.submit = (req, res) => { |
13 | - let captchaCode = _.get(req.session, 'captcha'); | ||
14 | let remoteIp = req.get('X-Forwarded-For') || req.ip; | 13 | let remoteIp = req.get('X-Forwarded-For') || req.ip; |
15 | 14 | ||
16 | if (remoteIp.indexOf(',') > 0) { | 15 | if (remoteIp.indexOf(',') > 0) { |
@@ -19,8 +18,8 @@ exports.submit = (req, res) => { | @@ -19,8 +18,8 @@ exports.submit = (req, res) => { | ||
19 | remoteIp = arr[0]; | 18 | remoteIp = arr[0]; |
20 | } | 19 | } |
21 | 20 | ||
22 | - if (req.body.captcha === captchaCode) { | ||
23 | let key = `pc:limiter:${remoteIp}`; | 21 | let key = `pc:limiter:${remoteIp}`; |
22 | + | ||
24 | cache.delAsync(key).then(() => { | 23 | cache.delAsync(key).then(() => { |
25 | return res.json({ | 24 | return res.json({ |
26 | code: 200 | 25 | code: 200 |
@@ -30,10 +29,5 @@ exports.submit = (req, res) => { | @@ -30,10 +29,5 @@ exports.submit = (req, res) => { | ||
30 | code: 400 | 29 | code: 400 |
31 | }); | 30 | }); |
32 | }); | 31 | }); |
33 | - } else { | ||
34 | - return res.json({ | ||
35 | - code: 400 | ||
36 | - }); | ||
37 | - } | ||
38 | 32 | ||
39 | }; | 33 | }; |
@@ -10,11 +10,12 @@ const router = require('express').Router(); // eslint-disable-line | @@ -10,11 +10,12 @@ const router = require('express').Router(); // eslint-disable-line | ||
10 | const cRoot = './controllers'; | 10 | const cRoot = './controllers'; |
11 | const ads = require(`${cRoot}/ads`); | 11 | const ads = require(`${cRoot}/ads`); |
12 | const check = require(`${cRoot}/check`); | 12 | const check = require(`${cRoot}/check`); |
13 | +const validateCode = require('../passport/controllers/validateCode'); | ||
13 | 14 | ||
14 | // routers | 15 | // routers |
15 | 16 | ||
16 | router.get('/ads', ads.index); | 17 | router.get('/ads', ads.index); |
17 | -router.get('/check', check.index); | ||
18 | -router.post('/check/submit', check.submit); | 18 | +router.get('/check', validateCode.load, check.index); |
19 | +router.post('/check/submit', validateCode.check, check.submit); | ||
19 | 20 | ||
20 | module.exports = router; | 21 | module.exports = router; |
1 | <div class="check-page"> | 1 | <div class="check-page"> |
2 | - <div class="title">请输入正确的验证码,继续访问</div> | ||
3 | - <div id="js-img-check"></div> | 2 | + <div class="title">请确认之后,继续访问</div> |
3 | + {{!--图片验证--}} | ||
4 | + <div data-geetest="{{useGeetest}}" id="js-img-check"></div> | ||
4 | <div class="submit"> | 5 | <div class="submit"> |
5 | 确认 | 6 | 确认 |
6 | </div> | 7 | </div> |
@@ -502,7 +502,7 @@ | @@ -502,7 +502,7 @@ | ||
502 | </ul> | 502 | </ul> |
503 | </p> | 503 | </p> |
504 | <p> | 504 | <p> |
505 | - 第二十二条 借款利率一般情形下按以下标准计收,不排除因特殊情况实际的利率与下列利率存在差异,具体利息标准以借款订单所示信息为准。 | 505 | + 第二十二条 日息一般情形下为0.06%,不排除因特殊情况实际的日息与上述日息存在差异,具体利息标准以借款订单所示信息为准。如借款发生逾期,则您需要根据如下标准按日向信而富支付延迟还款服务费:如借款金额为500元以内(含500元),则延迟还款服务费为1元/天;如借款金额为501—1000元(含1000元),则延迟还款服务费为2元/天;如借款金额为1001—1500元(含1500元),则延迟还款服务费为3元/天; 如借款金额为1501-2000元(含2000元),则延迟还款服务费为4元/天,以此类推,以500元为一个梯度,借款金额每增加一个梯度,延迟还款服务费每天增加1元。逾期3天免收逾期费用,逾期超过3天,按实际逾期总天数收取逾期费用。同时,一旦逾期费用和利息之和超过借款金额的50%,则之后的延迟还款服务费将不再计收。利息和延迟还款服务费的具体数值以信而富平台借款订单详情为准,有特别说明的除外。 |
506 | <table> | 506 | <table> |
507 | <tr> | 507 | <tr> |
508 | <td>分期</td> | 508 | <td>分期</td> |
@@ -101,7 +101,7 @@ | @@ -101,7 +101,7 @@ | ||
101 | 9、如果我没有按时还款会有什么影响? | 101 | 9、如果我没有按时还款会有什么影响? |
102 | </p> | 102 | </p> |
103 | <p> | 103 | <p> |
104 | - 如您在还款日24:00之前未能支付全部到期应付款而导致您信用违约时,您需支付逾期所产生的服务费和利息。服务费根据您当期应还本金,如当期应还本金在1-500元内,收取1元/天,501-1000元内,收取2元/天,借款本金每增加500元,逾期服务费增加1元;利息为您应付但未付金额×日利率(0.025%)×逾期天数。还款日后有3天的宽限日,宽限日内免收逾期服务费,宽限日结束后如您尚未还款将补收前三天的逾期服务费。请您在还款日前还款,避免对您的个人信用造成损失。 | 104 | + 如您在还款日24:00之前未能支付全部到期应付款而导致您信用违约时,您需支付逾期所产生的服务费和利息。服务费根据您当期应还本金,如当期应还本金在1-500元内,收取1元/天,501-1000元内,收取2元/天,借款本金每增加500元,逾期服务费增加1元;利息为您应付但未付金额×日利率(一般情形下为0.06%)×逾期天数。还款日后有3天的宽限日,宽限日内免收逾期服务费,宽限日结束后如您尚未还款将补收前三天的逾期服务费。同时,一旦逾期费用和利息之和超过借款本金的50%,则之后的逾期费用将不再计收。请您在还款日前还款,避免对您的个人信用造成损失。 |
105 | </p> | 105 | </p> |
106 | <p> | 106 | <p> |
107 | 10、逾期还款会影响个人信用吗? | 107 | 10、逾期还款会影响个人信用吗? |
@@ -195,50 +195,8 @@ const generateCodeImg = (req, res) => { | @@ -195,50 +195,8 @@ const generateCodeImg = (req, res) => { | ||
195 | * 发送手机验证码 | 195 | * 发送手机验证码 |
196 | */ | 196 | */ |
197 | const sendCodeToMobileAPI = (req, res, next) => { | 197 | const sendCodeToMobileAPI = (req, res, next) => { |
198 | - let verifyCode = req.body.verifyCode || ''; | ||
199 | let phoneNum = req.body.phoneNum || ''; | 198 | let phoneNum = req.body.phoneNum || ''; |
200 | let areaCode = req.body.areaCode || '86'; | 199 | let areaCode = req.body.areaCode || '86'; |
201 | - let testCode = req.body.yohobuy; | ||
202 | - | ||
203 | - let errorCount = _.get(req.session, 'captchaValidCount', 4); // 初始1次 + 后续4次, 同一个验证码 共5次 | ||
204 | - | ||
205 | - if (!errorCount) { | ||
206 | - _.set(req.session, 'captchaValidCount', 4); | ||
207 | - } else { | ||
208 | - --req.session.captchaValidCount; | ||
209 | - } | ||
210 | - | ||
211 | - if (verifyCode) { | ||
212 | - let captcha = _.get(req, 'session.captcha'); | ||
213 | - | ||
214 | - logger.info(`captcha validate result:${verifyCode.toString() === captcha},user:${verifyCode};server:${captcha}`); | ||
215 | - if ((captcha && verifyCode.toString() === captcha) || (testCode === config.testCode)) { | ||
216 | - _.set(req.session, 'backupCaptch.verifyResult', true); | ||
217 | - } else { | ||
218 | - let jsonData = { | ||
219 | - code: 400, | ||
220 | - message: '请将图片旋转到正确位置' | ||
221 | - }; | ||
222 | - | ||
223 | - if (req.session.captchaValidCount === 0) { | ||
224 | - req.session.captcha = null; // 验证码 用过就扔 | ||
225 | - jsonData.changeCaptcha = true; | ||
226 | - } | ||
227 | - | ||
228 | - return res.json(jsonData); | ||
229 | - } | ||
230 | - | ||
231 | - _.set(req.session, 'captcha', null); | ||
232 | - | ||
233 | - } else if (!req.session.backupCaptch.verifyResult) { | ||
234 | - | ||
235 | - return res.json({ | ||
236 | - code: 409, | ||
237 | - message: '非法请求!', | ||
238 | - refer: helpers.urlFormat('/') | ||
239 | - }); | ||
240 | - } | ||
241 | - | ||
242 | 200 | ||
243 | let ERR = { | 201 | let ERR = { |
244 | code: 400, | 202 | code: 400, |
@@ -266,7 +224,7 @@ const sendCodeToMobileAPI = (req, res, next) => { | @@ -266,7 +224,7 @@ const sendCodeToMobileAPI = (req, res, next) => { | ||
266 | } | 224 | } |
267 | } | 225 | } |
268 | 226 | ||
269 | - | 227 | + _.set(req.session, 'backupCaptch.verifyResult', true); |
270 | service.sendCodeToMobileAsync(phoneNum, areaCode) | 228 | service.sendCodeToMobileAsync(phoneNum, areaCode) |
271 | .then(result => { | 229 | .then(result => { |
272 | if (_.isEmpty(result) || result.code !== 200) { | 230 | if (_.isEmpty(result) || result.code !== 200) { |
@@ -57,7 +57,8 @@ const bind = { | @@ -57,7 +57,8 @@ const bind = { | ||
57 | serviceUrl: serviceUrl, // 在线客服 | 57 | serviceUrl: serviceUrl, // 在线客服 |
58 | module: 'passport', | 58 | module: 'passport', |
59 | page: 'bind', | 59 | page: 'bind', |
60 | - title: '绑定手机号' | 60 | + title: '绑定手机号', |
61 | + width750: true | ||
61 | }); | 62 | }); |
62 | }, | 63 | }, |
63 | 64 | ||
@@ -90,15 +91,8 @@ const bind = { | @@ -90,15 +91,8 @@ const bind = { | ||
90 | let openId = req.body.openId; | 91 | let openId = req.body.openId; |
91 | let areaCode = req.body.areaCode || '86'; | 92 | let areaCode = req.body.areaCode || '86'; |
92 | let sourceType = req.body.sourceType; | 93 | let sourceType = req.body.sourceType; |
93 | - let verify = req.body.verify || ''; | ||
94 | - let testCode = req.body.yohobuy; | ||
95 | 94 | ||
96 | if (_.isNumber(parseInt(phoneNum, 0)) && openId && areaCode && sourceType) { | 95 | if (_.isNumber(parseInt(phoneNum, 0)) && openId && areaCode && sourceType) { |
97 | - if (verify) { | ||
98 | - let captcha = _.get(req, 'session.captcha'); | ||
99 | - | ||
100 | - logger.info(`captcha validate result:${verify.toString() === captcha},user:${verify};server:${captcha}`); | ||
101 | - if ((captcha && verify.toString() === captcha) || (testCode === config.testCode)) { | ||
102 | BindService.bindCheck(phoneNum, openId, sourceType, areaCode).then(result => { | 96 | BindService.bindCheck(phoneNum, openId, sourceType, areaCode).then(result => { |
103 | let data = { | 97 | let data = { |
104 | code: result.code, | 98 | code: result.code, |
@@ -127,22 +121,6 @@ const bind = { | @@ -127,22 +121,6 @@ const bind = { | ||
127 | res.json(data); | 121 | res.json(data); |
128 | }).catch(next); | 122 | }).catch(next); |
129 | } else { | 123 | } else { |
130 | - let jsonData = { | ||
131 | - code: 400, | ||
132 | - message: '请将图片旋转到正确方向' | ||
133 | - }; | ||
134 | - | ||
135 | - if (req.session.captchaValidCount === 0) { | ||
136 | - req.session.captcha = null; // 验证码 用过就扔 | ||
137 | - jsonData.changeCaptcha = true; | ||
138 | - } | ||
139 | - | ||
140 | - return res.json(jsonData); | ||
141 | - } | ||
142 | - | ||
143 | - _.set(req.session, 'captcha', null); | ||
144 | - } | ||
145 | - } else { | ||
146 | res.json({ | 124 | res.json({ |
147 | code: 400, | 125 | code: 400, |
148 | message: '', | 126 | message: '', |
1 | 'use strict'; | 1 | 'use strict'; |
2 | 2 | ||
3 | +const _ = require('lodash'); | ||
4 | +const logger = global.yoho.logger; | ||
3 | let imgCheckAPI = require('../models/imgcheck'); | 5 | let imgCheckAPI = require('../models/imgcheck'); |
4 | const request = require('request'); | 6 | const request = require('request'); |
5 | const uuid = require('uuid'); | 7 | const uuid = require('uuid'); |
@@ -43,3 +45,37 @@ exports.imgCheck = (req, res, next) => { | @@ -43,3 +45,37 @@ exports.imgCheck = (req, res, next) => { | ||
43 | next(); | 45 | next(); |
44 | }).catch(next); | 46 | }).catch(next); |
45 | }; | 47 | }; |
48 | + | ||
49 | +/** | ||
50 | + * 验证img-check验证码 | ||
51 | + */ | ||
52 | +exports.validate = (req, res, next) => { | ||
53 | + let captchaInput = req.body.captcha; | ||
54 | + let captchaCode = _.get(req.session, 'captcha'); | ||
55 | + | ||
56 | + let errorCount = _.get(req.session, 'captchaValidCount'); // 初始1次 + 后续4次, 同一个验证码 共5次 | ||
57 | + | ||
58 | + let jsonData = { | ||
59 | + code: 400, | ||
60 | + message: '请将图片旋转到正确方向', | ||
61 | + captchaShow: true | ||
62 | + }; | ||
63 | + | ||
64 | + logger.info(`captcha validate result:${ | ||
65 | + captchaInput.toString() === captchaCode},user:${captchaInput};server:${captchaCode}`); | ||
66 | + | ||
67 | + _.set(req.session, 'captchaValidCount', errorCount - 1); | ||
68 | + | ||
69 | + if (!errorCount) { | ||
70 | + _.set(req.session, 'captchaValidCount', 5); | ||
71 | + req.session.captcha = null; | ||
72 | + jsonData.changeCaptcha = true; | ||
73 | + } | ||
74 | + | ||
75 | + if (!(captchaInput && captchaCode && captchaInput === captchaCode)) { | ||
76 | + return res.json(jsonData); | ||
77 | + } | ||
78 | + req.session.captcha = null; | ||
79 | + req.session.captchaValidCount = null; | ||
80 | + return next(); | ||
81 | +}; |
1 | 'use strict'; | 1 | 'use strict'; |
2 | -const _ = require('lodash'); | ||
3 | const Geetest = require('geetest'); | 2 | const Geetest = require('geetest'); |
4 | const logger = global.yoho.logger; | 3 | const logger = global.yoho.logger; |
5 | -const config = global.yoho.config; | ||
6 | 4 | ||
7 | const captcha = new Geetest({ | 5 | const captcha = new Geetest({ |
8 | geetest_id: 'bce95d796bc3058615fdf2ec2c0aef29', | 6 | geetest_id: 'bce95d796bc3058615fdf2ec2c0aef29', |
@@ -27,8 +25,7 @@ const geetest = { | @@ -27,8 +25,7 @@ const geetest = { | ||
27 | validate(req, res, next) { | 25 | validate(req, res, next) { |
28 | let challenge = req.body.geetest_challenge, | 26 | let challenge = req.body.geetest_challenge, |
29 | validate = req.body.geetest_validate, | 27 | validate = req.body.geetest_validate, |
30 | - seccode = req.body.geetest_seccode, | ||
31 | - testCode = req.body.yohobuy; | 28 | + seccode = req.body.geetest_seccode; |
32 | 29 | ||
33 | let errRes = { | 30 | let errRes = { |
34 | code: 400, | 31 | code: 400, |
@@ -37,21 +34,11 @@ const geetest = { | @@ -37,21 +34,11 @@ const geetest = { | ||
37 | changeCaptcha: true | 34 | changeCaptcha: true |
38 | }; | 35 | }; |
39 | 36 | ||
40 | - if (testCode === config.testCode) { | ||
41 | - return next(); | ||
42 | - } | ||
43 | - | ||
44 | - // 使用极验证 | ||
45 | - let useGeetest = !_.get(req.app.locals.wap, 'geetest.validation', false); | ||
46 | - | ||
47 | - if (!useGeetest) { | ||
48 | - return next(); | ||
49 | - } | ||
50 | if (!challenge || !validate || !seccode) { | 37 | if (!challenge || !validate || !seccode) { |
51 | - return res.send(errRes); | 38 | + return res.json(errRes); |
52 | } | 39 | } |
53 | 40 | ||
54 | - captcha.validate({ | 41 | + return captcha.validate({ |
55 | challenge, | 42 | challenge, |
56 | validate, | 43 | validate, |
57 | seccode | 44 | seccode |
@@ -61,7 +48,7 @@ const geetest = { | @@ -61,7 +48,7 @@ const geetest = { | ||
61 | return next(); | 48 | return next(); |
62 | } | 49 | } |
63 | logger.info('geetest faild'); | 50 | logger.info('geetest faild'); |
64 | - return res.send(errRes); | 51 | + return res.json(errRes); |
65 | }); | 52 | }); |
66 | } | 53 | } |
67 | }; | 54 | }; |
@@ -17,7 +17,6 @@ const config = global.yoho.config; | @@ -17,7 +17,6 @@ const config = global.yoho.config; | ||
17 | const utils = require(global.utils); | 17 | const utils = require(global.utils); |
18 | const RegService = require('../models/reg-service'); | 18 | const RegService = require('../models/reg-service'); |
19 | const AuthHelper = require('../models/auth-helper'); | 19 | const AuthHelper = require('../models/auth-helper'); |
20 | -const logger = global.yoho.logger; | ||
21 | 20 | ||
22 | const loginPage = `${config.siteUrl}/signin.html`; | 21 | const loginPage = `${config.siteUrl}/signin.html`; |
23 | 22 | ||
@@ -118,7 +117,6 @@ const local = { | @@ -118,7 +117,6 @@ const local = { | ||
118 | res.render('login', { | 117 | res.render('login', { |
119 | width750: true, | 118 | width750: true, |
120 | loginIndex: true, // 模板中使用JS的标识 | 119 | loginIndex: true, // 模板中使用JS的标识 |
121 | - useGeetest: !_.get(req.app.locals.wap, 'geetest.validation', false), // 使用极验证 | ||
122 | captchaShow: true, // 170306 因为暴力破解密码问题,要求每次都展示验证码 | 120 | captchaShow: true, // 170306 因为暴力破解密码问题,要求每次都展示验证码 |
123 | backUrl: 'javascript:history.go(-1)', // eslint-disable-line | 121 | backUrl: 'javascript:history.go(-1)', // eslint-disable-line |
124 | showHeaderImg: true, // 控制显示头部图片 | 122 | showHeaderImg: true, // 控制显示头部图片 |
@@ -135,12 +133,7 @@ const local = { | @@ -135,12 +133,7 @@ const local = { | ||
135 | module: 'passport', | 133 | module: 'passport', |
136 | page: 'login', | 134 | page: 'login', |
137 | title: '登录', | 135 | title: '登录', |
138 | - reg: true, | ||
139 | - loadJs: [ | ||
140 | - { | ||
141 | - src: global.yoho.config.geetestJs | ||
142 | - } | ||
143 | - ] | 136 | + reg: true |
144 | }); | 137 | }); |
145 | }, | 138 | }, |
146 | international: (req, res) => { | 139 | international: (req, res) => { |
@@ -181,7 +174,6 @@ const local = { | @@ -181,7 +174,6 @@ const local = { | ||
181 | width750: true, | 174 | width750: true, |
182 | backUrl: 'javascript:history.go(-1)', // eslint-disable-line | 175 | backUrl: 'javascript:history.go(-1)', // eslint-disable-line |
183 | loginInternational: true, // 模板中使用JS的标识 | 176 | loginInternational: true, // 模板中使用JS的标识 |
184 | - useGeetest: !_.get(req.app.locals.wap, 'geetest.validation', false), // 使用极验证 | ||
185 | captchaShow: true, // 170306 因为暴力破解密码问题,要求每次都展示验证码 | 177 | captchaShow: true, // 170306 因为暴力破解密码问题,要求每次都展示验证码 |
186 | isPassportPage: true, // 模板中模块标识 | 178 | isPassportPage: true, // 模板中模块标识 |
187 | headerText: '登录', | 179 | headerText: '登录', |
@@ -189,12 +181,7 @@ const local = { | @@ -189,12 +181,7 @@ const local = { | ||
189 | countrys: RegService.getAreaData(), // 地区信息列表 | 181 | countrys: RegService.getAreaData(), // 地区信息列表 |
190 | module: 'passport', | 182 | module: 'passport', |
191 | page: 'international', | 183 | page: 'international', |
192 | - title: '国际账号登录', | ||
193 | - loadJs: [ | ||
194 | - { | ||
195 | - src: global.yoho.config.geetestJs | ||
196 | - } | ||
197 | - ] | 184 | + title: '国际账号登录' |
198 | }); | 185 | }); |
199 | }, | 186 | }, |
200 | login: (req, res, next) => { | 187 | login: (req, res, next) => { |
@@ -208,47 +195,6 @@ const local = { | @@ -208,47 +195,6 @@ const local = { | ||
208 | }); | 195 | }); |
209 | } | 196 | } |
210 | 197 | ||
211 | - // 使用极验证 | ||
212 | - let useGeetest = !_.get(req.app.locals.wap, 'geetest.validation', false); | ||
213 | - | ||
214 | - // 关闭极验证的时候使用有货自有验证码 | ||
215 | - if (!useGeetest) { | ||
216 | - let captchaInput = req.body.captcha; | ||
217 | - let captchaCode = _.get(req.session, 'captcha'); | ||
218 | - let testCode = req.body.yohobuy; | ||
219 | - | ||
220 | - let errorCount = _.get(req.session, 'captchaValidCount'); // 初始1次 + 后续4次, 同一个验证码 共5次 | ||
221 | - | ||
222 | - let jsonData = { | ||
223 | - code: 400, | ||
224 | - message: '请将图片旋转到正确方向', | ||
225 | - captchaShow: true | ||
226 | - }; | ||
227 | - | ||
228 | - logger.info(`captcha validate result:${captchaInput.toString() === captchaCode},user:${captchaInput};server:${captchaCode}`); | ||
229 | - | ||
230 | - --req.session.captchaValidCount; | ||
231 | - | ||
232 | - if (!errorCount) { | ||
233 | - _.set(req.session, 'captchaValidCount', 5); | ||
234 | - | ||
235 | - // delete req.session.captcha; // 验证码 用过就扔 | ||
236 | - req.session.captcha = null; | ||
237 | - jsonData.changeCaptcha = true; | ||
238 | - } | ||
239 | - | ||
240 | - if ( | ||
241 | - !( | ||
242 | - (captchaInput && captchaCode && captchaInput === captchaCode) || | ||
243 | - (testCode === config.testCode) | ||
244 | - ) | ||
245 | - ) { | ||
246 | - res.json(jsonData); | ||
247 | - | ||
248 | - return; | ||
249 | - } | ||
250 | - } | ||
251 | - | ||
252 | passport.authenticate('local', (err, user) => { | 198 | passport.authenticate('local', (err, user) => { |
253 | if (err || !user) { | 199 | if (err || !user) { |
254 | let obj = { | 200 | let obj = { |
@@ -118,37 +118,6 @@ let verifyMobile = (req, res, next) => { | @@ -118,37 +118,6 @@ let verifyMobile = (req, res, next) => { | ||
118 | 118 | ||
119 | let mobile = +req.body.phoneNum; | 119 | let mobile = +req.body.phoneNum; |
120 | let area = +(req.body.areaCode || 86); | 120 | let area = +(req.body.areaCode || 86); |
121 | - let captcha = (req.body.captcha || '').trim(); | ||
122 | - let testCode = req.body.yohobuy; | ||
123 | - | ||
124 | - let diffCaptcha = _.get(req.session, 'captcha'); | ||
125 | - let errorCount = _.get(req.session, 'captchaValidCount', 4); | ||
126 | - | ||
127 | - // error case: 没有验证码 | ||
128 | - if (!diffCaptcha) { | ||
129 | - data.message = '非法请求'; | ||
130 | - data.changeCaptcha = true; | ||
131 | - | ||
132 | - return res.json(data); | ||
133 | - } | ||
134 | - | ||
135 | - if (req.session.captchaValidCount) { | ||
136 | - --req.session.captchaValidCount; | ||
137 | - } | ||
138 | - | ||
139 | - if (!errorCount) { | ||
140 | - _.set(req.session, 'captchaValidCount', 4); | ||
141 | - | ||
142 | - req.session.captcha = null; | ||
143 | - data.changeCaptcha = true; | ||
144 | - } | ||
145 | - logger.info(`captcha validate result:${captcha.toString() === diffCaptcha},user:${captcha};server:${diffCaptcha}`); | ||
146 | - | ||
147 | - // error case: 验证码不匹配 | ||
148 | - if (!(captcha === diffCaptcha || testCode === config.testCode)) { | ||
149 | - data.message = '请将图片旋转到正确方向'; | ||
150 | - return res.json(data); | ||
151 | - } | ||
152 | 121 | ||
153 | // 判断参数是否合法 | 122 | // 判断参数是否合法 |
154 | if (!_.isNumber(mobile) || !_.isNumber(area)) { | 123 | if (!_.isNumber(mobile) || !_.isNumber(area)) { |
@@ -468,19 +437,6 @@ let setPassword = (req, res, next) => { | @@ -468,19 +437,6 @@ let setPassword = (req, res, next) => { | ||
468 | }).catch(next); | 437 | }).catch(next); |
469 | }; | 438 | }; |
470 | 439 | ||
471 | -/** | ||
472 | - * 生成 校验码 | ||
473 | - */ | ||
474 | -const genCaptcha = (req, res) => { | ||
475 | - let captcha = captchaService.generateCaptcha(90, 52, 4); | ||
476 | - | ||
477 | - _.set(req.session, 'phoneReg.captcha', captcha.text); | ||
478 | - | ||
479 | - res.type('png') | ||
480 | - .set('Cache-Control', 'no-cache') | ||
481 | - .status(200) | ||
482 | - .send(captcha.image); | ||
483 | -}; | ||
484 | 440 | ||
485 | module.exports = { | 441 | module.exports = { |
486 | guardStep, | 442 | guardStep, |
@@ -491,6 +447,5 @@ module.exports = { | @@ -491,6 +447,5 @@ module.exports = { | ||
491 | sendCode, | 447 | sendCode, |
492 | verifyCode, | 448 | verifyCode, |
493 | password: passwordAction, | 449 | password: passwordAction, |
494 | - setPassword, | ||
495 | - genCaptcha | 450 | + setPassword |
496 | }; | 451 | }; |
@@ -4,13 +4,11 @@ const _ = require('lodash'); | @@ -4,13 +4,11 @@ const _ = require('lodash'); | ||
4 | const moment = require('moment'); | 4 | const moment = require('moment'); |
5 | const helpers = global.yoho.helpers; | 5 | const helpers = global.yoho.helpers; |
6 | const cookie = global.yoho.cookie; | 6 | const cookie = global.yoho.cookie; |
7 | -const config = global.yoho.config; | ||
8 | const EventEmitter = require('events'); | 7 | const EventEmitter = require('events'); |
9 | const utils = require(global.utils); | 8 | const utils = require(global.utils); |
10 | const RegService = require('../models/reg-service'); | 9 | const RegService = require('../models/reg-service'); |
11 | const PhoneService = require('../models/phone-service'); | 10 | const PhoneService = require('../models/phone-service'); |
12 | const AuthHelper = require('../models/auth-helper'); | 11 | const AuthHelper = require('../models/auth-helper'); |
13 | -const logger = global.yoho.logger; | ||
14 | 12 | ||
15 | // constrant | 13 | // constrant |
16 | const CODE_REQUIRED = '请输入校验码'; | 14 | const CODE_REQUIRED = '请输入校验码'; |
@@ -147,24 +145,12 @@ exports.indexCheck = (req, res, next) => { | @@ -147,24 +145,12 @@ exports.indexCheck = (req, res, next) => { | ||
147 | 145 | ||
148 | let area = req.body.area = (req.body.area || '').trim(); | 146 | let area = req.body.area = (req.body.area || '').trim(); |
149 | let mobile = req.body.mobile = (req.body.mobile || '').trim(); | 147 | let mobile = req.body.mobile = (req.body.mobile || '').trim(); |
150 | - let captcode = (req.body.captcode || '').trim(); | ||
151 | - let captcodeValid = _.get(req.session, 'captcha'); | ||
152 | - let testCode = req.body.yohobuy; | ||
153 | - | ||
154 | - let em = new EventEmitter(); | ||
155 | - | ||
156 | - | ||
157 | - let errorCount = _.get(req.session, 'captchaValidCount', 4 - 1); // 初始1次 + 后续4次, 同一个验证码 共5次 | ||
158 | let errorData = { | 148 | let errorData = { |
159 | code: 400, | 149 | code: 400, |
160 | message: '' | 150 | message: '' |
161 | }; | 151 | }; |
162 | 152 | ||
163 | - if (!errorCount) { | ||
164 | - _.set(req.session, 'captchaValidCount', 3); | ||
165 | - } else { | ||
166 | - --req.session.captchaValidCount; | ||
167 | - } | 153 | + let em = new EventEmitter(); |
168 | 154 | ||
169 | // 校验 成功 | 155 | // 校验 成功 |
170 | em.on('resolve', () => { | 156 | em.on('resolve', () => { |
@@ -190,24 +176,9 @@ exports.indexCheck = (req, res, next) => { | @@ -190,24 +176,9 @@ exports.indexCheck = (req, res, next) => { | ||
190 | res.json(error); | 176 | res.json(error); |
191 | }); | 177 | }); |
192 | 178 | ||
193 | - if (req.session.captchaValidCount === 0) { | ||
194 | - req.session.captcha = null; // 验证码 用过就扔 | ||
195 | - errorData.changeCaptcha = true; | ||
196 | - } | ||
197 | - | ||
198 | - | ||
199 | - logger.info(`captcha validate result:${captcode.toString() === captcodeValid},user:${captcode};server:${captcodeValid}`); | ||
200 | // 验证 | 179 | // 验证 |
201 | if ([area, mobile].some(val => val === '')) { | 180 | if ([area, mobile].some(val => val === '')) { |
202 | return em.emit('reject', Object.assign(errorData, { message: '请填写手机号'})); | 181 | return em.emit('reject', Object.assign(errorData, { message: '请填写手机号'})); |
203 | - } else if (!captcode) { | ||
204 | - return em.emit('reject', Object.assign(errorData, {message: '请填写验证码'})); | ||
205 | - } else if ( | ||
206 | - !( | ||
207 | - (captcodeValid && captcode === captcodeValid) || (testCode === config.testCode) | ||
208 | - ) | ||
209 | - ) { | ||
210 | - return em.emit('reject', Object.assign(errorData, {message: '请将图片旋转到正确方向'})); | ||
211 | } | 182 | } |
212 | 183 | ||
213 | // congratulation~~ | 184 | // congratulation~~ |
apps/passport/controllers/validateCode.js
0 → 100644
1 | +/** | ||
2 | + * 验证码中间件 | ||
3 | + * @author feng.chen<feng.chen@yoho.cn> | ||
4 | + * @date 2017/03/23 | ||
5 | + */ | ||
6 | + | ||
7 | +'use strict'; | ||
8 | +const _ = require('lodash'); | ||
9 | +const config = global.yoho.config; | ||
10 | +const geetest = require('./geetest'); | ||
11 | +const captcha = require('./captcha'); | ||
12 | + | ||
13 | +/** | ||
14 | + * 验证验证码 | ||
15 | + */ | ||
16 | +const check = (req, res, next) => { | ||
17 | + let testCode = req.body.yohobuy; | ||
18 | + | ||
19 | + if (testCode === config.testCode) { | ||
20 | + return next(); | ||
21 | + } | ||
22 | + | ||
23 | + // 使用极验证 | ||
24 | + let useGeetest = !_.get(req.app.locals.wap, 'geetest.validation', false); | ||
25 | + | ||
26 | + return (useGeetest ? geetest : captcha).validate(req, res, next); | ||
27 | +}; | ||
28 | + | ||
29 | +/** | ||
30 | + * 加载验证码 | ||
31 | + */ | ||
32 | +const load = (req, res, next) => { | ||
33 | + res.locals.useGeetest = !_.get(req.app.locals.wap, 'geetest.validation', false); // 使用极验证 | ||
34 | + if (_.has(res, 'locals.loadJs')) { | ||
35 | + res.locals.loadJs.push({ | ||
36 | + src: global.yoho.config.geetestJs | ||
37 | + }); | ||
38 | + } else { | ||
39 | + res.locals.loadJs = [ | ||
40 | + { | ||
41 | + src: global.yoho.config.geetestJs | ||
42 | + } | ||
43 | + ]; | ||
44 | + } | ||
45 | + return next(); | ||
46 | +}; | ||
47 | + | ||
48 | +module.exports = { | ||
49 | + check, | ||
50 | + load | ||
51 | +}; |
@@ -20,6 +20,7 @@ const update = require(cRoot + '/update'); | @@ -20,6 +20,7 @@ const update = require(cRoot + '/update'); | ||
20 | const agreement = require(cRoot + '/app-agreement'); | 20 | const agreement = require(cRoot + '/app-agreement'); |
21 | 21 | ||
22 | const geetest = require(cRoot + '/geetest'); | 22 | const geetest = require(cRoot + '/geetest'); |
23 | +const validateCode = require(cRoot + '/validateCode'); | ||
23 | 24 | ||
24 | const router = express.Router(); // eslint-disable-line | 25 | const router = express.Router(); // eslint-disable-line |
25 | 26 | ||
@@ -27,9 +28,9 @@ const router = express.Router(); // eslint-disable-line | @@ -27,9 +28,9 @@ const router = express.Router(); // eslint-disable-line | ||
27 | router.get('/passport/geetest/register', geetest.register); | 28 | router.get('/passport/geetest/register', geetest.register); |
28 | 29 | ||
29 | // 兼容老的路由 | 30 | // 兼容老的路由 |
30 | -router.get('/signin.html', login.common.beforeLogin, smsLogin.loginPage); | ||
31 | -router.get('/reg.html', disableBFCahce, reg.index); | ||
32 | -router.get('/login.html', login.common.beforeLogin, login.local.international); | 31 | +router.get('/signin.html', validateCode.load, login.common.beforeLogin, smsLogin.loginPage); |
32 | +router.get('/reg.html', validateCode.load, disableBFCahce, reg.index); | ||
33 | +router.get('/login.html', validateCode.load, login.common.beforeLogin, login.local.international); | ||
33 | router.get('/phoneback.html', back.indexMobilePage); | 34 | router.get('/phoneback.html', back.indexMobilePage); |
34 | router.get('/emailback.html', back.indexEmailPage); | 35 | router.get('/emailback.html', back.indexEmailPage); |
35 | 36 | ||
@@ -37,16 +38,16 @@ router.get('/emailback.html', back.indexEmailPage); | @@ -37,16 +38,16 @@ router.get('/emailback.html', back.indexEmailPage); | ||
37 | router.get('/passport/signout/index', login.local.logout); | 38 | router.get('/passport/signout/index', login.local.logout); |
38 | 39 | ||
39 | // 登录页面 | 40 | // 登录页面 |
40 | -router.get('/passport/login', login.common.beforeLogin, login.local.loginPage); | ||
41 | -router.get('/passport/international', login.common.beforeLogin, login.local.international); | 41 | +router.get('/passport/login', validateCode.load, login.common.beforeLogin, login.local.loginPage); |
42 | +router.get('/passport/international', validateCode.load, login.common.beforeLogin, login.local.international); | ||
42 | 43 | ||
43 | // 本地登录 | 44 | // 本地登录 |
44 | -router.post('/passport/login/auth', geetest.validate, login.local.login); | 45 | +router.post('/passport/login/auth', validateCode.check, login.local.login); |
45 | 46 | ||
46 | // SMS 短信 | 47 | // SMS 短信 |
47 | router.use('/passport/sms_login', login.common.beforeLogin, smsLogin.beforeIn); | 48 | router.use('/passport/sms_login', login.common.beforeLogin, smsLogin.beforeIn); |
48 | -router.get('/passport/sms_login', smsLogin.loginPage); | ||
49 | -router.post('/passport/sms_login/step1_check', smsLogin.indexCheck); | 49 | +router.get('/passport/sms_login', validateCode.load, smsLogin.loginPage); |
50 | +router.post('/passport/sms_login/step1_check', validateCode.check, smsLogin.indexCheck); | ||
50 | router.get('/passport/sms_login/token.json', | 51 | router.get('/passport/sms_login/token.json', |
51 | smsLogin.tokenBefore, | 52 | smsLogin.tokenBefore, |
52 | smsLogin.token); // only ajax; | 53 | smsLogin.token); // only ajax; |
@@ -79,8 +80,8 @@ router.get('/login/alipay', login.common.beforeLogin, login.alipay.login); | @@ -79,8 +80,8 @@ router.get('/login/alipay', login.common.beforeLogin, login.alipay.login); | ||
79 | router.get('/login/alipay/callback', login.alipay.callback); | 80 | router.get('/login/alipay/callback', login.alipay.callback); |
80 | 81 | ||
81 | // 登录绑定 | 82 | // 登录绑定 |
82 | -router.get('/passport/bind/index', bind.indexPage); | ||
83 | -router.post('/passport/bind/bindCheck', bind.bindCheck); | 83 | +router.get('/passport/bind/index', validateCode.load, bind.indexPage); |
84 | +router.post('/passport/bind/bindCheck', validateCode.check, bind.bindCheck); | ||
84 | router.get('/passport/bind/code', bind.codePage); | 85 | router.get('/passport/bind/code', bind.codePage); |
85 | router.post('/passport/bind/sendBindMsg', | 86 | router.post('/passport/bind/sendBindMsg', |
86 | bind.sendBefore, | 87 | bind.sendBefore, |
@@ -98,9 +99,8 @@ router.post('/passport/bind/changeMobile', bind.changeMobile); | @@ -98,9 +99,8 @@ router.post('/passport/bind/changeMobile', bind.changeMobile); | ||
98 | * 注册 | 99 | * 注册 |
99 | */ | 100 | */ |
100 | router.use('/passport/reg/*', disableBFCahce); | 101 | router.use('/passport/reg/*', disableBFCahce); |
101 | -router.get('/passport/reg/index', reg.index); | ||
102 | -router.get('/passport/reg/captcha.png', reg.genCaptcha); | ||
103 | -router.post('/passport/reg/verifymobile', reg.sendCodeBusyBoy, reg.verifyMobile); | 102 | +router.get('/passport/reg/index', validateCode.load, reg.index); |
103 | +router.post('/passport/reg/verifymobile', validateCode.check, reg.sendCodeBusyBoy, reg.verifyMobile); | ||
104 | router.get('/passport/reg/code', reg.guardStep(2), reg.code); | 104 | router.get('/passport/reg/code', reg.guardStep(2), reg.code); |
105 | router.post('/passport/reg/sendcode', reg.guardStep(2), reg.sendCodeBusyBoy, reg.sendCode); | 105 | router.post('/passport/reg/sendcode', reg.guardStep(2), reg.sendCodeBusyBoy, reg.sendCode); |
106 | router.post('/passport/reg/verifycode', reg.guardStep(2), reg.verifyCode); | 106 | router.post('/passport/reg/verifycode', reg.guardStep(2), reg.verifyCode); |
@@ -115,10 +115,10 @@ router.post('/passport/back/sendemail', back.sendCodeToEmailAPI);// 发送邮箱 | @@ -115,10 +115,10 @@ router.post('/passport/back/sendemail', back.sendCodeToEmailAPI);// 发送邮箱 | ||
115 | router.get('/passport/back/resendemail', back.resendCodeToEmailAPI);// 重新发送邮箱验证码 | 115 | router.get('/passport/back/resendemail', back.resendCodeToEmailAPI);// 重新发送邮箱验证码 |
116 | router.get('/passport/back/success', back.backSuccessByEmailPage);// 邮箱找回密码-发送成功页面 | 116 | router.get('/passport/back/success', back.backSuccessByEmailPage);// 邮箱找回密码-发送成功页面 |
117 | 117 | ||
118 | -router.get('/passport/back/mobile', back.indexMobilePage);// 输入手机号找回密码页面 | 118 | +router.get('/passport/back/mobile', validateCode.load, back.indexMobilePage);// 输入手机号找回密码页面 |
119 | router.get('/passport/back/mobilecode', back.verifyCodeByMobilePage);// 输入手机验证码页面 | 119 | router.get('/passport/back/mobilecode', back.verifyCodeByMobilePage);// 输入手机验证码页面 |
120 | router.get('/passport/back/generatecodeimg.png', back.generateCodeImg);// 生成图片验证码 | 120 | router.get('/passport/back/generatecodeimg.png', back.generateCodeImg);// 生成图片验证码 |
121 | -router.post('/passport/back/sendcode', back.sendCodeToMobileAPI);// 发送手机验证码 | 121 | +router.post('/passport/back/sendcode', validateCode.check, back.sendCodeToMobileAPI);// 发送手机验证码 |
122 | router.post('/passport/back/verifycode', back.verifyCodeByMobileAPI);// 校验手机验证码 | 122 | router.post('/passport/back/verifycode', back.verifyCodeByMobileAPI);// 校验手机验证码 |
123 | 123 | ||
124 | router.get('/passport/back/backcode', back.setNewPasswordByMobilePage);// 设置新密码页面 | 124 | router.get('/passport/back/backcode', back.setNewPasswordByMobilePage);// 设置新密码页面 |
@@ -6,11 +6,8 @@ | @@ -6,11 +6,8 @@ | ||
6 | <span id="area-code" class="area-code">{{areaCode}}</span> | 6 | <span id="area-code" class="area-code">{{areaCode}}</span> |
7 | <input id="phone-num" class="input phone-num" type="text" placeholder="手机号"> | 7 | <input id="phone-num" class="input phone-num" type="text" placeholder="手机号"> |
8 | </div> | 8 | </div> |
9 | - {{!--图片验证 start--}} | ||
10 | - <div id="js-img-check"> | ||
11 | - <input type="hidden" name="captsrc" value="{{captsrc}}"> | ||
12 | - </div> | ||
13 | - {{!--图片验证 end--}} | 9 | + {{!--图片验证--}} |
10 | + <div data-geetest="{{useGeetest}}" id="js-img-check"></div> | ||
14 | <span id="btn-next" class="btn btn-next disable row">下一步</span> | 11 | <span id="btn-next" class="btn btn-next disable row">下一步</span> |
15 | </div> | 12 | </div> |
16 | </div> | 13 | </div> |
@@ -14,12 +14,8 @@ | @@ -14,12 +14,8 @@ | ||
14 | <span id="area-code" class="area-code">{{areaCode}}</span> | 14 | <span id="area-code" class="area-code">{{areaCode}}</span> |
15 | <input id="phone-num" class="input phone-num" type="text" placeholder="手机号"> | 15 | <input id="phone-num" class="input phone-num" type="text" placeholder="手机号"> |
16 | </div> | 16 | </div> |
17 | - | ||
18 | - {{!--图片验证 start--}} | ||
19 | - <div id="js-img-check"> | ||
20 | - <input type="hidden" name="captsrc" value="{{captsrc}}"> | ||
21 | - </div> | ||
22 | - {{!--图片验证 end--}} | 17 | + {{!--图片验证--}} |
18 | + <div data-geetest="{{useGeetest}}" id="js-img-check"></div> | ||
23 | 19 | ||
24 | <span id="btn-next" class="btn btn-next disable row">发送验证码</span> | 20 | <span id="btn-next" class="btn btn-next disable row">发送验证码</span> |
25 | 21 |
@@ -9,7 +9,8 @@ | @@ -9,7 +9,8 @@ | ||
9 | <div class="input-container row has-eye"> | 9 | <div class="input-container row has-eye"> |
10 | <input id="pwd" class="pwd input" type="password" placeholder="密码"> | 10 | <input id="pwd" class="pwd input" type="password" placeholder="密码"> |
11 | </div> | 11 | </div> |
12 | - <div data-geetest="{{useGeetest}}" id="js-img-check" {{#captchaShow }}data-init{{/captchaShow}}></div> | 12 | + {{!--图片验证--}} |
13 | + <div data-geetest="{{useGeetest}}" id="js-img-check"></div> | ||
13 | 14 | ||
14 | <span id="btn-login" class="btn btn-login disble row">登录</span> | 15 | <span id="btn-login" class="btn btn-login disble row">登录</span> |
15 | </div> | 16 | </div> |
@@ -8,7 +8,8 @@ | @@ -8,7 +8,8 @@ | ||
8 | <div class="input-container row has-eye"> | 8 | <div class="input-container row has-eye"> |
9 | <input id="pwd" class="pwd input" type="password" placeholder="密码"> | 9 | <input id="pwd" class="pwd input" type="password" placeholder="密码"> |
10 | </div> | 10 | </div> |
11 | - <div data-geetest="{{useGeetest}}" id="js-img-check" {{#captchaShow }}data-init{{/captchaShow}}></div> | 11 | + {{!--图片验证--}} |
12 | + <div data-geetest="{{useGeetest}}" id="js-img-check"></div> | ||
12 | <span id="btn-login" class="btn btn-login disable">登录</span> | 13 | <span id="btn-login" class="btn btn-login disable">登录</span> |
13 | <p class="op-container"> | 14 | <p class="op-container"> |
14 | <a class="op-item internat" href={{internationalUrl}}>海外手机</a> | 15 | <a class="op-item internat" href={{internationalUrl}}>海外手机</a> |
@@ -7,11 +7,8 @@ | @@ -7,11 +7,8 @@ | ||
7 | <input id="phone-num" class="input phone-num" type="text" placeholder="手机号"> | 7 | <input id="phone-num" class="input phone-num" type="text" placeholder="手机号"> |
8 | </div> | 8 | </div> |
9 | 9 | ||
10 | - {{!--图片验证 start--}} | ||
11 | - <div id="js-img-check"> | ||
12 | - <input type="hidden" name="captsrc" value="{{captsrc}}"> | ||
13 | - </div> | ||
14 | - {{!--图片验证 end--}} | 10 | + {{!--图片验证--}} |
11 | + <div data-geetest="{{useGeetest}}" id="js-img-check"></div> | ||
15 | 12 | ||
16 | <span id="btn-next" class="btn btn-next disable row">下一步</span> | 13 | <span id="btn-next" class="btn btn-next disable row">下一步</span> |
17 | <p class="register-tip">Yoho!Family账号可登录Yoho!Buy有货、Yoho!Now、mars及SHOW</p> | 14 | <p class="register-tip">Yoho!Family账号可登录Yoho!Buy有货、Yoho!Now、mars及SHOW</p> |
@@ -7,11 +7,8 @@ | @@ -7,11 +7,8 @@ | ||
7 | <input id="phone-num" class="input phone-num" type="text" placeholder="手机号"> | 7 | <input id="phone-num" class="input phone-num" type="text" placeholder="手机号"> |
8 | <button class="clear-input" type="button"></button> | 8 | <button class="clear-input" type="button"></button> |
9 | </div> | 9 | </div> |
10 | - {{!--图片验证 start--}} | ||
11 | - <div id="js-img-check"> | ||
12 | - <input type="hidden" name="captsrc" value="{{captsrc}}"> | ||
13 | - </div> | ||
14 | - {{!--图片验证 end--}} | 10 | + {{!--图片验证--}} |
11 | + <div data-geetest="{{useGeetest}}" id="js-img-check"></div> | ||
15 | <button id="btn-next" class="btn btn-next disable row" disabled>获取短信验证码</button> | 12 | <button id="btn-next" class="btn btn-next disable row" disabled>获取短信验证码</button> |
16 | <p class="op-container"> | 13 | <p class="op-container"> |
17 | {{#if openPassword}} | 14 | {{#if openPassword}} |
@@ -10,8 +10,8 @@ const isProduction = process.env.NODE_ENV === 'production'; | @@ -10,8 +10,8 @@ const isProduction = process.env.NODE_ENV === 'production'; | ||
10 | const isTest = process.env.NODE_ENV === 'test'; | 10 | const isTest = process.env.NODE_ENV === 'test'; |
11 | 11 | ||
12 | const domains = { | 12 | const domains = { |
13 | - api: 'http://api.yoho.cn/', | ||
14 | - service: 'http://service.yoho.cn/', | 13 | + api: 'http://api-test3.yohops.com:9999/', |
14 | + service: 'http://dev-service.yohops.com:9999/', | ||
15 | liveApi: 'http://testapi.live.yohops.com:9999/', | 15 | liveApi: 'http://testapi.live.yohops.com:9999/', |
16 | singleApi: 'http://api-test3.yohops.com:9999/', | 16 | singleApi: 'http://api-test3.yohops.com:9999/', |
17 | 17 |
1 | { | 1 | { |
2 | "name": "m-yohobuy-node", | 2 | "name": "m-yohobuy-node", |
3 | - "version": "5.5.3", | 3 | + "version": "5.5.4", |
4 | "private": true, | 4 | "private": true, |
5 | "description": "A New Yohobuy Project With Express", | 5 | "description": "A New Yohobuy Project With Express", |
6 | "repository": { | 6 | "repository": { |
@@ -49,7 +49,7 @@ | @@ -49,7 +49,7 @@ | ||
49 | "uuid": "^2.0.3", | 49 | "uuid": "^2.0.3", |
50 | "xml2js": "^0.4.17", | 50 | "xml2js": "^0.4.17", |
51 | "yoho-express-session": "^2.0.0", | 51 | "yoho-express-session": "^2.0.0", |
52 | - "yoho-node-lib": "^0.2.8", | 52 | + "yoho-node-lib": "0.2.8", |
53 | "yoho-zookeeper": "^1.0.8" | 53 | "yoho-zookeeper": "^1.0.8" |
54 | }, | 54 | }, |
55 | "devDependencies": { | 55 | "devDependencies": { |
@@ -12,6 +12,4 @@ | @@ -12,6 +12,4 @@ | ||
12 | <li class="img-check-pic" data-val="0" style="background-image:url('{{imgSrc}}');"></li> | 12 | <li class="img-check-pic" data-val="0" style="background-image:url('{{imgSrc}}');"></li> |
13 | </ul> | 13 | </ul> |
14 | </div> | 14 | </div> |
15 | - | ||
16 | - <input id="yohobuy" type="text" style="display:none;"> | ||
17 | </div> | 15 | </div> |
1 | require('3party/check.page.css'); | 1 | require('3party/check.page.css'); |
2 | require('../common'); | 2 | require('../common'); |
3 | + | ||
3 | // 图片验证码 | 4 | // 图片验证码 |
4 | -let ImgCheck = require('plugin/img-check'); | 5 | +let Validate = require('plugin/validata'); |
5 | 6 | ||
6 | -let imgCheck = new ImgCheck('#js-img-check', { | 7 | +let validate = new Validate('#js-img-check', { |
7 | useREM: { | 8 | useREM: { |
8 | rootFontSize: 40, | 9 | rootFontSize: 40, |
9 | picWidth: 150 | 10 | picWidth: 150 |
10 | } | 11 | } |
11 | }); | 12 | }); |
12 | 13 | ||
13 | -imgCheck.init(); | 14 | +validate.init(); |
14 | 15 | ||
15 | $(function() { | 16 | $(function() { |
16 | $('.submit').on('click', function() { | 17 | $('.submit').on('click', function() { |
18 | + validate.getResults().then((result) => { | ||
17 | $.ajax({ | 19 | $.ajax({ |
18 | method: 'POST', | 20 | method: 'POST', |
19 | url: '/3party/check/submit', | 21 | url: '/3party/check/submit', |
20 | - data: { | ||
21 | - captcha: $.trim(imgCheck.getResults()) | ||
22 | - }, | 22 | + data: result, |
23 | success: function(ret) { | 23 | success: function(ret) { |
24 | + validate.type === 2 && validate.refresh(); | ||
24 | if (ret.code === 200) { | 25 | if (ret.code === 200) { |
25 | - window.location.href = decodeURIComponent(window.queryString.refer) || '//m.yohobuy.com'; | 26 | + if (window.queryString.refer) { |
27 | + window.location.href = decodeURIComponent(window.queryString.refer); | ||
28 | + } else { | ||
29 | + window.location.href = '//m.yohobuy.com'; | ||
30 | + } | ||
26 | } else { | 31 | } else { |
27 | - imgCheck.refresh(); | 32 | + validate.refresh(); |
28 | } | 33 | } |
29 | } | 34 | } |
30 | }); | 35 | }); |
31 | }); | 36 | }); |
37 | + | ||
38 | + }); | ||
32 | }); | 39 | }); |
@@ -20,16 +20,16 @@ var trim = $.trim; | @@ -20,16 +20,16 @@ var trim = $.trim; | ||
20 | var showErrTip = tip.show; | 20 | var showErrTip = tip.show; |
21 | 21 | ||
22 | // 图片验证码 | 22 | // 图片验证码 |
23 | -let ImgCheck = require('plugin/img-check'); | 23 | +let Validate = require('plugin/validata'); |
24 | 24 | ||
25 | -let imgCheck = new ImgCheck('#js-img-check', { | 25 | +let validate = new Validate('#js-img-check', { |
26 | useREM: { | 26 | useREM: { |
27 | rootFontSize: 40, | 27 | rootFontSize: 40, |
28 | picWidth: 150 | 28 | picWidth: 150 |
29 | } | 29 | } |
30 | }); | 30 | }); |
31 | 31 | ||
32 | -imgCheck.init(); | 32 | +validate.init(); |
33 | 33 | ||
34 | api.selectCssHack($('#country-select')); | 34 | api.selectCssHack($('#country-select')); |
35 | 35 | ||
@@ -56,25 +56,27 @@ $verifyCodeImg.on('touchstart', function() { | @@ -56,25 +56,27 @@ $verifyCodeImg.on('touchstart', function() { | ||
56 | 56 | ||
57 | $btnNext.on('touchstart', function() { | 57 | $btnNext.on('touchstart', function() { |
58 | var pn = trim($phoneNum.val()), | 58 | var pn = trim($phoneNum.val()), |
59 | - area = trim($countrySelect.val()), | ||
60 | - verify = trim(imgCheck.getResults()); | 59 | + area = trim($countrySelect.val()); |
61 | 60 | ||
62 | if ($btnNext.hasClass('disable')) { | 61 | if ($btnNext.hasClass('disable')) { |
63 | return; | 62 | return; |
64 | } | 63 | } |
65 | 64 | ||
66 | 65 | ||
67 | - if (verify && area && pn && api.phoneRegx[area].test(pn)) { | 66 | + if (area && pn && api.phoneRegx[area].test(pn)) { |
67 | + validate.getResults().then((result) => { | ||
68 | + let params = { | ||
69 | + areaCode: area.replace('+', ''), | ||
70 | + phoneNum: pn | ||
71 | + }; | ||
72 | + | ||
73 | + $.extend(params, result); | ||
68 | $.ajax({ | 74 | $.ajax({ |
69 | url: '/passport/back/sendcode', | 75 | url: '/passport/back/sendcode', |
70 | type: 'POST', | 76 | type: 'POST', |
71 | - data: { | ||
72 | - areaCode: area.replace('+', ''), | ||
73 | - phoneNum: pn, | ||
74 | - verifyCode: verify, | ||
75 | - yohobuy: $('#yohobuy').val() | ||
76 | - }, | 77 | + data: params, |
77 | success: function(data) { | 78 | success: function(data) { |
79 | + validate.type === 2 && validate.refresh(); | ||
78 | if (data.code === 200) { | 80 | if (data.code === 200) { |
79 | location.href = data.data; | 81 | location.href = data.data; |
80 | return; | 82 | return; |
@@ -84,10 +86,15 @@ $btnNext.on('touchstart', function() { | @@ -84,10 +86,15 @@ $btnNext.on('touchstart', function() { | ||
84 | } else { | 86 | } else { |
85 | showErrTip(data.message); | 87 | showErrTip(data.message); |
86 | } | 88 | } |
87 | - | ||
88 | - data.changeCaptcha && imgCheck.refresh(); | 89 | + (data.changeCaptcha && validate.type !== 2) && validate.refresh(); |
90 | + }, | ||
91 | + error: function() { | ||
92 | + showErrTip('出错了,请重试'); | ||
93 | + validate.refresh(); | ||
89 | } | 94 | } |
90 | }); | 95 | }); |
96 | + }); | ||
97 | + | ||
91 | } else if (!area) { | 98 | } else if (!area) { |
92 | showErrTip('出错了,请重新刷新页面'); | 99 | showErrTip('出错了,请重新刷新页面'); |
93 | } else { | 100 | } else { |
@@ -24,16 +24,16 @@ var requested = false; | @@ -24,16 +24,16 @@ var requested = false; | ||
24 | 24 | ||
25 | require('common'); | 25 | require('common'); |
26 | 26 | ||
27 | -var ImgCheck = require('plugin/img-check'); | 27 | +var Validate = require('plugin/validata'); |
28 | 28 | ||
29 | -var imgCheck = new ImgCheck('#js-img-check', { | 29 | +var validate = new Validate('#js-img-check', { |
30 | useREM: { | 30 | useREM: { |
31 | rootFontSize: 40, | 31 | rootFontSize: 40, |
32 | picWidth: 150 | 32 | picWidth: 150 |
33 | } | 33 | } |
34 | }); | 34 | }); |
35 | 35 | ||
36 | -imgCheck.init(); | 36 | +validate.init(); |
37 | 37 | ||
38 | function nextStep(url, mobileNo, areaCode) { | 38 | function nextStep(url, mobileNo, areaCode) { |
39 | if (requested) { | 39 | if (requested) { |
@@ -95,36 +95,29 @@ $btnNext.on('touchstart', function() { | @@ -95,36 +95,29 @@ $btnNext.on('touchstart', function() { | ||
95 | openId = trim($openId.val()), | 95 | openId = trim($openId.val()), |
96 | nickname = trim($nickname.val()), | 96 | nickname = trim($nickname.val()), |
97 | sourceType = trim($sourceType.val()), | 97 | sourceType = trim($sourceType.val()), |
98 | - areaCode = $countrySelect.val(), | ||
99 | - verify = trim(imgCheck.getResults()); | 98 | + areaCode = $countrySelect.val(); |
100 | 99 | ||
101 | if ($btnNext.hasClass('disable')) { | 100 | if ($btnNext.hasClass('disable')) { |
102 | return; | 101 | return; |
103 | } | 102 | } |
104 | 103 | ||
105 | if (api.phoneRegx[areaCode].test(pn)) { | 104 | if (api.phoneRegx[areaCode].test(pn)) { |
106 | - $.ajax({ | ||
107 | - url: '/passport/bind/bindCheck', | ||
108 | - type: 'POST', | ||
109 | - data: { | 105 | + validate.getResults().then((result) => { |
106 | + let params = { | ||
110 | areaCode: areaCode.replace('+', ''), | 107 | areaCode: areaCode.replace('+', ''), |
111 | phoneNum: pn, | 108 | phoneNum: pn, |
112 | openId: openId, | 109 | openId: openId, |
113 | sourceType: sourceType, | 110 | sourceType: sourceType, |
114 | - nickname: nickname, | ||
115 | - verify: verify | ||
116 | - }, | ||
117 | - success: function(res) { | ||
118 | - | ||
119 | - // res : { | ||
120 | - // code: 'xxx', | ||
121 | - // data: { | ||
122 | - // isReg: 0, | ||
123 | - // next: 'xxxx' | ||
124 | - // }, | ||
125 | - // message: 'xxxx', | ||
126 | - // } | 111 | + nickname: nickname |
112 | + }; | ||
127 | 113 | ||
114 | + $.extend(params, result); | ||
115 | + $.ajax({ | ||
116 | + url: '/passport/bind/bindCheck', | ||
117 | + type: 'POST', | ||
118 | + data: params, | ||
119 | + success: function(res) { | ||
120 | + validate.type === 2 && validate.refresh(); | ||
128 | if (res.code === 200) { | 121 | if (res.code === 200) { |
129 | if (res.data.isReg === 1) { | 122 | if (res.data.isReg === 1) { |
130 | dialog.showDialog({ | 123 | dialog.showDialog({ |
@@ -150,10 +143,19 @@ $btnNext.on('touchstart', function() { | @@ -150,10 +143,19 @@ $btnNext.on('touchstart', function() { | ||
150 | nextStep(res.data.next, pn, areaCode); | 143 | nextStep(res.data.next, pn, areaCode); |
151 | } | 144 | } |
152 | } else { | 145 | } else { |
146 | + if (res.captchaShow) { | ||
147 | + ((res.changeCaptcha && validate.type !== 2) && validate.refresh()); | ||
148 | + } | ||
153 | showErrTip(res.message); | 149 | showErrTip(res.message); |
154 | } | 150 | } |
151 | + }, | ||
152 | + error: function() { | ||
153 | + showErrTip('网络断开连接啦~'); | ||
154 | + validate.refresh(); | ||
155 | } | 155 | } |
156 | }); | 156 | }); |
157 | + }); | ||
158 | + | ||
157 | } else { | 159 | } else { |
158 | showErrTip('手机号格式不正确,请重新输入'); | 160 | showErrTip('手机号格式不正确,请重新输入'); |
159 | } | 161 | } |
@@ -20,7 +20,7 @@ require('./login/login'); | @@ -20,7 +20,7 @@ require('./login/login'); | ||
20 | setTimeout(function() { | 20 | setTimeout(function() { |
21 | var yas = window._yas; | 21 | var yas = window._yas; |
22 | 22 | ||
23 | - yas && yas.sendCustomInfo({ | 23 | + yas && yas.sendCustomInfo && yas.sendCustomInfo({ |
24 | op: 'YB_LOGIN_L', | 24 | op: 'YB_LOGIN_L', |
25 | param: param | 25 | param: param |
26 | }); | 26 | }); |
@@ -33,7 +33,7 @@ require('./login/login'); | @@ -33,7 +33,7 @@ require('./login/login'); | ||
33 | $smsLogin.on('click', function() { | 33 | $smsLogin.on('click', function() { |
34 | var yas = window._yas; | 34 | var yas = window._yas; |
35 | 35 | ||
36 | - yas && yas.sendCustomInfo({ | 36 | + yas && yas.sendCustomInfo && yas.sendCustomInfo({ |
37 | op: 'YB_MOBILE_QUICK_LOGIN_C', | 37 | op: 'YB_MOBILE_QUICK_LOGIN_C', |
38 | param: param | 38 | param: param |
39 | }); | 39 | }); |
@@ -30,9 +30,7 @@ var validate = new Validate($captcha, { | @@ -30,9 +30,7 @@ var validate = new Validate($captcha, { | ||
30 | } | 30 | } |
31 | }); | 31 | }); |
32 | 32 | ||
33 | -if ($captcha.data('init') != null) { //eslint-disable-line | ||
34 | - validate.init(); | ||
35 | -} | 33 | +validate.init(); |
36 | 34 | ||
37 | 35 | ||
38 | // 登录按钮状态切换 | 36 | // 登录按钮状态切换 |
@@ -92,31 +90,20 @@ $loginBtn.on('touchstart', function() { | @@ -92,31 +90,20 @@ $loginBtn.on('touchstart', function() { | ||
92 | } | 90 | } |
93 | 91 | ||
94 | if ((api.phoneRegx[areaCode].test(pn) || areaCode !== '+86') && api.pwdValidate(pwd)) { | 92 | if ((api.phoneRegx[areaCode].test(pn) || areaCode !== '+86') && api.pwdValidate(pwd)) { |
95 | - | ||
96 | - let validResult = validate.getResults(); | ||
97 | - | ||
98 | - if (typeof validResult === 'string') { | ||
99 | - if (validResult === '0000') { | ||
100 | - return tip.show(' 请将图片旋转到正确方向'); | ||
101 | - } | ||
102 | - validResult = Promise.resolve({captcha: validResult}); | ||
103 | - } | ||
104 | - validResult.then((captcha) => { | 93 | + validate.getResults().then((result) => { |
105 | $loginBtn.text('正在登录...').addClass('disable'); | 94 | $loginBtn.text('正在登录...').addClass('disable'); |
106 | - let data = { | 95 | + let params = { |
107 | areaCode: areaCode.replace('+', ''), | 96 | areaCode: areaCode.replace('+', ''), |
108 | account: pn, | 97 | account: pn, |
109 | password: pwd | 98 | password: pwd |
110 | }; | 99 | }; |
111 | 100 | ||
112 | - if (validate.atWorking) { | ||
113 | - $.extend(data, captcha); | ||
114 | - } | 101 | + $.extend(params, result); |
115 | 102 | ||
116 | $.ajax({ | 103 | $.ajax({ |
117 | type: 'POST', | 104 | type: 'POST', |
118 | url: '/passport/login/auth', | 105 | url: '/passport/login/auth', |
119 | - data, | 106 | + data: params, |
120 | success: function(data) { | 107 | success: function(data) { |
121 | var res; | 108 | var res; |
122 | 109 | ||
@@ -134,7 +121,7 @@ $loginBtn.on('touchstart', function() { | @@ -134,7 +121,7 @@ $loginBtn.on('touchstart', function() { | ||
134 | showErrTip('登录成功'); | 121 | showErrTip('登录成功'); |
135 | } else { | 122 | } else { |
136 | if (data.captchaShow) { | 123 | if (data.captchaShow) { |
137 | - validate.atWorking ? ((data.changeCaptcha || validate.type !== 2) && validate.refresh()) : validate.init(); | 124 | + ((data.changeCaptcha && validate.type !== 2) && validate.refresh()); |
138 | } | 125 | } |
139 | 126 | ||
140 | showErrTip(data.message); | 127 | showErrTip(data.message); |
@@ -145,7 +132,7 @@ $loginBtn.on('touchstart', function() { | @@ -145,7 +132,7 @@ $loginBtn.on('touchstart', function() { | ||
145 | showErrTip('网络断开连接啦~'); | 132 | showErrTip('网络断开连接啦~'); |
146 | $loginBtn.text('登录'); | 133 | $loginBtn.text('登录'); |
147 | 134 | ||
148 | - validate.atWorking && validate.refresh(); | 135 | + validate.refresh(); |
149 | } | 136 | } |
150 | }); | 137 | }); |
151 | }); | 138 | }); |
@@ -32,9 +32,7 @@ var validate = new Validate($captcha, { | @@ -32,9 +32,7 @@ var validate = new Validate($captcha, { | ||
32 | } | 32 | } |
33 | }); | 33 | }); |
34 | 34 | ||
35 | -if ($captcha.data('init') != null) { //eslint-disable-line | ||
36 | - validate.init(); | ||
37 | -} | 35 | +validate.init(); |
38 | 36 | ||
39 | // 登录按钮状态切换 | 37 | // 登录按钮状态切换 |
40 | function switchLoginBtnStatus() { | 38 | function switchLoginBtnStatus() { |
@@ -97,32 +95,21 @@ $loginBtn.on('touchstart', function() { | @@ -97,32 +95,21 @@ $loginBtn.on('touchstart', function() { | ||
97 | 95 | ||
98 | // 验证账号(数字或者邮箱)和密码合理性 | 96 | // 验证账号(数字或者邮箱)和密码合理性 |
99 | if ((/^[0-9]+$/.test(acc) || api.emailRegx.test(acc)) && api.pwdValidate(pwd)) { | 97 | if ((/^[0-9]+$/.test(acc) || api.emailRegx.test(acc)) && api.pwdValidate(pwd)) { |
100 | - let validResult = validate.getResults(); | ||
101 | - | ||
102 | - if (typeof validResult === 'string') { | ||
103 | - if (validResult === '0000') { | ||
104 | - return tip.show(' 请将图片旋转到正确方向'); | ||
105 | - } | ||
106 | - validResult = Promise.resolve({captcha: validResult}); | ||
107 | - } | ||
108 | - validResult.then((captcha) => { | 98 | + validate.getResults().then((result) => { |
109 | $loginBtn.text('正在登录...').addClass('disable'); | 99 | $loginBtn.text('正在登录...').addClass('disable'); |
110 | 100 | ||
111 | - let data = { | 101 | + let params = { |
112 | account: acc, | 102 | account: acc, |
113 | - password: pwd, | ||
114 | - yohobuy: $('#yohobuy').val() | 103 | + password: pwd |
115 | }; | 104 | }; |
116 | 105 | ||
117 | - if (validate.atWorking) { | ||
118 | - $.extend(data, captcha); | ||
119 | - } | 106 | + $.extend(params, result); |
120 | 107 | ||
121 | $.ajax({ | 108 | $.ajax({ |
122 | type: 'POST', | 109 | type: 'POST', |
123 | url: '/passport/login/auth', | 110 | url: '/passport/login/auth', |
124 | - data, | ||
125 | - success: function(data) { //eslint-disable-line | 111 | + data: params, |
112 | + success: function(data) { | ||
126 | var res, | 113 | var res, |
127 | LOGI_TYPE; | 114 | LOGI_TYPE; |
128 | 115 | ||
@@ -150,7 +137,7 @@ $loginBtn.on('touchstart', function() { | @@ -150,7 +137,7 @@ $loginBtn.on('touchstart', function() { | ||
150 | $loginBtn.text('登录成功'); | 137 | $loginBtn.text('登录成功'); |
151 | } else { | 138 | } else { |
152 | if (data.captchaShow) { | 139 | if (data.captchaShow) { |
153 | - validate.atWorking ? ((data.changeCaptcha || validate.type !== 2) && validate.refresh()) : validate.init(); | 140 | + ((data.changeCaptcha && validate.type !== 2) && validate.refresh()); |
154 | } | 141 | } |
155 | 142 | ||
156 | showErrTip(data.message); | 143 | showErrTip(data.message); |
@@ -162,7 +149,7 @@ $loginBtn.on('touchstart', function() { | @@ -162,7 +149,7 @@ $loginBtn.on('touchstart', function() { | ||
162 | error: function() { | 149 | error: function() { |
163 | showErrTip('网络断开连接啦~'); | 150 | showErrTip('网络断开连接啦~'); |
164 | 151 | ||
165 | - validate.atWorking && validate.refresh(); | 152 | + validate.refresh(); |
166 | }, | 153 | }, |
167 | complete: function() { | 154 | complete: function() { |
168 | $loginBtn.text('登录').removeClass('disable'); | 155 | $loginBtn.text('登录').removeClass('disable'); |
@@ -26,16 +26,16 @@ api.bindClearEvt(); | @@ -26,16 +26,16 @@ api.bindClearEvt(); | ||
26 | 26 | ||
27 | 27 | ||
28 | // 图片验证码 | 28 | // 图片验证码 |
29 | -let ImgCheck = require('plugin/img-check'); | 29 | +let Validate = require('plugin/validata'); |
30 | 30 | ||
31 | -let imgCheck = new ImgCheck('#js-img-check', { | 31 | +let validate = new Validate('#js-img-check', { |
32 | useREM: { | 32 | useREM: { |
33 | rootFontSize: 40, | 33 | rootFontSize: 40, |
34 | picWidth: 150 | 34 | picWidth: 150 |
35 | } | 35 | } |
36 | }); | 36 | }); |
37 | 37 | ||
38 | -imgCheck.init(); | 38 | +validate.init(); |
39 | 39 | ||
40 | /** | 40 | /** |
41 | * 必填校验 | 41 | * 必填校验 |
@@ -70,41 +70,33 @@ $countrySelect.change(function() { | @@ -70,41 +70,33 @@ $countrySelect.change(function() { | ||
70 | 70 | ||
71 | $btnNext.on('touchstart', function() { | 71 | $btnNext.on('touchstart', function() { |
72 | var pn = trim($phoneNum.val()), | 72 | var pn = trim($phoneNum.val()), |
73 | - areaCode = $countrySelect.val(), | ||
74 | - captcha = imgCheck.getResults(); | ||
75 | - | ||
76 | - if (captcha === '0000') { | ||
77 | - tip.show('请将图片旋转到正确方向'); | ||
78 | - return false; | ||
79 | - } | 73 | + areaCode = $countrySelect.val(); |
80 | 74 | ||
81 | if ($btnNext.hasClass('disable')) { | 75 | if ($btnNext.hasClass('disable')) { |
82 | return; | 76 | return; |
83 | } | 77 | } |
84 | - | ||
85 | if (requested) { | 78 | if (requested) { |
86 | return false; | 79 | return false; |
87 | } | 80 | } |
88 | - | ||
89 | - | ||
90 | if (api.phoneRegx[areaCode].test(pn) || areaCode !== '+86') { | 81 | if (api.phoneRegx[areaCode].test(pn) || areaCode !== '+86') { |
91 | - | 82 | + validate.getResults().then((result) => { |
92 | requested = true; | 83 | requested = true; |
84 | + let params = { | ||
85 | + areaCode: areaCode.replace('+', ''), | ||
86 | + phoneNum: pn | ||
87 | + }; | ||
93 | 88 | ||
89 | + $.extend(params, result); | ||
94 | $.ajax({ | 90 | $.ajax({ |
95 | url: '/passport/reg/verifymobile', | 91 | url: '/passport/reg/verifymobile', |
96 | type: 'POST', | 92 | type: 'POST', |
97 | - data: { | ||
98 | - areaCode: areaCode.replace('+', ''), | ||
99 | - phoneNum: pn, | ||
100 | - captcha: captcha, | ||
101 | - yohobuy: $('#yohobuy').val() | ||
102 | - }, | 93 | + data: params, |
103 | success: function(data) { | 94 | success: function(data) { |
95 | + validate.type === 2 && validate.refresh(); | ||
104 | if (data.code === 200) { | 96 | if (data.code === 200) { |
105 | location.href = data.data; | 97 | location.href = data.data; |
106 | } else { | 98 | } else { |
107 | - data.changeCaptcha && imgCheck.refresh(); | 99 | + (data.changeCaptcha && validate.type !== 2) && validate.refresh(); |
108 | 100 | ||
109 | showErrTip(data.message); | 101 | showErrTip(data.message); |
110 | requested = false; | 102 | requested = false; |
@@ -112,10 +104,12 @@ $btnNext.on('touchstart', function() { | @@ -112,10 +104,12 @@ $btnNext.on('touchstart', function() { | ||
112 | }, | 104 | }, |
113 | error: function() { | 105 | error: function() { |
114 | showErrTip('出错了,请重试'); | 106 | showErrTip('出错了,请重试'); |
115 | - imgCheck.refresh(); | 107 | + validate.refresh(); |
116 | requested = false; | 108 | requested = false; |
117 | } | 109 | } |
118 | }); | 110 | }); |
111 | + }); | ||
112 | + | ||
119 | } else { | 113 | } else { |
120 | showErrTip('手机号格式不正确,请重新输入'); | 114 | showErrTip('手机号格式不正确,请重新输入'); |
121 | } | 115 | } |
@@ -6,8 +6,6 @@ var $countrySelect, | @@ -6,8 +6,6 @@ var $countrySelect, | ||
6 | $areaCode, | 6 | $areaCode, |
7 | $nextBtn, | 7 | $nextBtn, |
8 | $resetBtn, | 8 | $resetBtn, |
9 | - $captcha, | ||
10 | - $captchaPNG, | ||
11 | $phoneNum, | 9 | $phoneNum, |
12 | $mask = $('#retrive-pwd-mask'), | 10 | $mask = $('#retrive-pwd-mask'), |
13 | $ways = $('#retrive-pwd-ways'); | 11 | $ways = $('#retrive-pwd-ways'); |
@@ -21,16 +19,16 @@ checkPoint = require('./smslogin/check-point'); | @@ -21,16 +19,16 @@ checkPoint = require('./smslogin/check-point'); | ||
21 | 19 | ||
22 | 20 | ||
23 | // 图片验证码 | 21 | // 图片验证码 |
24 | -let ImgCheck = require('plugin/img-check'); | 22 | +let Validate = require('plugin/validata'); |
25 | 23 | ||
26 | -let imgCheck = new ImgCheck('#js-img-check', { | 24 | +let validate = new Validate('#js-img-check', { |
27 | useREM: { | 25 | useREM: { |
28 | rootFontSize: 40, | 26 | rootFontSize: 40, |
29 | picWidth: 150 | 27 | picWidth: 150 |
30 | } | 28 | } |
31 | }); | 29 | }); |
32 | 30 | ||
33 | -imgCheck.init(); | 31 | +validate.init(); |
34 | 32 | ||
35 | require('./login/qr-check'); | 33 | require('./login/qr-check'); |
36 | 34 | ||
@@ -90,6 +88,7 @@ page = { | @@ -90,6 +88,7 @@ page = { | ||
90 | $mask.hide(); | 88 | $mask.hide(); |
91 | $ways.hide(); | 89 | $ways.hide(); |
92 | }, | 90 | }, |
91 | + | ||
93 | // 切换$nextBtn disable状态 | 92 | // 切换$nextBtn disable状态 |
94 | toggleNextBtn: function() { | 93 | toggleNextBtn: function() { |
95 | var bool = Boolean($.trim($phoneNum.val())); | 94 | var bool = Boolean($.trim($phoneNum.val())); |
@@ -105,7 +104,6 @@ page = { | @@ -105,7 +104,6 @@ page = { | ||
105 | goNext: function() { | 104 | goNext: function() { |
106 | var areaCode = $countrySelect.val(); | 105 | var areaCode = $countrySelect.val(); |
107 | var phone = $.trim($phoneNum.val()); | 106 | var phone = $.trim($phoneNum.val()); |
108 | - var captcha = $.trim(imgCheck.getResults()); | ||
109 | 107 | ||
110 | if ($nextBtn.prop('disabled')) { | 108 | if ($nextBtn.prop('disabled')) { |
111 | return; | 109 | return; |
@@ -116,35 +114,33 @@ page = { | @@ -116,35 +114,33 @@ page = { | ||
116 | return; | 114 | return; |
117 | } | 115 | } |
118 | 116 | ||
119 | - // if (captcha === '0000') { | ||
120 | - // tip.show('请将图片旋转到正确方向'); | ||
121 | - // return; | ||
122 | - // } | ||
123 | - | 117 | + validate.getResults().then((result) => { |
124 | $nextBtn.prop('disabled', true); | 118 | $nextBtn.prop('disabled', true); |
125 | - $.post('/passport/sms_login/step1_check', { | 119 | + let params = { |
126 | area: areaCode.replace('+', ''), | 120 | area: areaCode.replace('+', ''), |
127 | - mobile: phone, | ||
128 | - captcode: captcha, | ||
129 | - yohobuy: $('#yohobuy').val() | ||
130 | - }) | ||
131 | - .done(function(data) { | 121 | + mobile: phone |
122 | + }; | ||
123 | + | ||
124 | + $.extend(params, result); | ||
125 | + $.post('/passport/sms_login/step1_check', params).done(function(data) { | ||
126 | + validate.type === 2 && validate.refresh(); | ||
132 | if (data.code === 200) { | 127 | if (data.code === 200) { |
133 | checkPoint('YB_MOBILE_NEXT_C'); // 埋点 | 128 | checkPoint('YB_MOBILE_NEXT_C'); // 埋点 |
134 | // $nextBtn.off(); | 129 | // $nextBtn.off(); |
135 | location.href = data.redirect; | 130 | location.href = data.redirect; |
136 | } else { | 131 | } else { |
137 | - data.changeCaptcha && imgCheck.refresh(); | 132 | + (data.changeCaptcha && validate.type !== 2) && validate.refresh(); |
138 | tip.show(data.message); | 133 | tip.show(data.message); |
139 | } | 134 | } |
140 | }) | 135 | }) |
141 | .fail(function() { | 136 | .fail(function() { |
142 | - imgCheck.refresh(); | 137 | + validate.refresh(); |
143 | tip.show('出错了, 请重试'); | 138 | tip.show('出错了, 请重试'); |
144 | }) | 139 | }) |
145 | .always(function() { | 140 | .always(function() { |
146 | $nextBtn.prop('disabled', false); | 141 | $nextBtn.prop('disabled', false); |
147 | }); | 142 | }); |
143 | + }); | ||
148 | } | 144 | } |
149 | }; | 145 | }; |
150 | 146 |
@@ -4,7 +4,8 @@ | @@ -4,7 +4,8 @@ | ||
4 | * @date: 2017/03/13 | 4 | * @date: 2017/03/13 |
5 | */ | 5 | */ |
6 | let $ = require('yoho-jquery'), | 6 | let $ = require('yoho-jquery'), |
7 | - ImgCheck = require('plugin/img-check'); | 7 | + ImgCheck = require('plugin/img-check'), |
8 | + tip = require('plugin/tip'); | ||
8 | const validType = { | 9 | const validType = { |
9 | IMG_CHECK: 1, | 10 | IMG_CHECK: 1, |
10 | GEETEST: 2 | 11 | GEETEST: 2 |
@@ -19,9 +20,10 @@ const validType = { | @@ -19,9 +20,10 @@ const validType = { | ||
19 | 20 | ||
20 | class Validate { | 21 | class Validate { |
21 | constructor(container, options) { | 22 | constructor(container, options) { |
22 | - this.$container = container; | 23 | + this.$container = container instanceof $ ? container : $(container); |
23 | this.options = options; | 24 | this.options = options; |
24 | - this.type = container.data('geetest') ? validType.GEETEST : validType.IMG_CHECK; | 25 | + this.type = this.$container.data('geetest') ? validType.GEETEST : validType.IMG_CHECK; |
26 | + this.$container.after('<input id="yohobuy" type="text" style="display:none;">'); | ||
25 | if (this.type === validType.IMG_CHECK) { | 27 | if (this.type === validType.IMG_CHECK) { |
26 | this.imgCheck = new ImgCheck(this.$container, this.options); | 28 | this.imgCheck = new ImgCheck(this.$container, this.options); |
27 | } else { | 29 | } else { |
@@ -36,10 +38,9 @@ class Validate { | @@ -36,10 +38,9 @@ class Validate { | ||
36 | offline: !data.success | 38 | offline: !data.success |
37 | }, (captchaObj) => { | 39 | }, (captchaObj) => { |
38 | this.captchaObj = captchaObj; | 40 | this.captchaObj = captchaObj; |
39 | - captchaObj.appendTo($('#js-img-check')); | ||
40 | - $('#js-img-check').after('<input id="yohobuy" type="text" style="display:none;">'); | 41 | + captchaObj.appendTo(this.$container); |
41 | this._atWorking = true; | 42 | this._atWorking = true; |
42 | - $('#js-img-check').addClass('hide').addClass('popup'); | 43 | + this.$container.addClass('hide').addClass('popup'); |
43 | }); | 44 | }); |
44 | } | 45 | } |
45 | }); | 46 | }); |
@@ -47,7 +48,7 @@ class Validate { | @@ -47,7 +48,7 @@ class Validate { | ||
47 | if ($(e.target).attr('id') !== 'js-img-check') { | 48 | if ($(e.target).attr('id') !== 'js-img-check') { |
48 | return; | 49 | return; |
49 | } | 50 | } |
50 | - $('#js-img-check').addClass('hide'); | 51 | + this.$container.addClass('hide'); |
51 | }); | 52 | }); |
52 | } | 53 | } |
53 | } | 54 | } |
@@ -63,24 +64,29 @@ class Validate { | @@ -63,24 +64,29 @@ class Validate { | ||
63 | } | 64 | } |
64 | init() { | 65 | init() { |
65 | if (this.type === validType.IMG_CHECK) { | 66 | if (this.type === validType.IMG_CHECK) { |
66 | - if (this.$container.data('init') != null) { //eslint-disable-line | ||
67 | this.imgCheck.init(); | 67 | this.imgCheck.init(); |
68 | this._atWorking = this.imgCheck.atWorking; | 68 | this._atWorking = this.imgCheck.atWorking; |
69 | } | 69 | } |
70 | } | 70 | } |
71 | - } | ||
72 | getResults() { | 71 | getResults() { |
73 | - if (this.type === validType.IMG_CHECK) { | ||
74 | - return this.imgCheck.getResults(); | ||
75 | - } else { | ||
76 | - if ($('#yohobuy').val()) { | ||
77 | - return ''; | 72 | + let yohobuy = $('#yohobuy').val(); |
73 | + | ||
74 | + if (yohobuy) { | ||
75 | + return Promise.resolve({yohobuy}); | ||
76 | + } else if (this.type === validType.IMG_CHECK) { | ||
77 | + let captcha = this.imgCheck.getResults(); | ||
78 | + | ||
79 | + if (captcha === '0000') { | ||
80 | + tip.show(' 请将图片旋转到正确方向'); | ||
81 | + return Promise.reject(); | ||
78 | } | 82 | } |
83 | + return Promise.resolve({captcha}); | ||
84 | + } else { | ||
79 | return new Promise((resolve) => { | 85 | return new Promise((resolve) => { |
80 | - $('#js-img-check').removeClass('hide'); | 86 | + this.$container.removeClass('hide'); |
81 | this.captchaObj.onSuccess(() => { | 87 | this.captchaObj.onSuccess(() => { |
82 | resolve(this.captchaObj.getValidate()); | 88 | resolve(this.captchaObj.getValidate()); |
83 | - $('#js-img-check').addClass('hide'); | 89 | + this.$container.addClass('hide'); |
84 | }); | 90 | }); |
85 | }); | 91 | }); |
86 | } | 92 | } |
-
Please register or login to post a comment