Showing
21 changed files
with
394 additions
and
155 deletions
@@ -142,6 +142,7 @@ const indexMobilePage = (req, res, next) => { | @@ -142,6 +142,7 @@ const indexMobilePage = (req, res, next) => { | ||
142 | service.getAreaDataAsync() | 142 | service.getAreaDataAsync() |
143 | .then(result => { | 143 | .then(result => { |
144 | res.render('back/mobile', Object.assign({ | 144 | res.render('back/mobile', Object.assign({ |
145 | + width750: true, | ||
145 | module: 'passport', | 146 | module: 'passport', |
146 | page: 'back-mobile', | 147 | page: 'back-mobile', |
147 | title: '找回密码-通过手机号' | 148 | title: '找回密码-通过手机号' |
@@ -217,11 +218,13 @@ const sendCodeToMobileAPI = (req, res, next) => { | @@ -217,11 +218,13 @@ const sendCodeToMobileAPI = (req, res, next) => { | ||
217 | } | 218 | } |
218 | req.session.backupCaptch.useTime = req.session.backupCaptch.useTime - 1; | 219 | req.session.backupCaptch.useTime = req.session.backupCaptch.useTime - 1; |
219 | } else { | 220 | } else { |
220 | - req.session.backupCaptch.useTime = 5; | 221 | + _.set(req.session, 'backupCaptch.useTime', 5); |
221 | } | 222 | } |
222 | 223 | ||
223 | if (verifyCode) { | 224 | if (verifyCode) { |
224 | - if (verifyCode.toString() === _.get(req, 'session.backupCaptch.code', '').toString()) { | 225 | + let captcha = _.get(req, 'session.captcha'); |
226 | + | ||
227 | + if (captcha && verifyCode.toString() === captcha) { | ||
225 | req.session.backupCaptch.verifyResult = true; | 228 | req.session.backupCaptch.verifyResult = true; |
226 | } else { | 229 | } else { |
227 | return res.json({ | 230 | return res.json({ |
@@ -5,7 +5,7 @@ | @@ -5,7 +5,7 @@ | ||
5 | * @date: 2016/05/09 | 5 | * @date: 2016/05/09 |
6 | */ | 6 | */ |
7 | 'use strict'; | 7 | 'use strict'; |
8 | - | 8 | +const _ = require('lodash'); |
9 | const passport = require('passport'); | 9 | const passport = require('passport'); |
10 | 10 | ||
11 | // const md5 = require('md5'); | 11 | // const md5 = require('md5'); |
@@ -78,6 +78,7 @@ const common = { | @@ -78,6 +78,7 @@ const common = { | ||
78 | } | 78 | } |
79 | }; | 79 | }; |
80 | 80 | ||
81 | + | ||
81 | const local = { | 82 | const local = { |
82 | loginPage: (req, res) => { | 83 | loginPage: (req, res) => { |
83 | // 先清除cookie | 84 | // 先清除cookie |
@@ -97,7 +98,9 @@ const local = { | @@ -97,7 +98,9 @@ const local = { | ||
97 | }); | 98 | }); |
98 | 99 | ||
99 | res.render('login', { | 100 | res.render('login', { |
101 | + width750: true, | ||
100 | loginIndex: true, // 模板中使用JS的标识 | 102 | loginIndex: true, // 模板中使用JS的标识 |
103 | + captchaShow: _.get(req.session, 'login.errorCount') <= 0, | ||
101 | 104 | ||
102 | // 返回的URL链接 | 105 | // 返回的URL链接 |
103 | backUrl: 'javascript:history.go(-1)', // eslint-disable-line | 106 | backUrl: 'javascript:history.go(-1)', // eslint-disable-line |
@@ -135,9 +138,11 @@ const local = { | @@ -135,9 +138,11 @@ const local = { | ||
135 | }); | 138 | }); |
136 | 139 | ||
137 | res.render('international', { | 140 | res.render('international', { |
141 | + width750: true, | ||
138 | // 返回的URL链接 | 142 | // 返回的URL链接 |
139 | backUrl: 'javascript:history.go(-1)', // eslint-disable-line | 143 | backUrl: 'javascript:history.go(-1)', // eslint-disable-line |
140 | loginInternational: true, // 模板中使用JS的标识 | 144 | loginInternational: true, // 模板中使用JS的标识 |
145 | + captchaShow: _.get(req.session, 'login.errorCount') <= 0, | ||
141 | isPassportPage: true, // 模板中模块标识 | 146 | isPassportPage: true, // 模板中模块标识 |
142 | headerText: '登录', | 147 | headerText: '登录', |
143 | areaCode: '+86', // 默认区号 | 148 | areaCode: '+86', // 默认区号 |
@@ -148,13 +153,44 @@ const local = { | @@ -148,13 +153,44 @@ const local = { | ||
148 | }); | 153 | }); |
149 | }, | 154 | }, |
150 | login: (req, res, next) => { | 155 | login: (req, res, next) => { |
156 | + let count = _.get(req.session, 'login.errorCount'); | ||
157 | + | ||
158 | + if (count == null) { // eslint-disable-line | ||
159 | + _.set(req.session, 'login.errorCount', 3); | ||
160 | + } else if (count <= 0) { | ||
161 | + let captchaInput = req.body.captcha; | ||
162 | + let captchaCode = _.get(req.session, 'captcha'); | ||
163 | + | ||
164 | + delete req.session.captcha; // 用过就丢弃 | ||
165 | + | ||
166 | + if (!captchaInput || !captchaCode || captchaInput !== captchaCode) { | ||
167 | + res.json({ | ||
168 | + code: 400, | ||
169 | + message: '请将图片旋转到正确方向', | ||
170 | + captchaShow: true | ||
171 | + }); | ||
172 | + | ||
173 | + return; | ||
174 | + } | ||
175 | + } | ||
176 | + | ||
151 | passport.authenticate('local', (err, user) => { | 177 | passport.authenticate('local', (err, user) => { |
178 | + let loginSession = req.session.login; | ||
179 | + | ||
152 | if (err) { | 180 | if (err) { |
153 | - res.json({ | 181 | + let obj = { |
154 | code: 400, | 182 | code: 400, |
155 | message: err, | 183 | message: err, |
156 | data: '' | 184 | data: '' |
157 | - }); | 185 | + }; |
186 | + | ||
187 | + --loginSession.errorCount; | ||
188 | + | ||
189 | + if (loginSession.errorCount <= 0) { | ||
190 | + obj.captchaShow = true; | ||
191 | + } | ||
192 | + | ||
193 | + res.json(obj); | ||
158 | } else { | 194 | } else { |
159 | let refer = req.cookies.refer; | 195 | let refer = req.cookies.refer; |
160 | 196 |
@@ -8,6 +8,7 @@ | @@ -8,6 +8,7 @@ | ||
8 | 'use strict'; | 8 | 'use strict'; |
9 | 9 | ||
10 | const _ = require('lodash'); | 10 | const _ = require('lodash'); |
11 | +const url = require('url'); | ||
11 | const utils = require(global.utils); | 12 | const utils = require(global.utils); |
12 | const helpers = global.yoho.helpers; | 13 | const helpers = global.yoho.helpers; |
13 | const sign = global.yoho.sign; | 14 | const sign = global.yoho.sign; |
@@ -26,6 +27,7 @@ const captchaService = require('../models/captcha-service'); | @@ -26,6 +27,7 @@ const captchaService = require('../models/captcha-service'); | ||
26 | } | 27 | } |
27 | */ | 28 | */ |
28 | 29 | ||
30 | + | ||
29 | /** | 31 | /** |
30 | * 步骤校验 | 32 | * 步骤校验 |
31 | * step: 预期步骤 | 33 | * step: 预期步骤 |
@@ -58,6 +60,17 @@ let index = (req, res) => { | @@ -58,6 +60,17 @@ let index = (req, res) => { | ||
58 | return res.redirect(req.get('refer') || '/'); | 60 | return res.redirect(req.get('refer') || '/'); |
59 | } | 61 | } |
60 | 62 | ||
63 | + // 判断是否 来自 个人中心 | ||
64 | + if (!_.get(req.session, 'phoneReg.isFromMy')) { | ||
65 | + let referer = req.get('Referer') || ''; | ||
66 | + let urlObj = url.parse(referer, true, true); | ||
67 | + | ||
68 | + referer = _.get(urlObj, 'query.refer', ''); | ||
69 | + | ||
70 | + urlObj = url.parse(referer, true, true); | ||
71 | + urlObj.path === '/home' && _.set(req.session, 'phoneReg.isFromMy', '1'); | ||
72 | + } | ||
73 | + | ||
61 | // 设置注册有效时间30分钟, 防机器刷 | 74 | // 设置注册有效时间30分钟, 防机器刷 |
62 | // req.session.REG_EXPIRE = Date.now() + 1800000; | 75 | // req.session.REG_EXPIRE = Date.now() + 1800000; |
63 | let refer = req.query.refer; | 76 | let refer = req.query.refer; |
@@ -76,6 +89,7 @@ let index = (req, res) => { | @@ -76,6 +89,7 @@ let index = (req, res) => { | ||
76 | } | 89 | } |
77 | 90 | ||
78 | res.render('reg/index', { | 91 | res.render('reg/index', { |
92 | + width750: true, | ||
79 | module: 'passport', | 93 | module: 'passport', |
80 | page: 'reg', | 94 | page: 'reg', |
81 | title: '注册', | 95 | title: '注册', |
@@ -99,7 +113,7 @@ let verifyMobile = (req, res, next) => { | @@ -99,7 +113,7 @@ let verifyMobile = (req, res, next) => { | ||
99 | let mobile = +req.body.phoneNum; | 113 | let mobile = +req.body.phoneNum; |
100 | let area = +(req.body.areaCode || 86); | 114 | let area = +(req.body.areaCode || 86); |
101 | let captcha = (req.body.captcha || '').trim(); | 115 | let captcha = (req.body.captcha || '').trim(); |
102 | - let diffCaptcha = _.get(req.session, 'phoneReg.captcha'); | 116 | + let diffCaptcha = _.get(req.session, 'captcha'); |
103 | 117 | ||
104 | // error case: 没有验证码 | 118 | // error case: 没有验证码 |
105 | if (!diffCaptcha) { | 119 | if (!diffCaptcha) { |
@@ -110,7 +124,7 @@ let verifyMobile = (req, res, next) => { | @@ -110,7 +124,7 @@ let verifyMobile = (req, res, next) => { | ||
110 | }); | 124 | }); |
111 | } | 125 | } |
112 | 126 | ||
113 | - delete req.session.phoneReg.captcha; // captcha 一次性 | 127 | + delete req.session.captcha; // captcha 一次性 |
114 | 128 | ||
115 | // error case: 验证码不匹配 | 129 | // error case: 验证码不匹配 |
116 | if (captcha !== diffCaptcha) { | 130 | if (captcha !== diffCaptcha) { |
@@ -185,7 +199,6 @@ let codeAction = (req, res, next) => { | @@ -185,7 +199,6 @@ let codeAction = (req, res, next) => { | ||
185 | res.render('reg/code', { | 199 | res.render('reg/code', { |
186 | page: 'code', | 200 | page: 'code', |
187 | title: '注册-验证码', | 201 | title: '注册-验证码', |
188 | - backUrl: '/?go=1', // eslint-disable-line | ||
189 | headerText: '注册', // 头部信息 | 202 | headerText: '注册', // 头部信息 |
190 | isPassportPage: true, // 模板中模块标识 | 203 | isPassportPage: true, // 模板中模块标识 |
191 | areaCode: area, // 默认的区号 | 204 | areaCode: area, // 默认的区号 |
@@ -361,6 +374,7 @@ let setPassword = (req, res, next) => { | @@ -361,6 +374,7 @@ let setPassword = (req, res, next) => { | ||
361 | let password = req.body.password; | 374 | let password = req.body.password; |
362 | let token = req.body.token; | 375 | let token = req.body.token; |
363 | let smsCode = +req.body.smsCode; | 376 | let smsCode = +req.body.smsCode; |
377 | + let isFromMy = _.get(req.session, 'phoneReg.isFromMy', '0'); | ||
364 | 378 | ||
365 | // 判断参数是否合法 | 379 | // 判断参数是否合法 |
366 | if (!smsCode || !_.isString(token) || !_.isNumber(mobile) || !_.isNumber(area) || !password) { | 380 | if (!smsCode || !_.isString(token) || !_.isNumber(mobile) || !_.isNumber(area) || !password) { |
@@ -383,29 +397,40 @@ let setPassword = (req, res, next) => { | @@ -383,29 +397,40 @@ let setPassword = (req, res, next) => { | ||
383 | let shoppingKey = cookie.getShoppingKey(req); | 397 | let shoppingKey = cookie.getShoppingKey(req); |
384 | 398 | ||
385 | // 验证注册的标识码是否有效 | 399 | // 验证注册的标识码是否有效 |
386 | - RegService.regMobileAes(area, mobile, password, shoppingKey, smsCode).then((result) => { | 400 | + let resultCopy = null; |
401 | + | ||
402 | + RegService.regMobileAes(area, mobile, password, shoppingKey, smsCode, isFromMy).then((result) => { | ||
387 | if (!result.code || result.code !== 200) { | 403 | if (!result.code || result.code !== 200) { |
388 | return Promise.reject(result); | 404 | return Promise.reject(result); |
389 | } | 405 | } |
390 | if (!result.data || !result.data.uid) { | 406 | if (!result.data || !result.data.uid) { |
391 | return Promise.reject(result); | 407 | return Promise.reject(result); |
392 | } | 408 | } |
409 | + | ||
410 | + resultCopy = result; | ||
411 | + | ||
393 | return AuthHelper.syncUserSession(result.data.uid, req, res); | 412 | return AuthHelper.syncUserSession(result.data.uid, req, res); |
394 | }).then(() => { | 413 | }).then(() => { |
395 | // 返回跳转到来源页面 | 414 | // 返回跳转到来源页面 |
396 | let refer = req.cookies.refer; | 415 | let refer = req.cookies.refer; |
397 | 416 | ||
398 | - if (refer) { | ||
399 | - refer = decodeURI(req.cookies.refer); | 417 | + // isFromMy to 新人会场 |
418 | + if (resultCopy.data.newUserPage) { | ||
419 | + refer = resultCopy.data.msgDelivery; // 来自个人中心,跳新人会场 | ||
400 | } else { | 420 | } else { |
401 | - refer = '/home'; | ||
402 | - } | 421 | + if (refer) { |
422 | + refer = decodeURI(req.cookies.refer); | ||
423 | + } else { | ||
424 | + refer = '/home'; | ||
425 | + } | ||
426 | + | ||
427 | + if (/sign|login/.test(refer)) { | ||
428 | + refer = '/home'; | ||
429 | + } | ||
403 | 430 | ||
404 | - if (/sign|login/.test(refer)) { | ||
405 | - refer = '/home'; | 431 | + refer = utils.refererLimit(refer); |
406 | } | 432 | } |
407 | 433 | ||
408 | - refer = utils.refererLimit(refer); | ||
409 | 434 | ||
410 | delete req.session.phoneNum; | 435 | delete req.session.phoneNum; |
411 | 436 |
1 | /* eslint no-unused-vars: ["error", { "args": "none" }] */ | 1 | /* eslint no-unused-vars: ["error", { "args": "none" }] */ |
2 | 'use strict'; | 2 | 'use strict'; |
3 | const _ = require('lodash'); | 3 | const _ = require('lodash'); |
4 | +const moment = require('moment'); | ||
4 | const helpers = global.yoho.helpers; | 5 | const helpers = global.yoho.helpers; |
5 | const cookie = global.yoho.cookie; | 6 | const cookie = global.yoho.cookie; |
7 | +const EventEmitter = require('events'); | ||
6 | const utils = require(global.utils); | 8 | const utils = require(global.utils); |
7 | const RegService = require('../models/reg-service'); | 9 | const RegService = require('../models/reg-service'); |
8 | const PhoneService = require('../models/phone-service'); | 10 | const PhoneService = require('../models/phone-service'); |
9 | const AuthHelper = require('../models/auth-helper'); | 11 | const AuthHelper = require('../models/auth-helper'); |
10 | -const captchaService = require('../models/captcha-service'); | ||
11 | 12 | ||
12 | // constrant | 13 | // constrant |
13 | const CODE_REQUIRED = '请输入校验码'; | 14 | const CODE_REQUIRED = '请输入校验码'; |
14 | const PASSWORD_REQUIRED = '请输入密码'; | 15 | const PASSWORD_REQUIRED = '请输入密码'; |
15 | const PASSWORD_LENGTH_ERROR = '密码6-20位,请重新输入'; | 16 | const PASSWORD_LENGTH_ERROR = '密码6-20位,请重新输入'; |
16 | const BAD_PASSWORD = '密码格式不正确'; | 17 | const BAD_PASSWORD = '密码格式不正确'; |
17 | -const TOO_MANY = '请求太频繁'; | ||
18 | const LOGIN_SUCCSS = '登录成功'; | 18 | const LOGIN_SUCCSS = '登录成功'; |
19 | const VERIFY_ERROR = '校验失败'; | 19 | const VERIFY_ERROR = '校验失败'; |
20 | 20 | ||
@@ -44,6 +44,7 @@ const _step1 = (req, res, next) => { | @@ -44,6 +44,7 @@ const _step1 = (req, res, next) => { | ||
44 | 44 | ||
45 | let template = 'sms/login'; | 45 | let template = 'sms/login'; |
46 | let viewData = { | 46 | let viewData = { |
47 | + width750: true, | ||
47 | module: 'passport', | 48 | module: 'passport', |
48 | page: 'sms-login', | 49 | page: 'sms-login', |
49 | title: '手机短信登录', | 50 | title: '手机短信登录', |
@@ -55,6 +56,8 @@ const _step1 = (req, res, next) => { | @@ -55,6 +56,8 @@ const _step1 = (req, res, next) => { | ||
55 | }; | 56 | }; |
56 | 57 | ||
57 | res.render(template, viewData); | 58 | res.render(template, viewData); |
59 | + | ||
60 | + | ||
58 | }; | 61 | }; |
59 | 62 | ||
60 | // 短信登录 第二步: 输入 校验码 | 63 | // 短信登录 第二步: 输入 校验码 |
@@ -118,44 +121,75 @@ exports.loginPage = (req, res, next) => { | @@ -118,44 +121,75 @@ exports.loginPage = (req, res, next) => { | ||
118 | } | 121 | } |
119 | }; | 122 | }; |
120 | 123 | ||
121 | -exports.tokenBefore = (req, res, next) => { | ||
122 | - let area = req.query.area = (req.query.area || '').trim(); | ||
123 | - let mobile = req.query.mobile = (req.query.mobile || '').trim(); | ||
124 | - let step = _.get(req.session, 'smsLogin.step'); | ||
125 | - let count = _.get(req.session, 'smsLogin.count'); | ||
126 | - let interval = _.get(req.session, 'smsLogin.interval'); | ||
127 | - let captcha1 = _.get(req.session, 'smsLogin.captcha'); | ||
128 | - let captcha2 = (req.query.captcha || '').trim(); | ||
129 | 124 | ||
125 | +/** | ||
126 | + * step1 的表单提交验证 | ||
127 | + */ | ||
128 | +exports.indexCheck = (req, res, next) => { | ||
129 | + _.set(req.session, 'smsLogin.step', 1); | ||
130 | 130 | ||
131 | - if (!req.xhr) { | ||
132 | - return next(404); | ||
133 | - } | 131 | + let area = req.body.area = (req.body.area || '').trim(); |
132 | + let mobile = req.body.mobile = (req.body.mobile || '').trim(); | ||
133 | + let captcode = (req.body.captcode || '').trim(); | ||
134 | + let captcodeValid = _.get(req.session, 'captcha'); | ||
134 | 135 | ||
135 | - if ([area, mobile].some(val => val === '')) { | ||
136 | - return res.json({ | ||
137 | - code: 401, | ||
138 | - message: '手机号 必填' | 136 | + let em = new EventEmitter(); |
137 | + | ||
138 | + // 校验 成功 | ||
139 | + em.on('resolve', () => { | ||
140 | + // 1. 将信息放入 session | ||
141 | + _.set(req.session, 'smsLogin.area', area); | ||
142 | + _.set(req.session, 'smsLogin.mobile', mobile); | ||
143 | + _.set(req.session, 'smsLogin.step', 2); | ||
144 | + | ||
145 | + PhoneService.sendSMS(mobile, area, 1); | ||
146 | + | ||
147 | + --req.session.smsLogin.count; | ||
148 | + | ||
149 | + if (!req.session.smsLogin.count) { | ||
150 | + _.set(req.session, 'smsLogin.interval', Date.now() + 5 * 60 * 1000); | ||
151 | + } else { | ||
152 | + _.set(req.session, 'smsLogin.interval', Date.now() + 60 * 1000); | ||
153 | + } | ||
154 | + | ||
155 | + res.json({ | ||
156 | + code: 200, | ||
157 | + redirect: '/passport/sms_login?step=2' | ||
139 | }); | 158 | }); |
159 | + }); | ||
160 | + | ||
161 | + // 校验 失败 | ||
162 | + em.on('reject', error => { | ||
163 | + _.set(req.session, 'smsLogin.step', 1); | ||
164 | + | ||
165 | + res.json(error); | ||
166 | + }); | ||
167 | + | ||
168 | + | ||
169 | + req.session.captcha = void 0; // 验证码 用过就扔 | ||
170 | + | ||
171 | + // 验证 | ||
172 | + if ([area, mobile].some(val => val === '')) { | ||
173 | + return em.emit('reject', {code: 400, message: '请填写手机号'}); | ||
174 | + } else if (!captcode) { | ||
175 | + return em.emit('reject', {code: 400, message: '请填写验证码'}); | ||
176 | + } else if (captcode !== captcodeValid) { | ||
177 | + return em.emit('reject', {code: 400, message: '请将图片旋转到正确位置'}); | ||
140 | } | 178 | } |
141 | 179 | ||
142 | - delete req.session.smsLogin.captcha; // 图形验证码 一次性 | 180 | + // congratulation~~ |
181 | + em.emit('resolve'); | ||
182 | +}; | ||
143 | 183 | ||
144 | - // step1 要 校验图形验证码 | ||
145 | - if (step === 1) { | ||
146 | - if (!captcha2) { | ||
147 | - return res.json({ | ||
148 | - code: 400, | ||
149 | - message: '请填写验证码' | ||
150 | - }); | ||
151 | - } | 184 | +exports.tokenBefore = (req, res, next) => { |
152 | 185 | ||
153 | - if (captcha1 !== captcha2) { | ||
154 | - return res.json({ | ||
155 | - code: 400, | ||
156 | - message: VERIFY_ERROR | ||
157 | - }); | ||
158 | - } | 186 | + let step = _.get(req.session, 'smsLogin.step'); |
187 | + let count = _.get(req.session, 'smsLogin.count'); | ||
188 | + let interval = _.get(req.session, 'smsLogin.interval'); | ||
189 | + | ||
190 | + | ||
191 | + if (!req.xhr || step !== 2) { | ||
192 | + return next(404); | ||
159 | } | 193 | } |
160 | 194 | ||
161 | let now = Date.now(); | 195 | let now = Date.now(); |
@@ -164,11 +198,14 @@ exports.tokenBefore = (req, res, next) => { | @@ -164,11 +198,14 @@ exports.tokenBefore = (req, res, next) => { | ||
164 | // 1. 过了冻结期, count 重设为 5次 | 198 | // 1. 过了冻结期, count 重设为 5次 |
165 | // 2. 没过冻结期, end | 199 | // 2. 没过冻结期, end |
166 | // 没有用完, 判断是否请求太频繁 | 200 | // 没有用完, 判断是否请求太频繁 |
201 | + let during = moment.duration(interval - now, 'ms').minutes(); | ||
202 | + let message = `请${during}分钟后再试`; | ||
203 | + | ||
167 | if (!count) { | 204 | if (!count) { |
168 | if (interval > now) { | 205 | if (interval > now) { |
169 | return res.json({ | 206 | return res.json({ |
170 | code: 400, | 207 | code: 400, |
171 | - message: TOO_MANY, | 208 | + message: message, |
172 | during: Math.ceil((interval - now) / 1000) | 209 | during: Math.ceil((interval - now) / 1000) |
173 | }); | 210 | }); |
174 | } else { | 211 | } else { |
@@ -177,17 +214,19 @@ exports.tokenBefore = (req, res, next) => { | @@ -177,17 +214,19 @@ exports.tokenBefore = (req, res, next) => { | ||
177 | } else if (interval > now) { | 214 | } else if (interval > now) { |
178 | return res.json({ | 215 | return res.json({ |
179 | code: 429, | 216 | code: 429, |
180 | - message: TOO_MANY | 217 | + message: message |
181 | }); | 218 | }); |
182 | } | 219 | } |
183 | 220 | ||
184 | next(); | 221 | next(); |
185 | }; | 222 | }; |
186 | 223 | ||
224 | + | ||
225 | + | ||
187 | // AJAX 获取验证码 | 226 | // AJAX 获取验证码 |
188 | exports.token = (req, res, next) => { | 227 | exports.token = (req, res, next) => { |
189 | - let area = req.query.area; | ||
190 | - let mobile = req.query.mobile; | 228 | + let area = _.get(req.session, 'smsLogin.area'); |
229 | + let mobile = _.get(req.session, 'smsLogin.mobile'); | ||
191 | 230 | ||
192 | PhoneService.sendSMS(mobile, area, 1).then(result => { | 231 | PhoneService.sendSMS(mobile, area, 1).then(result => { |
193 | if (result.code === 200) { | 232 | if (result.code === 200) { |
@@ -376,6 +415,7 @@ exports.password = (req, res, next) => { | @@ -376,6 +415,7 @@ exports.password = (req, res, next) => { | ||
376 | /** | 415 | /** |
377 | * 生成 校验码 | 416 | * 生成 校验码 |
378 | */ | 417 | */ |
418 | +/* | ||
379 | exports.genCaptcha = (req, res) => { | 419 | exports.genCaptcha = (req, res) => { |
380 | let captcha = captchaService.generateCaptcha(90, 52, 4); | 420 | let captcha = captchaService.generateCaptcha(90, 52, 4); |
381 | 421 | ||
@@ -386,3 +426,4 @@ exports.genCaptcha = (req, res) => { | @@ -386,3 +426,4 @@ exports.genCaptcha = (req, res) => { | ||
386 | .status(200) | 426 | .status(200) |
387 | .send(captcha.image); | 427 | .send(captcha.image); |
388 | }; | 428 | }; |
429 | +*/ |
apps/passport/data/captcha.json
0 → 100644
This diff could not be displayed because it is too large.
1 | 'use strict'; | 1 | 'use strict'; |
2 | +const _ = require('lodash'); | ||
2 | const aes = require('./aes-pwd'); | 3 | const aes = require('./aes-pwd'); |
3 | const sign = global.yoho.sign; | 4 | const sign = global.yoho.sign; |
4 | const api = global.yoho.API; | 5 | const api = global.yoho.API; |
@@ -87,10 +88,17 @@ class Auth { | @@ -87,10 +88,17 @@ class Auth { | ||
87 | domain: 'yohobuy.com', | 88 | domain: 'yohobuy.com', |
88 | expires: new Date(Date.now() + 2592000000) // 有效期一年 | 89 | expires: new Date(Date.now() + 2592000000) // 有效期一年 |
89 | }); | 90 | }); |
91 | + | ||
92 | + req.session.AVATAR = data.head_ico; | ||
93 | + _.set(req.session, 'USER.AVATAR', data.head_ico); | ||
94 | + _.set(req.session, 'USER.NAME', data.profile_name); | ||
90 | } | 95 | } |
91 | 96 | ||
92 | req.session.TOKEN = publicToken; | 97 | req.session.TOKEN = publicToken; |
93 | req.session.LOGIN_UID = uid; | 98 | req.session.LOGIN_UID = uid; |
99 | + | ||
100 | + _.set(req.session, 'USER.ENCRYPTION_UID', encryptionUid); | ||
101 | + | ||
94 | res.cookie('_TOKEN', publicToken, { | 102 | res.cookie('_TOKEN', publicToken, { |
95 | httpOnly: true, | 103 | httpOnly: true, |
96 | domain: 'yohobuy.com', | 104 | domain: 'yohobuy.com', |
@@ -96,13 +96,16 @@ const RegService = { | @@ -96,13 +96,16 @@ const RegService = { | ||
96 | 96 | ||
97 | return api.post('', params); | 97 | return api.post('', params); |
98 | }, | 98 | }, |
99 | - regMobileAes(area, mobile, password, shoppingKey, smsCode) { | 99 | + regMobileAes(area, mobile, password, shoppingKey, smsCode, isFromMy) { |
100 | + isFromMy = isFromMy || '0'; | ||
101 | + | ||
100 | let params = { | 102 | let params = { |
101 | method: 'app.passport.registerAES', | 103 | method: 'app.passport.registerAES', |
102 | area: area, | 104 | area: area, |
103 | profile: mobile, | 105 | profile: mobile, |
104 | password: aes.aesPwd(password), | 106 | password: aes.aesPwd(password), |
105 | - verifyCode: smsCode | 107 | + verifyCode: smsCode, |
108 | + isFromMy | ||
106 | }; | 109 | }; |
107 | 110 | ||
108 | if (shoppingKey) { | 111 | if (shoppingKey) { |
@@ -41,6 +41,7 @@ router.post('/passport/login/auth', login.local.login); | @@ -41,6 +41,7 @@ router.post('/passport/login/auth', login.local.login); | ||
41 | // SMS 短信 | 41 | // SMS 短信 |
42 | router.use('/passport/sms_login', login.common.beforeLogin, smsLogin.beforeIn); | 42 | router.use('/passport/sms_login', login.common.beforeLogin, smsLogin.beforeIn); |
43 | router.get('/passport/sms_login', smsLogin.loginPage); | 43 | router.get('/passport/sms_login', smsLogin.loginPage); |
44 | +router.post('/passport/sms_login/step1_check', smsLogin.indexCheck); | ||
44 | router.get('/passport/sms_login/token.json', | 45 | router.get('/passport/sms_login/token.json', |
45 | smsLogin.tokenBefore, | 46 | smsLogin.tokenBefore, |
46 | smsLogin.token); // only ajax; | 47 | smsLogin.token); // only ajax; |
@@ -48,7 +49,6 @@ router.get('/passport/sms_login/check.json', | @@ -48,7 +49,6 @@ router.get('/passport/sms_login/check.json', | ||
48 | smsLogin.checkBefore, | 49 | smsLogin.checkBefore, |
49 | smsLogin.check); // only ajax | 50 | smsLogin.check); // only ajax |
50 | router.post('/passport/sms_login/password.json', smsLogin.password); | 51 | router.post('/passport/sms_login/password.json', smsLogin.password); |
51 | -router.get('/passport/sms_login/captcha.png', smsLogin.genCaptcha); | ||
52 | 52 | ||
53 | // 微信登录 | 53 | // 微信登录 |
54 | router.get('/passport/login/wechat', login.common.beforeLogin, login.wechat.login); | 54 | router.get('/passport/login/wechat', login.common.beforeLogin, login.wechat.login); |
@@ -126,4 +126,9 @@ router.get('/passport/newpower', agreement.newpower);// 新力传媒 | @@ -126,4 +126,9 @@ router.get('/passport/newpower', agreement.newpower);// 新力传媒 | ||
126 | router.get('/passport/yohobuy', agreement.aboutYoho);// 关于有货 | 126 | router.get('/passport/yohobuy', agreement.aboutYoho);// 关于有货 |
127 | router.get('/passport/agreement', agreement.agreement);// 服务条款 | 127 | router.get('/passport/agreement', agreement.agreement);// 服务条款 |
128 | 128 | ||
129 | +// 验证码 | ||
130 | +let captcha = require(`${cRoot}/captcha`); | ||
131 | + | ||
132 | +router.get('/passport/captcha/get', captcha.get); | ||
133 | + | ||
129 | module.exports = router; | 134 | module.exports = router; |
@@ -6,12 +6,11 @@ | @@ -6,12 +6,11 @@ | ||
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 | - <div class="passport-captcha row"> | ||
10 | - <div class="passport-captcha-img"><img id="verify-code-img" src="{{verifySrc}}" alt="verify code"></div> | ||
11 | - <div class="passport-captcha-input"> | ||
12 | - <input id="verify-code" type="text" placeholder="验证码"> | ||
13 | - </div> | 9 | + {{!--图片验证 start--}} |
10 | + <div id="js-img-check"> | ||
11 | + <input type="hidden" name="captsrc" value="{{captsrc}}"> | ||
14 | </div> | 12 | </div> |
13 | + {{!--图片验证 end--}} | ||
15 | <span id="btn-next" class="btn btn-next disable row">下一步</span> | 14 | <span id="btn-next" class="btn btn-next disable row">下一步</span> |
16 | </div> | 15 | </div> |
17 | </div> | 16 | </div> |
@@ -9,6 +9,8 @@ | @@ -9,6 +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 id="js-img-check" {{#captchaShow }}data-init{{/captchaShow}}></div> | ||
13 | + | ||
12 | <span id="btn-login" class="btn btn-login disble row">登录</span> | 14 | <span id="btn-login" class="btn btn-login disble row">登录</span> |
13 | </div> | 15 | </div> |
14 | </div> | 16 | </div> |
@@ -8,9 +8,10 @@ | @@ -8,9 +8,10 @@ | ||
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 id="js-img-check" {{#captchaShow }}data-init{{/captchaShow}}></div> | ||
11 | <span id="btn-login" class="btn btn-login disable">登录</span> | 12 | <span id="btn-login" class="btn btn-login disable">登录</span> |
12 | <p class="op-container"> | 13 | <p class="op-container"> |
13 | - {{!--<a class="sms-login" href={{smsLoginUrl}}>手机号码快捷登录</a>--}} | 14 | + <a class="sms-login" href={{smsLoginUrl}}>手机号码快捷登录</a> |
14 | <span id="forget-pwd" class="forget-pwd">忘记密码</span> | 15 | <span id="forget-pwd" class="forget-pwd">忘记密码</span> |
15 | </p> | 16 | </p> |
16 | <div class="third-party-login"> | 17 | <div class="third-party-login"> |
@@ -43,4 +44,4 @@ | @@ -43,4 +44,4 @@ | ||
43 | </li> | 44 | </li> |
44 | </ul> | 45 | </ul> |
45 | </div> | 46 | </div> |
46 | -</div> | ||
47 | +</div> |
@@ -6,16 +6,13 @@ | @@ -6,16 +6,13 @@ | ||
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 class="passport-captcha row"> | ||
11 | - <div class="passport-captcha-img"> | ||
12 | - <img class="passport-captcha-png" src="{{captchaUrl}}"> | ||
13 | - </div> | ||
14 | - <div class="passport-captcha-input"> | ||
15 | - <input id="js-captcha" type="text" placeholder="验证码"> | ||
16 | - </div> | 9 | + |
10 | + {{!--图片验证 start--}} | ||
11 | + <div id="js-img-check"> | ||
12 | + <input type="hidden" name="captsrc" value="{{captsrc}}"> | ||
17 | </div> | 13 | </div> |
18 | - <!-- 验证码: end--> | 14 | + {{!--图片验证 end--}} |
15 | + | ||
19 | <span id="btn-next" class="btn btn-next disable row">下一步</span> | 16 | <span id="btn-next" class="btn btn-next disable row">下一步</span> |
20 | <p class="register-tip">Yoho!Family账号可登录Yoho!Buy有货、Yoho!Now、mars及SHOW</p> | 17 | <p class="register-tip">Yoho!Family账号可登录Yoho!Buy有货、Yoho!Now、mars及SHOW</p> |
21 | </div> | 18 | </div> |
@@ -7,12 +7,11 @@ | @@ -7,12 +7,11 @@ | ||
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 | - <div class="passport-captcha row"> | ||
11 | - <div class="passport-captcha-img"><img src="{{captchaUrl}}" alt=""></div> | ||
12 | - <div class="passport-captcha-input"> | ||
13 | - <input id="js-captcha" type="text" placeholder="验证码"> | ||
14 | - </div> | 10 | + {{!--图片验证 start--}} |
11 | + <div id="js-img-check"> | ||
12 | + <input type="hidden" name="captsrc" value="{{captsrc}}"> | ||
15 | </div> | 13 | </div> |
14 | + {{!--图片验证 end--}} | ||
16 | <button id="btn-next" class="btn btn-next disable row" disabled>获取短信验证码</button> | 15 | <button id="btn-next" class="btn btn-next disable row" disabled>获取短信验证码</button> |
17 | </div> | 16 | </div> |
18 | </div> | 17 | </div> |
1 | 'use strict'; | 1 | 'use strict'; |
2 | +const _ = require('lodash'); | ||
3 | +let captchaData = require('../passport/data/captcha.json'); | ||
2 | 4 | ||
3 | -let api = global.yoho.API; | ||
4 | - | 5 | +// let api = global.yoho.API; |
5 | /** | 6 | /** |
6 | * 获取图形旋转验证码 | 7 | * 获取图形旋转验证码 |
7 | * @return Promise | 8 | * @return Promise |
@@ -24,9 +25,16 @@ let api = global.yoho.API; | @@ -24,9 +25,16 @@ let api = global.yoho.API; | ||
24 | *} | 25 | *} |
25 | */ | 26 | */ |
26 | exports.gen = () => { | 27 | exports.gen = () => { |
27 | - let params = { | ||
28 | - method: 'web.register.getVerifiedGraphicCode' | ||
29 | - }; | 28 | + // let params = { |
29 | + // method: 'web.register.getVerifiedGraphicCode' | ||
30 | + // }; | ||
31 | + | ||
32 | + // return api.get('', params); | ||
33 | + | ||
34 | + let random = _.random(0, captchaData.length); | ||
30 | 35 | ||
31 | - return api.get('', params); | 36 | + return Promise.resolve({ |
37 | + code: 200, | ||
38 | + data: captchaData[random] | ||
39 | + }) | ||
32 | }; | 40 | }; |
@@ -19,6 +19,18 @@ var tip = require('../../plugin/tip'); | @@ -19,6 +19,18 @@ var tip = require('../../plugin/tip'); | ||
19 | var trim = $.trim; | 19 | var trim = $.trim; |
20 | var showErrTip = tip.show; | 20 | var showErrTip = tip.show; |
21 | 21 | ||
22 | +// 图片验证码 | ||
23 | +let ImgCheck = require('plugin/img-check'); | ||
24 | + | ||
25 | +let imgCheck = new ImgCheck('#js-img-check', { | ||
26 | + useREM: { | ||
27 | + rootFontSize: 40, | ||
28 | + picWidth: 150 | ||
29 | + } | ||
30 | +}); | ||
31 | + | ||
32 | +imgCheck.init(); | ||
33 | + | ||
22 | api.selectCssHack($('#country-select')); | 34 | api.selectCssHack($('#country-select')); |
23 | 35 | ||
24 | api.bindClearEvt(); | 36 | api.bindClearEvt(); |
@@ -45,12 +57,13 @@ $verifyCodeImg.on('touchstart', function() { | @@ -45,12 +57,13 @@ $verifyCodeImg.on('touchstart', function() { | ||
45 | $btnNext.on('touchstart', function() { | 57 | $btnNext.on('touchstart', function() { |
46 | var pn = trim($phoneNum.val()), | 58 | var pn = trim($phoneNum.val()), |
47 | area = trim($countrySelect.val()), | 59 | area = trim($countrySelect.val()), |
48 | - verify = trim($verifyCode.val()); | 60 | + verify = trim(imgCheck.getResults()); |
49 | 61 | ||
50 | if ($btnNext.hasClass('disable')) { | 62 | if ($btnNext.hasClass('disable')) { |
51 | return; | 63 | return; |
52 | } | 64 | } |
53 | 65 | ||
66 | + | ||
54 | if (verify && area && pn && api.phoneRegx[area].test(pn)) { | 67 | if (verify && area && pn && api.phoneRegx[area].test(pn)) { |
55 | $.ajax({ | 68 | $.ajax({ |
56 | url: '/passport/back/sendcode', | 69 | url: '/passport/back/sendcode', |
@@ -63,18 +76,21 @@ $btnNext.on('touchstart', function() { | @@ -63,18 +76,21 @@ $btnNext.on('touchstart', function() { | ||
63 | success: function(data) { | 76 | success: function(data) { |
64 | if (data.code === 200) { | 77 | if (data.code === 200) { |
65 | location.href = data.data; | 78 | location.href = data.data; |
79 | + return; | ||
66 | } else if (data.code === 409) { | 80 | } else if (data.code === 409) { |
67 | showErrTip(data.message); | 81 | showErrTip(data.message); |
68 | location.href = data.refer; | 82 | location.href = data.refer; |
69 | } else { | 83 | } else { |
70 | showErrTip(data.message); | 84 | showErrTip(data.message); |
71 | } | 85 | } |
86 | + | ||
87 | + imgCheck.refresh(); | ||
72 | } | 88 | } |
73 | }); | 89 | }); |
74 | } else if (!area) { | 90 | } else if (!area) { |
75 | showErrTip('出错了,请重新刷新页面'); | 91 | showErrTip('出错了,请重新刷新页面'); |
76 | - } else if (!verify) { | ||
77 | - showErrTip('请输入验证码'); | 92 | + } else if (verify === '0000') { |
93 | + showErrTip('请将图片旋转到正确位置'); | ||
78 | } else { | 94 | } else { |
79 | showErrTip('手机号格式不正确,请重新输入'); | 95 | showErrTip('手机号格式不正确,请重新输入'); |
80 | } | 96 | } |
@@ -4,6 +4,7 @@ | @@ -4,6 +4,7 @@ | ||
4 | * @date: 2015/10/8 | 4 | * @date: 2015/10/8 |
5 | */ | 5 | */ |
6 | var $ = require('yoho-jquery'); | 6 | var $ = require('yoho-jquery'); |
7 | +var ImgCheck = require('plugin/img-check'); | ||
7 | 8 | ||
8 | var $phoneNum = $('#phone-num'), | 9 | var $phoneNum = $('#phone-num'), |
9 | $countrySelect = $('#country-select'), | 10 | $countrySelect = $('#country-select'), |
@@ -11,6 +12,8 @@ var $phoneNum = $('#phone-num'), | @@ -11,6 +12,8 @@ var $phoneNum = $('#phone-num'), | ||
11 | $pwd = $('#pwd'), | 12 | $pwd = $('#pwd'), |
12 | $loginBtn = $('#btn-login'), | 13 | $loginBtn = $('#btn-login'), |
13 | 14 | ||
15 | + $captcha = $('#js-img-check'), | ||
16 | + | ||
14 | pnPass = false, | 17 | pnPass = false, |
15 | pwdPass = false; | 18 | pwdPass = false; |
16 | 19 | ||
@@ -20,13 +23,28 @@ var tip = require('../../plugin/tip'); | @@ -20,13 +23,28 @@ var tip = require('../../plugin/tip'); | ||
20 | var trim = $.trim; | 23 | var trim = $.trim; |
21 | var showErrTip = tip.show; | 24 | var showErrTip = tip.show; |
22 | 25 | ||
26 | +var imgCheck = new ImgCheck($captcha, { | ||
27 | + useREM: { | ||
28 | + rootFontSize: 40, | ||
29 | + picWidth: 150 | ||
30 | + } | ||
31 | +}); | ||
32 | + | ||
33 | +if ($captcha.data('init') != null) { //eslint-disable-line | ||
34 | + imgCheck.init(); | ||
35 | +} | ||
36 | + | ||
37 | + | ||
23 | // 登录按钮状态切换 | 38 | // 登录按钮状态切换 |
24 | function switchLoginBtnStatus() { | 39 | function switchLoginBtnStatus() { |
25 | - if (pnPass && pwdPass) { | ||
26 | - $loginBtn.removeClass('disable'); | ||
27 | - } else { | ||
28 | - $loginBtn.addClass('disable'); | ||
29 | - } | 40 | + var bool = !(pnPass && pwdPass); |
41 | + | ||
42 | + $loginBtn.toggleClass('disable', bool); | ||
43 | +} | ||
44 | + | ||
45 | +function resetForm() { | ||
46 | + $pwd.val('').focus(); | ||
47 | + $loginBtn.text('登录').addClass('disable'); | ||
30 | } | 48 | } |
31 | 49 | ||
32 | // Android-UC下显示select的direction:rtl无效的临时解决办法 | 50 | // Android-UC下显示select的direction:rtl无效的临时解决办法 |
@@ -67,23 +85,39 @@ $countrySelect.change(function() { | @@ -67,23 +85,39 @@ $countrySelect.change(function() { | ||
67 | $loginBtn.on('touchstart', function() { | 85 | $loginBtn.on('touchstart', function() { |
68 | var pn = trim($phoneNum.val()), | 86 | var pn = trim($phoneNum.val()), |
69 | areaCode = $countrySelect.val(), | 87 | areaCode = $countrySelect.val(), |
70 | - pwd = trim($pwd.val()); | 88 | + pwd = trim($pwd.val()), |
89 | + captcha = null; | ||
71 | 90 | ||
72 | if ($loginBtn.hasClass('disable')) { | 91 | if ($loginBtn.hasClass('disable')) { |
73 | return; | 92 | return; |
74 | } | 93 | } |
75 | 94 | ||
95 | + if (imgCheck.atWorking) { | ||
96 | + captcha = imgCheck.getResults(); | ||
97 | + | ||
98 | + if (captcha === '0000') { | ||
99 | + return tip.show(' 请将图片旋转到正确方向'); | ||
100 | + } | ||
101 | + } | ||
102 | + | ||
103 | + | ||
76 | $loginBtn.text('正在登录...').addClass('disable'); | 104 | $loginBtn.text('正在登录...').addClass('disable'); |
77 | 105 | ||
78 | if ((api.phoneRegx[areaCode].test(pn) || areaCode !== '+86') && api.pwdValidate(pwd)) { | 106 | if ((api.phoneRegx[areaCode].test(pn) || areaCode !== '+86') && api.pwdValidate(pwd)) { |
107 | + let data = { | ||
108 | + areaCode: areaCode.replace('+', ''), | ||
109 | + account: pn, | ||
110 | + password: pwd | ||
111 | + }; | ||
112 | + | ||
113 | + if (imgCheck.atWorking) { | ||
114 | + $.extend(data, {captcha}); | ||
115 | + } | ||
116 | + | ||
79 | $.ajax({ | 117 | $.ajax({ |
80 | type: 'POST', | 118 | type: 'POST', |
81 | url: '/passport/login/auth', | 119 | url: '/passport/login/auth', |
82 | - data: { | ||
83 | - areaCode: areaCode.replace('+', ''), | ||
84 | - account: pn, | ||
85 | - password: pwd | ||
86 | - }, | 120 | + data, |
87 | success: function(data) { | 121 | success: function(data) { |
88 | var res, | 122 | var res, |
89 | time; | 123 | time; |
@@ -110,21 +144,27 @@ $loginBtn.on('touchstart', function() { | @@ -110,21 +144,27 @@ $loginBtn.on('touchstart', function() { | ||
110 | location.href = res.href; | 144 | location.href = res.href; |
111 | }, 3000); | 145 | }, 3000); |
112 | 146 | ||
147 | + $loginBtn.text('登录成功').off(); | ||
113 | showErrTip('登录成功'); | 148 | showErrTip('登录成功'); |
114 | } else { | 149 | } else { |
150 | + if (data.captchaShow) { | ||
151 | + imgCheck.atWorking ? imgCheck.refresh() : imgCheck.init(); | ||
152 | + } | ||
153 | + | ||
115 | showErrTip(data.message); | 154 | showErrTip(data.message); |
155 | + resetForm(); | ||
116 | } | 156 | } |
117 | }, | 157 | }, |
118 | error: function() { | 158 | error: function() { |
119 | showErrTip('网络断开连接啦~'); | 159 | showErrTip('网络断开连接啦~'); |
120 | - }, | ||
121 | - complete: function() { | ||
122 | - $loginBtn.text('登录').removeClass('disable'); | 160 | + $loginBtn.text('登录'); |
161 | + | ||
162 | + imgCheck.atWorking && imgCheck.refresh(); | ||
123 | } | 163 | } |
124 | }); | 164 | }); |
125 | } else { | 165 | } else { |
126 | showErrTip('账号或密码有错误,请重新输入'); | 166 | showErrTip('账号或密码有错误,请重新输入'); |
127 | - $loginBtn.text('登录').removeClass('disable'); | 167 | + $loginBtn.text('登录').addClass('disable'); |
128 | } | 168 | } |
129 | }); | 169 | }); |
130 | 170 |
@@ -4,6 +4,7 @@ | @@ -4,6 +4,7 @@ | ||
4 | * @date: 2015/9/30 | 4 | * @date: 2015/9/30 |
5 | */ | 5 | */ |
6 | var $ = require('yoho-jquery'); | 6 | var $ = require('yoho-jquery'); |
7 | +var ImgCheck = require('plugin/img-check'); | ||
7 | 8 | ||
8 | var $account = $('#account'), | 9 | var $account = $('#account'), |
9 | $pwd = $('#pwd'), | 10 | $pwd = $('#pwd'), |
@@ -12,6 +13,8 @@ var $account = $('#account'), | @@ -12,6 +13,8 @@ var $account = $('#account'), | ||
12 | $mask = $('#retrive-pwd-mask'), | 13 | $mask = $('#retrive-pwd-mask'), |
13 | $ways = $('#retrive-pwd-ways'), | 14 | $ways = $('#retrive-pwd-ways'), |
14 | 15 | ||
16 | + $captcha = $('#js-img-check'), | ||
17 | + | ||
15 | accPass = false, | 18 | accPass = false, |
16 | pwdPass = false; | 19 | pwdPass = false; |
17 | 20 | ||
@@ -21,13 +24,30 @@ var tip = require('../../plugin/tip'); | @@ -21,13 +24,30 @@ var tip = require('../../plugin/tip'); | ||
21 | var trim = $.trim; | 24 | var trim = $.trim; |
22 | var showErrTip = tip.show; | 25 | var showErrTip = tip.show; |
23 | 26 | ||
27 | + | ||
28 | +var imgCheck = new ImgCheck($captcha, { | ||
29 | + useREM: { | ||
30 | + rootFontSize: 40, | ||
31 | + picWidth: 150 | ||
32 | + } | ||
33 | +}); | ||
34 | + | ||
35 | +if ($captcha.data('init') != null) { //eslint-disable-line | ||
36 | + imgCheck.init(); | ||
37 | +} | ||
38 | + | ||
24 | // 登录按钮状态切换 | 39 | // 登录按钮状态切换 |
25 | function switchLoginBtnStatus() { | 40 | function switchLoginBtnStatus() { |
26 | - if (accPass && pwdPass) { | ||
27 | - $loginBtn.removeClass('disable'); | ||
28 | - } else { | ||
29 | - $loginBtn.addClass('disable'); | ||
30 | - } | 41 | + var bool = true; |
42 | + | ||
43 | + bool = !(accPass && pwdPass); | ||
44 | + | ||
45 | + $loginBtn.toggleClass('disable', bool); | ||
46 | +} | ||
47 | + | ||
48 | +function resetForm() { | ||
49 | + $pwd.val('').focus(); | ||
50 | + $loginBtn.text('登录').addClass('disable'); | ||
31 | } | 51 | } |
32 | 52 | ||
33 | // 显示找回密码面板 | 53 | // 显示找回密码面板 |
@@ -70,23 +90,38 @@ $pwd.bind('input', function() { | @@ -70,23 +90,38 @@ $pwd.bind('input', function() { | ||
70 | // Login | 90 | // Login |
71 | $loginBtn.on('touchstart', function() { | 91 | $loginBtn.on('touchstart', function() { |
72 | var acc = trim($account.val()), | 92 | var acc = trim($account.val()), |
73 | - pwd = trim($pwd.val()); | 93 | + pwd = trim($pwd.val()), |
94 | + captcha = null; | ||
74 | 95 | ||
75 | if ($loginBtn.hasClass('disable')) { | 96 | if ($loginBtn.hasClass('disable')) { |
76 | return; | 97 | return; |
77 | } | 98 | } |
78 | 99 | ||
100 | + if (imgCheck.atWorking) { | ||
101 | + captcha = imgCheck.getResults(); | ||
102 | + | ||
103 | + if (captcha === '0000') { | ||
104 | + return tip.show(' 请将图片旋转到正确方向'); | ||
105 | + } | ||
106 | + } | ||
107 | + | ||
79 | $loginBtn.text('正在登录...').addClass('disable'); | 108 | $loginBtn.text('正在登录...').addClass('disable'); |
80 | 109 | ||
81 | // 验证账号(数字或者邮箱)和密码合理性 | 110 | // 验证账号(数字或者邮箱)和密码合理性 |
82 | if ((/^[0-9]+$/.test(acc) || api.emailRegx.test(acc)) && api.pwdValidate(pwd)) { | 111 | if ((/^[0-9]+$/.test(acc) || api.emailRegx.test(acc)) && api.pwdValidate(pwd)) { |
112 | + let data = { | ||
113 | + account: acc, | ||
114 | + password: pwd | ||
115 | + }; | ||
116 | + | ||
117 | + if (imgCheck.atWorking) { | ||
118 | + $.extend(data, {captcha}); | ||
119 | + } | ||
120 | + | ||
83 | $.ajax({ | 121 | $.ajax({ |
84 | type: 'POST', | 122 | type: 'POST', |
85 | url: '/passport/login/auth', | 123 | url: '/passport/login/auth', |
86 | - data: { | ||
87 | - account: acc, | ||
88 | - password: pwd | ||
89 | - }, | 124 | + data, |
90 | success: function(data) { | 125 | success: function(data) { |
91 | var res; | 126 | var res; |
92 | 127 | ||
@@ -95,12 +130,22 @@ $loginBtn.on('touchstart', function() { | @@ -95,12 +130,22 @@ $loginBtn.on('touchstart', function() { | ||
95 | 130 | ||
96 | showErrTip('登录成功'); | 131 | showErrTip('登录成功'); |
97 | location.href = res.href; | 132 | location.href = res.href; |
133 | + $loginBtn.text('登录成功').off(); | ||
98 | } else { | 134 | } else { |
135 | + if (data.captchaShow) { | ||
136 | + imgCheck.atWorking ? imgCheck.refresh() : imgCheck.init(); | ||
137 | + } | ||
138 | + | ||
99 | showErrTip(data.message); | 139 | showErrTip(data.message); |
140 | + resetForm(); | ||
100 | } | 141 | } |
142 | + | ||
143 | + return data; | ||
101 | }, | 144 | }, |
102 | error: function() { | 145 | error: function() { |
103 | showErrTip('网络断开连接啦~'); | 146 | showErrTip('网络断开连接啦~'); |
147 | + | ||
148 | + imgCheck.atWorking && imgCheck.refresh(); | ||
104 | }, | 149 | }, |
105 | complete: function() { | 150 | complete: function() { |
106 | $loginBtn.text('登录').removeClass('disable'); | 151 | $loginBtn.text('登录').removeClass('disable'); |
@@ -35,7 +35,7 @@ $pwd.bind('input', function() { | @@ -35,7 +35,7 @@ $pwd.bind('input', function() { | ||
35 | }); | 35 | }); |
36 | 36 | ||
37 | $btnSure.toggleClass('disable', !bool); | 37 | $btnSure.toggleClass('disable', !bool); |
38 | -}) | 38 | +}); |
39 | 39 | ||
40 | 40 | ||
41 | qs = window.queryString; | 41 | qs = window.queryString; |
@@ -137,4 +137,4 @@ $('.agreement-detail').on('click', function() { | @@ -137,4 +137,4 @@ $('.agreement-detail').on('click', function() { | ||
137 | // 如果有值, 立刻校验 | 137 | // 如果有值, 立刻校验 |
138 | if ($pwd.val()) { | 138 | if ($pwd.val()) { |
139 | $pwd.triggerHandler('input'); | 139 | $pwd.triggerHandler('input'); |
140 | -} | ||
140 | +} |
@@ -24,17 +24,29 @@ api.selectCssHack($('#country-select')); | @@ -24,17 +24,29 @@ api.selectCssHack($('#country-select')); | ||
24 | 24 | ||
25 | api.bindClearEvt(); | 25 | api.bindClearEvt(); |
26 | 26 | ||
27 | + | ||
28 | +// 图片验证码 | ||
29 | +let ImgCheck = require('plugin/img-check'); | ||
30 | + | ||
31 | +let imgCheck = new ImgCheck('#js-img-check', { | ||
32 | + useREM: { | ||
33 | + rootFontSize: 40, | ||
34 | + picWidth: 150 | ||
35 | + } | ||
36 | +}); | ||
37 | + | ||
38 | +imgCheck.init(); | ||
39 | + | ||
27 | /** | 40 | /** |
28 | * 必填校验 | 41 | * 必填校验 |
29 | */ | 42 | */ |
30 | function checkEnableNext() { | 43 | function checkEnableNext() { |
31 | var phone = trim($phoneNum.val()); | 44 | var phone = trim($phoneNum.val()); |
32 | var area = trim($countrySelect.val()); | 45 | var area = trim($countrySelect.val()); |
33 | - var captcha = trim($captcha.val()); | ||
34 | 46 | ||
35 | var ret = true; | 47 | var ret = true; |
36 | 48 | ||
37 | - $.each([phone, area, captcha], function(i, val) { | 49 | + $.each([phone, area], function(i, val) { |
38 | if (!val) { | 50 | if (!val) { |
39 | ret = false; | 51 | ret = false; |
40 | return ret; | 52 | return ret; |
@@ -44,24 +56,13 @@ function checkEnableNext() { | @@ -44,24 +56,13 @@ function checkEnableNext() { | ||
44 | return ret; | 56 | return ret; |
45 | } | 57 | } |
46 | 58 | ||
47 | - | ||
48 | -/** | ||
49 | - * 刷新 校验码 | ||
50 | - */ | ||
51 | -function refreshCaptcha() { | ||
52 | - $captcha.val('').focus(); | ||
53 | - $captchaPNG.attr('src', ['//m.yohobuy.com/passport/reg/captcha.png', '?t=', Date.now()].join('')); | ||
54 | -} | ||
55 | - | ||
56 | - | ||
57 | /* | 59 | /* |
58 | Event bind | 60 | Event bind |
59 | */ | 61 | */ |
60 | $('.reg-page') | 62 | $('.reg-page') |
61 | - .on('input', '.phone-num, #js-captcha', function() { | 63 | + .on('input', '.phone-num', function() { |
62 | $btnNext.toggleClass('disable', !checkEnableNext()); | 64 | $btnNext.toggleClass('disable', !checkEnableNext()); |
63 | - }) | ||
64 | - .on('click', '.passport-captcha-png', refreshCaptcha); | 65 | + }); |
65 | 66 | ||
66 | $countrySelect.change(function() { | 67 | $countrySelect.change(function() { |
67 | $areaCode.text($countrySelect.val()); | 68 | $areaCode.text($countrySelect.val()); |
@@ -70,10 +71,10 @@ $countrySelect.change(function() { | @@ -70,10 +71,10 @@ $countrySelect.change(function() { | ||
70 | $btnNext.on('touchstart', function() { | 71 | $btnNext.on('touchstart', function() { |
71 | var pn = trim($phoneNum.val()), | 72 | var pn = trim($phoneNum.val()), |
72 | areaCode = $countrySelect.val(), | 73 | areaCode = $countrySelect.val(), |
73 | - captcha = $captcha.val().trim(); | 74 | + captcha = imgCheck.getResults(); |
74 | 75 | ||
75 | - if (!captcha) { | ||
76 | - tip.show('请输入验证码'); | 76 | + if (captcha === '0000') { |
77 | + tip.show('请将图片旋转到正确位置'); | ||
77 | return false; | 78 | return false; |
78 | } | 79 | } |
79 | 80 | ||
@@ -102,7 +103,7 @@ $btnNext.on('touchstart', function() { | @@ -102,7 +103,7 @@ $btnNext.on('touchstart', function() { | ||
102 | if (data.code === 200) { | 103 | if (data.code === 200) { |
103 | location.href = data.data; | 104 | location.href = data.data; |
104 | } else { | 105 | } else { |
105 | - refreshCaptcha(); | 106 | + imgCheck.refresh(); |
106 | 107 | ||
107 | showErrTip(data.message); | 108 | showErrTip(data.message); |
108 | requested = false; | 109 | requested = false; |
@@ -110,7 +111,7 @@ $btnNext.on('touchstart', function() { | @@ -110,7 +111,7 @@ $btnNext.on('touchstart', function() { | ||
110 | }, | 111 | }, |
111 | error: function() { | 112 | error: function() { |
112 | showErrTip('出错了,请重试'); | 113 | showErrTip('出错了,请重试'); |
113 | - refreshCaptcha(); | 114 | + imgCheck.refresh(); |
114 | requested = false; | 115 | requested = false; |
115 | } | 116 | } |
116 | }); | 117 | }); |
@@ -17,10 +17,26 @@ tip = require('plugin/tip'); | @@ -17,10 +17,26 @@ tip = require('plugin/tip'); | ||
17 | api = require('./api'); | 17 | api = require('./api'); |
18 | checkPoint = require('./smslogin/check-point'); | 18 | checkPoint = require('./smslogin/check-point'); |
19 | 19 | ||
20 | + | ||
21 | +// 图片验证码 | ||
22 | +let ImgCheck = require('plugin/img-check'); | ||
23 | + | ||
24 | +let imgCheck = new ImgCheck('#js-img-check', { | ||
25 | + useREM: { | ||
26 | + rootFontSize: 40, | ||
27 | + picWidth: 150 | ||
28 | + } | ||
29 | +}); | ||
30 | + | ||
31 | +imgCheck.init(); | ||
32 | + | ||
33 | + | ||
34 | + | ||
20 | page = { | 35 | page = { |
21 | init: function() { | 36 | init: function() { |
22 | this.domInit(); | 37 | this.domInit(); |
23 | this.bindEvent(); | 38 | this.bindEvent(); |
39 | + this.toggleNextBtn(); | ||
24 | }, | 40 | }, |
25 | domInit: function() { | 41 | domInit: function() { |
26 | $countrySelect = $('#country-select'); | 42 | $countrySelect = $('#country-select'); |
@@ -28,8 +44,6 @@ page = { | @@ -28,8 +44,6 @@ page = { | ||
28 | $nextBtn = $('#btn-next'); | 44 | $nextBtn = $('#btn-next'); |
29 | $phoneNum = $('#phone-num'); | 45 | $phoneNum = $('#phone-num'); |
30 | $resetBtn = $('.clear-input'); | 46 | $resetBtn = $('.clear-input'); |
31 | - $captcha = $('.passport-captcha input'); | ||
32 | - $captchaPNG = $('.passport-captcha-img img'); | ||
33 | }, | 47 | }, |
34 | bindEvent: function() { | 48 | bindEvent: function() { |
35 | var self = this; | 49 | var self = this; |
@@ -41,12 +55,6 @@ page = { | @@ -41,12 +55,6 @@ page = { | ||
41 | self.toggleNextBtn(); | 55 | self.toggleNextBtn(); |
42 | }); | 56 | }); |
43 | 57 | ||
44 | - $captcha.on('input', function() { | ||
45 | - self.toggleNextBtn(); | ||
46 | - }); | ||
47 | - | ||
48 | - $captchaPNG.on('click', $.proxy(this.refreshCapatch, this)); | ||
49 | - | ||
50 | $nextBtn.on('click', function() { | 58 | $nextBtn.on('click', function() { |
51 | self.goNext(); | 59 | self.goNext(); |
52 | }); | 60 | }); |
@@ -62,7 +70,7 @@ page = { | @@ -62,7 +70,7 @@ page = { | ||
62 | 70 | ||
63 | // 切换$nextBtn disable状态 | 71 | // 切换$nextBtn disable状态 |
64 | toggleNextBtn: function() { | 72 | toggleNextBtn: function() { |
65 | - var bool = Boolean($.trim($phoneNum.val())) && Boolean($.trim($captcha.val())); | 73 | + var bool = Boolean($.trim($phoneNum.val())); |
66 | 74 | ||
67 | $nextBtn | 75 | $nextBtn |
68 | .toggleClass('disable', !bool) | 76 | .toggleClass('disable', !bool) |
@@ -71,17 +79,11 @@ page = { | @@ -71,17 +79,11 @@ page = { | ||
71 | $resetBtn.toggle(bool); | 79 | $resetBtn.toggle(bool); |
72 | }, | 80 | }, |
73 | 81 | ||
74 | - refreshCapatch: function() { | ||
75 | - $captchaPNG.attr('src', '/passport/sms_login/captcha.png?t=' + Date.now()); | ||
76 | - $captcha.val(''); | ||
77 | - }, | ||
78 | - | ||
79 | // 提交按钮 | 82 | // 提交按钮 |
80 | goNext: function() { | 83 | goNext: function() { |
81 | - var self = this; | ||
82 | var areaCode = $countrySelect.val(); | 84 | var areaCode = $countrySelect.val(); |
83 | var phone = $.trim($phoneNum.val()); | 85 | var phone = $.trim($phoneNum.val()); |
84 | - var captcha = $.trim($captcha.val()); | 86 | + var captcha = $.trim(imgCheck.getResults()); |
85 | 87 | ||
86 | if ($nextBtn.prop('disabled')) { | 88 | if ($nextBtn.prop('disabled')) { |
87 | return; | 89 | return; |
@@ -92,11 +94,16 @@ page = { | @@ -92,11 +94,16 @@ page = { | ||
92 | return; | 94 | return; |
93 | } | 95 | } |
94 | 96 | ||
97 | + if (captcha === '0000') { | ||
98 | + tip.show('请将图片旋转到正确位置'); | ||
99 | + return; | ||
100 | + } | ||
101 | + | ||
95 | $nextBtn.prop('disabled', true); | 102 | $nextBtn.prop('disabled', true); |
96 | - $.get('/passport/sms_login/token.json', { | 103 | + $.post('/passport/sms_login/step1_check', { |
97 | area: areaCode.replace('+', ''), | 104 | area: areaCode.replace('+', ''), |
98 | mobile: phone, | 105 | mobile: phone, |
99 | - captcha: captcha | 106 | + captcode: captcha |
100 | }) | 107 | }) |
101 | .done(function(data) { | 108 | .done(function(data) { |
102 | if (data.code === 200) { | 109 | if (data.code === 200) { |
@@ -104,11 +111,12 @@ page = { | @@ -104,11 +111,12 @@ page = { | ||
104 | $nextBtn.off(); | 111 | $nextBtn.off(); |
105 | location.href = data.redirect; | 112 | location.href = data.redirect; |
106 | } else { | 113 | } else { |
107 | - self.refreshCapatch(); | 114 | + imgCheck.refresh(); |
108 | tip.show(data.message); | 115 | tip.show(data.message); |
109 | } | 116 | } |
110 | }) | 117 | }) |
111 | .fail(function() { | 118 | .fail(function() { |
119 | + imgCheck.refresh(); | ||
112 | tip.show('出错了, 请重试'); | 120 | tip.show('出错了, 请重试'); |
113 | }) | 121 | }) |
114 | .always(function() { | 122 | .always(function() { |
@@ -12,10 +12,12 @@ var sendInfo = function(eventName) { | @@ -12,10 +12,12 @@ var sendInfo = function(eventName) { | ||
12 | channel = channelMap[channel] || 1; | 12 | channel = channelMap[channel] || 1; |
13 | param = JSON.stringify({C_ID: channel}); | 13 | param = JSON.stringify({C_ID: channel}); |
14 | 14 | ||
15 | - yas && yas.sendCustomInfo({ | ||
16 | - op: eventName, | ||
17 | - param: param | ||
18 | - }, true); | 15 | + if (yas && yas.sendCustomInfo) { |
16 | + yas.sendCustomInfo({ | ||
17 | + op: eventName, | ||
18 | + param: param | ||
19 | + }, true); | ||
20 | + } | ||
19 | }; | 21 | }; |
20 | 22 | ||
21 | module.exports = sendInfo; | 23 | module.exports = sendInfo; |
-
Please register or login to post a comment