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