|
@@ -13,6 +13,7 @@ const utils = require(global.utils); |
|
@@ -13,6 +13,7 @@ const utils = require(global.utils); |
13
|
const helpers = global.yoho.helpers;
|
13
|
const helpers = global.yoho.helpers;
|
14
|
const sign = global.yoho.sign;
|
14
|
const sign = global.yoho.sign;
|
15
|
const cookie = global.yoho.cookie;
|
15
|
const cookie = global.yoho.cookie;
|
|
|
16
|
+const config = global.yoho.config;
|
16
|
const RegService = require('../models/reg-service');
|
17
|
const RegService = require('../models/reg-service');
|
17
|
const AuthHelper = require('../models/auth-helper');
|
18
|
const AuthHelper = require('../models/auth-helper');
|
18
|
const captchaService = require('../models/captcha-service');
|
19
|
const captchaService = require('../models/captcha-service');
|
|
@@ -84,6 +85,10 @@ let index = (req, res) => { |
|
@@ -84,6 +85,10 @@ let index = (req, res) => { |
84
|
// session init
|
85
|
// session init
|
85
|
_.set(req.session, 'phoneReg.step', 1);
|
86
|
_.set(req.session, 'phoneReg.step', 1);
|
86
|
|
87
|
|
|
|
88
|
+ if (req.session.captchaValidCount == null) { // eslint-disable-line
|
|
|
89
|
+ req.session.captchaValidCount = 5;
|
|
|
90
|
+ }
|
|
|
91
|
+
|
87
|
if (req.session.phoneReg.count == null) { // eslint-disable-line
|
92
|
if (req.session.phoneReg.count == null) { // eslint-disable-line
|
88
|
req.session.phoneReg.count = 5;
|
93
|
req.session.phoneReg.count = 5;
|
89
|
}
|
94
|
}
|
|
@@ -113,26 +118,34 @@ let verifyMobile = (req, res, next) => { |
|
@@ -113,26 +118,34 @@ let verifyMobile = (req, res, next) => { |
113
|
let mobile = +req.body.phoneNum;
|
118
|
let mobile = +req.body.phoneNum;
|
114
|
let area = +(req.body.areaCode || 86);
|
119
|
let area = +(req.body.areaCode || 86);
|
115
|
let captcha = (req.body.captcha || '').trim();
|
120
|
let captcha = (req.body.captcha || '').trim();
|
|
|
121
|
+ let testCode = req.body.yohobuy;
|
|
|
122
|
+
|
116
|
let diffCaptcha = _.get(req.session, 'captcha');
|
123
|
let diffCaptcha = _.get(req.session, 'captcha');
|
|
|
124
|
+ let errorCount = _.get(req.session, 'captchaValidCount', 4);
|
117
|
|
125
|
|
118
|
// error case: 没有验证码
|
126
|
// error case: 没有验证码
|
119
|
if (!diffCaptcha) {
|
127
|
if (!diffCaptcha) {
|
120
|
- return res.json({
|
|
|
121
|
- code: 400,
|
|
|
122
|
- message: '请求失败',
|
|
|
123
|
- refreshCaptcha: true
|
|
|
124
|
- });
|
128
|
+ data.message = '非法请求';
|
|
|
129
|
+ data.changeCaptcha = true;
|
|
|
130
|
+
|
|
|
131
|
+ return res.json(data);
|
125
|
}
|
132
|
}
|
126
|
|
133
|
|
127
|
- delete req.session.captcha; // captcha 一次性
|
134
|
+ if (req.session.captchaValidCount) {
|
|
|
135
|
+ --req.session.captchaValidCount;
|
|
|
136
|
+ }
|
|
|
137
|
+
|
|
|
138
|
+ if (!errorCount) {
|
|
|
139
|
+ _.set(req.session, 'captchaValidCount', 4);
|
|
|
140
|
+
|
|
|
141
|
+ req.session.captcha = null;
|
|
|
142
|
+ data.changeCaptcha = true;
|
|
|
143
|
+ }
|
128
|
|
144
|
|
129
|
// error case: 验证码不匹配
|
145
|
// error case: 验证码不匹配
|
130
|
- if (captcha !== diffCaptcha) {
|
|
|
131
|
- return res.json({
|
|
|
132
|
- code: 400,
|
|
|
133
|
- message: '校验码不正确',
|
|
|
134
|
- refreshCaptcha: true
|
|
|
135
|
- });
|
146
|
+ if (!(captcha === diffCaptcha || testCode === config.testCode)) {
|
|
|
147
|
+ data.message = '请将图片旋转到正确方向';
|
|
|
148
|
+ return res.json(data);
|
136
|
}
|
149
|
}
|
137
|
|
150
|
|
138
|
// 判断参数是否合法
|
151
|
// 判断参数是否合法
|
|
@@ -152,7 +165,8 @@ let verifyMobile = (req, res, next) => { |
|
@@ -152,7 +165,8 @@ let verifyMobile = (req, res, next) => { |
152
|
|
165
|
|
153
|
// 向手机发送注册验证码
|
166
|
// 向手机发送注册验证码
|
154
|
RegService.sendCodeToMobile(area, mobile).then((result) => {
|
167
|
RegService.sendCodeToMobile(area, mobile).then((result) => {
|
155
|
- if (!result.code) {
|
168
|
+ if (result.code !== 200) {
|
|
|
169
|
+ data.message = result.message;
|
156
|
return res.json(data);
|
170
|
return res.json(data);
|
157
|
}
|
171
|
}
|
158
|
|
172
|
|