Authored by 毕凯

增加注册验证码

@@ -78,20 +78,19 @@ let checkMobile = (req, res, next) => { @@ -78,20 +78,19 @@ let checkMobile = (req, res, next) => {
78 }).catch(next); 78 }).catch(next);
79 }; 79 };
80 80
81 -let picCaptcha = (req, res, next) => { 81 +let picCaptcha = (req, res) => {
82 let verifyCode = _.trim(req.body.verifyCode); 82 let verifyCode = _.trim(req.body.verifyCode);
83 - let picFlag = true; // TODO: 图形验证码校验  
84 83
85 - if (picFlag) { 84 + if (verifyCode !== req.session.captcha) {
86 return res.json({ 85 return res.json({
87 - code: 200,  
88 - message: '验证码正确' 86 + code: 400,
  87 + message: '验证码错误'
89 }); 88 });
90 } 89 }
91 90
92 return res.json({ 91 return res.json({
93 - code: 400,  
94 - message: '验证码错误' 92 + code: 200,
  93 + message: '验证码正确'
95 }); 94 });
96 }; 95 };
97 96
@@ -104,7 +103,6 @@ let sendBindMsg = (req, res, next) => { @@ -104,7 +103,6 @@ let sendBindMsg = (req, res, next) => {
104 103
105 let mobile = +req.body.mobile; 104 let mobile = +req.body.mobile;
106 let area = +req.body.area; 105 let area = +req.body.area;
107 - let verifyCode = +req.body.verifyCode;  
108 106
109 // 判断参数是否合法 107 // 判断参数是否合法
110 if (!_.isNumber(mobile) || !_.isNumber(area)) { 108 if (!_.isNumber(mobile) || !_.isNumber(area)) {
@@ -112,6 +110,13 @@ let sendBindMsg = (req, res, next) => { @@ -112,6 +110,13 @@ let sendBindMsg = (req, res, next) => {
112 return res.json(data); 110 return res.json(data);
113 } 111 }
114 112
  113 + let verifyCode = _.trim(req.body.verifyCode);
  114 +
  115 + if (verifyCode !== req.session.captcha) {
  116 + data.message = '验证码不正确';
  117 + return res.json(data);
  118 + }
  119 +
115 // 检查是否检查过 120 // 检查是否检查过
116 // let makeMobile = passportHelper.makeAreaMobile(area, mobile); 121 // let makeMobile = passportHelper.makeAreaMobile(area, mobile);
117 // 122 //
@@ -140,13 +145,6 @@ let sendBindMsg = (req, res, next) => { @@ -140,13 +145,6 @@ let sendBindMsg = (req, res, next) => {
140 return res.json(data); 145 return res.json(data);
141 } 146 }
142 147
143 - // TODO: 检测验证码不正确  
144 - // if (!PassportModel::verifyCode($verifyCode)) {  
145 - // $data['code'] = 400;  
146 - // $data['message'] = '图形验证码不正确';  
147 - // break;  
148 - // }  
149 -  
150 /* 向手机发送注册验证码 */ 148 /* 向手机发送注册验证码 */
151 return regService.sendCodeToMobile(area, mobile).then((result) => { 149 return regService.sendCodeToMobile(area, mobile).then((result) => {
152 return cache.set(sendCodeKey, sendCodeTimes + 1, 3600).then(() => { 150 return cache.set(sendCodeKey, sendCodeTimes + 1, 3600).then(() => {
@@ -212,12 +210,12 @@ let mobileRegister = (req, res, next) => { @@ -212,12 +210,12 @@ let mobileRegister = (req, res, next) => {
212 return res.json(data); 210 return res.json(data);
213 } 211 }
214 212
215 - // TODO: 检测验证码不正确  
216 - // $verifyCode = strtolower(trim($this->post('verifyCode'))); //图形验证码  
217 - // if (!PassportModel::verifyCode($verifyCode)) {  
218 - // $data['message'] = '验证码不正确';  
219 - // break;  
220 - // } 213 + let verifyCode = _.trim(req.body.verifyCode);
  214 +
  215 + if (verifyCode !== req.session.captcha) {
  216 + data.message = '验证码不正确';
  217 + return res.json(data);
  218 + }
221 219
222 /* 判断密码是否符合规则 */ 220 /* 判断密码是否符合规则 */
223 let code = +req.body.code; // 短信验证码 221 let code = +req.body.code; // 短信验证码
@@ -33,6 +33,7 @@ @@ -33,6 +33,7 @@
33 "dependencies": { 33 "dependencies": {
34 "bluebird": "^3.4.0", 34 "bluebird": "^3.4.0",
35 "body-parser": "^1.15.0", 35 "body-parser": "^1.15.0",
  36 + "captchapng": "0.0.1",
36 "connect-memcached": "^0.2.0", 37 "connect-memcached": "^0.2.0",
37 "cookie-parser": "^1.4.3", 38 "cookie-parser": "^1.4.3",
38 "express": "^4.13.1", 39 "express": "^4.13.1",