Showing
11 changed files
with
307 additions
and
251 deletions
@@ -5,12 +5,11 @@ | @@ -5,12 +5,11 @@ | ||
5 | 5 | ||
6 | 'use strict'; | 6 | 'use strict'; |
7 | 7 | ||
8 | -const library = '../../../library'; | ||
9 | -const helpers = require(`${library}/helpers`); | ||
10 | - | ||
11 | -const service = require('../models/back-service'); | 8 | +const library = '../../../library'; |
9 | +const helpers = require(`${library}/helpers`); | ||
10 | +const service = require('../models/back-service'); | ||
12 | const passportHelper = require('../models/passport-helper'); | 11 | const passportHelper = require('../models/passport-helper'); |
13 | -const moment = require('moment'); | 12 | +const moment = require('moment'); |
14 | 13 | ||
15 | // 本地地址 localhost | 14 | // 本地地址 localhost |
16 | helpers.urlFormat = helpers.fakeUrlFormat; | 15 | helpers.urlFormat = helpers.fakeUrlFormat; |
@@ -19,13 +18,15 @@ helpers.urlFormat = helpers.fakeUrlFormat; | @@ -19,13 +18,15 @@ helpers.urlFormat = helpers.fakeUrlFormat; | ||
19 | * 找回密码主页面 | 18 | * 找回密码主页面 |
20 | */ | 19 | */ |
21 | module.exports.indexPage = (req, res, next) => { | 20 | module.exports.indexPage = (req, res, next) => { |
22 | - service.indexPageDataAsync().then(result => { | ||
23 | - res.render('back/index', Object.assign({ | ||
24 | - module: 'passport', | ||
25 | - page: 'back-index', | ||
26 | - title: '找回密码' | ||
27 | - }, result)); | ||
28 | - }).catch(next); | 21 | + service.indexPageDataAsync() |
22 | + .then(result => { | ||
23 | + res.render('back/index', Object.assign({ | ||
24 | + module: 'passport', | ||
25 | + page : 'back-index', | ||
26 | + title : '找回密码' | ||
27 | + }, result)); | ||
28 | + }) | ||
29 | + .catch(next); | ||
29 | }; | 30 | }; |
30 | 31 | ||
31 | /** | 32 | /** |
@@ -33,8 +34,7 @@ module.exports.indexPage = (req, res, next) => { | @@ -33,8 +34,7 @@ module.exports.indexPage = (req, res, next) => { | ||
33 | */ | 34 | */ |
34 | module.exports.validateInputAPI = (req, res, next) => { | 35 | module.exports.validateInputAPI = (req, res, next) => { |
35 | let userInput = req.body.phoneNum || ''; | 36 | let userInput = req.body.phoneNum || ''; |
36 | - | ||
37 | - let areaCode = (req.body.area || '86').replace('+', ''); | 37 | + let areaCode = (req.body.area || '86').replace('+', ''); |
38 | 38 | ||
39 | service.validateEmailOrMobileAsync(userInput, areaCode) | 39 | service.validateEmailOrMobileAsync(userInput, areaCode) |
40 | .then(result => { | 40 | .then(result => { |
@@ -44,7 +44,7 @@ module.exports.validateInputAPI = (req, res, next) => { | @@ -44,7 +44,7 @@ module.exports.validateInputAPI = (req, res, next) => { | ||
44 | }) | 44 | }) |
45 | .catch(err => { | 45 | .catch(err => { |
46 | res.json({ | 46 | res.json({ |
47 | - code: 400, | 47 | + code : 400, |
48 | message: err | 48 | message: err |
49 | }); | 49 | }); |
50 | }); | 50 | }); |
@@ -55,8 +55,7 @@ module.exports.validateInputAPI = (req, res, next) => { | @@ -55,8 +55,7 @@ module.exports.validateInputAPI = (req, res, next) => { | ||
55 | */ | 55 | */ |
56 | module.exports.validateUserPage = (req, res, next) => { | 56 | module.exports.validateUserPage = (req, res, next) => { |
57 | let userInput = req.body.phoneNum || ''; | 57 | let userInput = req.body.phoneNum || ''; |
58 | - | ||
59 | - let areaCode = (req.body.area || '86').replace('+', ''); | 58 | + let areaCode = (req.body.area || '86').replace('+', ''); |
60 | 59 | ||
61 | service.validateEmailOrMobileAsync(userInput, areaCode) | 60 | service.validateEmailOrMobileAsync(userInput, areaCode) |
62 | .then(result => { | 61 | .then(result => { |
@@ -74,22 +73,25 @@ module.exports.getUserInfoAPI = (req, res, next) => { | @@ -74,22 +73,25 @@ module.exports.getUserInfoAPI = (req, res, next) => { | ||
74 | service.findUserAsync(inputInfo.type, inputInfo.phone, inputInfo.area) | 73 | service.findUserAsync(inputInfo.type, inputInfo.phone, inputInfo.area) |
75 | .then(result => { | 74 | .then(result => { |
76 | res.json(result); | 75 | res.json(result); |
77 | - }).catch(next); | 76 | + }) |
77 | + .catch(next); | ||
78 | }; | 78 | }; |
79 | 79 | ||
80 | module.exports.sendCodePage = (req, res, next) => { | 80 | module.exports.sendCodePage = (req, res, next) => { |
81 | let inputInfo = req.inputInfo; | 81 | let inputInfo = req.inputInfo; |
82 | 82 | ||
83 | - service.sendCodeToUserAsync(inputInfo.type, inputInfo.phone, inputInfo.area).then(result => { | ||
84 | - if (_.isEmpty(result)) { | ||
85 | - res.redirect(helpers.urlFormat('/passport/back/index.html')); | ||
86 | - } else { | ||
87 | - next(); | ||
88 | - } | 83 | + service.sendCodeToUserAsync(inputInfo.type, inputInfo.phone, inputInfo.area) |
84 | + .then(result => { | ||
85 | + if (_.isEmpty(result)) { | ||
86 | + res.redirect(helpers.urlFormat('/passport/back/index.html')); | ||
87 | + } else { | ||
88 | + next(); | ||
89 | + } | ||
89 | 90 | ||
90 | - }).catch(() => { | ||
91 | - res.redirect(helpers.urlFormat('/passport/back/index.html')); | ||
92 | - }); | 91 | + }) |
92 | + .catch(() => { | ||
93 | + res.redirect(helpers.urlFormat('/passport/back/index.html')); | ||
94 | + }); | ||
93 | }; | 95 | }; |
94 | 96 | ||
95 | module.exports.saveInSession = (req, res) => { | 97 | module.exports.saveInSession = (req, res) => { |
@@ -103,7 +105,7 @@ module.exports.saveInSession = (req, res) => { | @@ -103,7 +105,7 @@ module.exports.saveInSession = (req, res) => { | ||
103 | case 'mobile': | 105 | case 'mobile': |
104 | { | 106 | { |
105 | req.session.mobile = req.inputInfo.phone; | 107 | req.session.mobile = req.inputInfo.phone; |
106 | - req.session.area = req.inputInfo.area; | 108 | + req.session.area = req.inputInfo.area; |
107 | res.redirect(helpers.urlFormat('/passport/back/verification.html')); | 109 | res.redirect(helpers.urlFormat('/passport/back/verification.html')); |
108 | break; | 110 | break; |
109 | } | 111 | } |
@@ -118,7 +120,8 @@ module.exports.sendBackMobileAPI = (req, res, next) => { | @@ -118,7 +120,8 @@ module.exports.sendBackMobileAPI = (req, res, next) => { | ||
118 | service.sendCodeToMobileAsync(area, mobile) | 120 | service.sendCodeToMobileAsync(area, mobile) |
119 | .then(result => { | 121 | .then(result => { |
120 | res.json(result); | 122 | res.json(result); |
121 | - }).catch(next); | 123 | + }) |
124 | + .catch(next); | ||
122 | }; | 125 | }; |
123 | 126 | ||
124 | module.exports.validateMobileAPI = (req, res, next) => { | 127 | module.exports.validateMobileAPI = (req, res, next) => { |
@@ -157,13 +160,13 @@ module.exports.sendEmailPage = (req, res, next) => { | @@ -157,13 +160,13 @@ module.exports.sendEmailPage = (req, res, next) => { | ||
157 | .then(result => { | 160 | .then(result => { |
158 | res.render('back/send-email', Object.assign({ | 161 | res.render('back/send-email', Object.assign({ |
159 | module: 'passport', | 162 | module: 'passport', |
160 | - page: 'back-send-email-ok', | ||
161 | - title: "邮件发送成功" | 163 | + page : 'back-send-email-ok', |
164 | + title : "邮件发送成功" | ||
162 | }, { | 165 | }, { |
163 | sendEmail: { | 166 | sendEmail: { |
164 | coverHref: result.url, | 167 | coverHref: result.url, |
165 | - coverImg: result.img, | ||
166 | - email: req.body.emailUrl | 168 | + coverImg : result.img, |
169 | + email : req.body.emailUrl | ||
167 | } | 170 | } |
168 | })); | 171 | })); |
169 | }).catch(next); | 172 | }).catch(next); |
@@ -185,7 +188,8 @@ module.exports.validateCodeByEmailPage = (req, res, next) => { | @@ -185,7 +188,8 @@ module.exports.validateCodeByEmailPage = (req, res, next) => { | ||
185 | } else { | 188 | } else { |
186 | res.redirect(helpers.urlFormat('/passport/back/index.html')); | 189 | res.redirect(helpers.urlFormat('/passport/back/index.html')); |
187 | } | 190 | } |
188 | - }).catch(next); | 191 | + }) |
192 | + .catch(next); | ||
189 | }; | 193 | }; |
190 | 194 | ||
191 | module.exports.resetPasswordPage = (req, res, next) => { | 195 | module.exports.resetPasswordPage = (req, res, next) => { |
@@ -195,39 +199,40 @@ module.exports.resetPasswordPage = (req, res, next) => { | @@ -195,39 +199,40 @@ module.exports.resetPasswordPage = (req, res, next) => { | ||
195 | .then(result => { | 199 | .then(result => { |
196 | res.render('back/reset-pwd', Object.assign({ | 200 | res.render('back/reset-pwd', Object.assign({ |
197 | module: 'passport', | 201 | module: 'passport', |
198 | - page: 'back-reset-pwd', | ||
199 | - title: '重置密码' | 202 | + page : 'back-reset-pwd', |
203 | + title : '重置密码' | ||
200 | }, { | 204 | }, { |
201 | resetPwd: Object.assign({ | 205 | resetPwd: Object.assign({ |
202 | coverHref: result.url, | 206 | coverHref: result.url, |
203 | - coverImg: result.img, | ||
204 | - code: code | 207 | + coverImg : result.img, |
208 | + code : code | ||
205 | }, req.mobileAuth) | 209 | }, req.mobileAuth) |
206 | })) | 210 | })) |
207 | - }).catch(next); | 211 | + }) |
212 | + .catch(next); | ||
208 | }; | 213 | }; |
209 | 214 | ||
210 | /** | 215 | /** |
211 | * 手机验证页面 | 216 | * 手机验证页面 |
212 | */ | 217 | */ |
213 | module.exports.verifyCodeByMobilePage = (req, res, next) => { | 218 | module.exports.verifyCodeByMobilePage = (req, res, next) => { |
214 | - | ||
215 | passportHelper.getLeftBannerAsync() | 219 | passportHelper.getLeftBannerAsync() |
216 | .then(result => { | 220 | .then(result => { |
217 | res.render('back/verification', Object.assign({ | 221 | res.render('back/verification', Object.assign({ |
218 | module: 'passport', | 222 | module: 'passport', |
219 | - page: 'back-verify-mobile-code', | ||
220 | - title: '手机验证' | 223 | + page : 'back-verify-mobile-code', |
224 | + title : '手机验证' | ||
221 | }, { | 225 | }, { |
222 | verification: { | 226 | verification: { |
223 | - coverHref: result.url, | ||
224 | - coverImg: result.img, | ||
225 | - mobile: req.body.mobile, | ||
226 | - area: req.body.area, | 227 | + coverHref : result.url, |
228 | + coverImg : result.img, | ||
229 | + mobile : req.body.mobile, | ||
230 | + area : req.body.area, | ||
227 | verifyCode: req.body.verifyCode | 231 | verifyCode: req.body.verifyCode |
228 | } | 232 | } |
229 | })); | 233 | })); |
230 | - }).catch(next); | 234 | + }) |
235 | + .catch(next); | ||
231 | }; | 236 | }; |
232 | 237 | ||
233 | module.exports.checkSuccessStatusPage = (req, res, next) => { | 238 | module.exports.checkSuccessStatusPage = (req, res, next) => { |
@@ -246,31 +251,28 @@ module.exports.resetPwdSuccessPage = (req, res, next) => { | @@ -246,31 +251,28 @@ module.exports.resetPwdSuccessPage = (req, res, next) => { | ||
246 | .then(result => { | 251 | .then(result => { |
247 | res.render('back/reset-success', Object.assign({ | 252 | res.render('back/reset-success', Object.assign({ |
248 | module: 'passport', | 253 | module: 'passport', |
249 | - page: 'back-index', | ||
250 | - title: '重置密码成功' | 254 | + page : 'back-index', |
255 | + title : '重置密码成功' | ||
251 | }, { | 256 | }, { |
252 | resetSuccess: { | 257 | resetSuccess: { |
253 | coverHref: result.url, | 258 | coverHref: result.url, |
254 | - coverImg: result.img | 259 | + coverImg : result.img |
255 | } | 260 | } |
256 | })) | 261 | })) |
257 | - }).catch(next); | 262 | + }) |
263 | + .catch(next); | ||
258 | }; | 264 | }; |
259 | 265 | ||
260 | module.exports.verifyCodeByMobileAPI = (req, res) => { | 266 | module.exports.verifyCodeByMobileAPI = (req, res) => { |
261 | - | ||
262 | - let mobile = req.param('mobile', ''); | ||
263 | - | ||
264 | - let area = req.param('area', '86'); | ||
265 | - | 267 | + let mobile = req.param('mobile', ''); |
268 | + let area = req.param('area', '86'); | ||
266 | let mobileCode = req.param('code', ''); | 269 | let mobileCode = req.param('code', ''); |
267 | - | ||
268 | - const session = req.session; | 270 | + const session = req.session; |
269 | 271 | ||
270 | const ERR = { | 272 | const ERR = { |
271 | - code: 400, | 273 | + code : 400, |
272 | message: '验证码错误!', | 274 | message: '验证码错误!', |
273 | - data: helpers.urlFormat('/passport/back/index.html') | 275 | + data : helpers.urlFormat('/passport/back/index.html') |
274 | }; | 276 | }; |
275 | 277 | ||
276 | if (!code || mobile !== session.mobile || area !== session.area) { | 278 | if (!code || mobile !== session.mobile || area !== session.area) { |
@@ -298,8 +300,7 @@ module.exports.validateExistCodePage = (req, res, next) => { | @@ -298,8 +300,7 @@ module.exports.validateExistCodePage = (req, res, next) => { | ||
298 | }; | 300 | }; |
299 | 301 | ||
300 | module.exports.validateCodeByMobilePage = (req, res, next) => { | 302 | module.exports.validateCodeByMobilePage = (req, res, next) => { |
301 | - let code = req.param('code', ''); | ||
302 | - | 303 | + let code = req.param('code', ''); |
303 | let mobile = req.param('mobile', ''); | 304 | let mobile = req.param('mobile', ''); |
304 | 305 | ||
305 | if (!mobile) { | 306 | if (!mobile) { |
@@ -309,13 +310,13 @@ module.exports.validateCodeByMobilePage = (req, res, next) => { | @@ -309,13 +310,13 @@ module.exports.validateCodeByMobilePage = (req, res, next) => { | ||
309 | } | 310 | } |
310 | 311 | ||
311 | let data = { | 312 | let data = { |
312 | - mobile: mobile, | ||
313 | - area: req.param('area', ''), | ||
314 | - token: req.param('token', ''), | 313 | + mobile : mobile, |
314 | + area : req.param('area', ''), | ||
315 | + token : req.param('token', ''), | ||
315 | create_time: req.param('create_time', 0) | 316 | create_time: req.param('create_time', 0) |
316 | }; | 317 | }; |
317 | 318 | ||
318 | - code = new Buffer(code, 'base64').toString(); | 319 | + code = new Buffer(code, 'base64').toString(); |
319 | req.mobileAuth = service.authRequest(data, code); | 320 | req.mobileAuth = service.authRequest(data, code); |
320 | next(); | 321 | next(); |
321 | }; | 322 | }; |
@@ -330,11 +331,9 @@ module.exports.validatePwdPage = (req, res, next) => { | @@ -330,11 +331,9 @@ module.exports.validatePwdPage = (req, res, next) => { | ||
330 | } | 331 | } |
331 | }; | 332 | }; |
332 | 333 | ||
333 | -module.exports.updatePwdAPI = (req, res) => { | ||
334 | - let code = req.body.code || ''; | ||
335 | - | ||
336 | - let mobileAuth = req.mobileAuth; | ||
337 | - | 334 | +module.exports.updatePwdAPI = (req, res, next) => { |
335 | + let code = req.body.code || ''; | ||
336 | + let mobileAuth = req.mobileAuth; | ||
338 | let newPassword = req.body.pwd; | 337 | let newPassword = req.body.pwd; |
339 | 338 | ||
340 | service.updatePwdAsync(code, mobileAuth, newPassword) | 339 | service.updatePwdAsync(code, mobileAuth, newPassword) |
@@ -345,13 +344,14 @@ module.exports.updatePwdAPI = (req, res) => { | @@ -345,13 +344,14 @@ module.exports.updatePwdAPI = (req, res) => { | ||
345 | } else { | 344 | } else { |
346 | res.redirect(helpers.urlFormat('/passport/back/index.html')); | 345 | res.redirect(helpers.urlFormat('/passport/back/index.html')); |
347 | } | 346 | } |
348 | - }); | 347 | + }) |
348 | + .catch(next); | ||
349 | }; | 349 | }; |
350 | 350 | ||
351 | module.exports.validateMobileInSession = (req, res, next) => { | 351 | module.exports.validateMobileInSession = (req, res, next) => { |
352 | - req.body.mobile = req.session.mobile || ""; | 352 | + req.body.mobile = req.session.mobile || ""; |
353 | req.body.verifyCode = req.session.verifyCode || ""; | 353 | req.body.verifyCode = req.session.verifyCode || ""; |
354 | - req.body.area = req.session.area || ""; | 354 | + req.body.area = req.session.area || ""; |
355 | 355 | ||
356 | if (req.body.mobile && req.body.verifyCode) { | 356 | if (req.body.mobile && req.body.verifyCode) { |
357 | next() | 357 | next() |
@@ -359,3 +359,4 @@ module.exports.validateMobileInSession = (req, res, next) => { | @@ -359,3 +359,4 @@ module.exports.validateMobileInSession = (req, res, next) => { | ||
359 | res.redirect(helpers.urlFormat('/passport/back/index.html')); | 359 | res.redirect(helpers.urlFormat('/passport/back/index.html')); |
360 | } | 360 | } |
361 | }; | 361 | }; |
362 | + |
@@ -4,38 +4,40 @@ | @@ -4,38 +4,40 @@ | ||
4 | 4 | ||
5 | 'use strict'; | 5 | 'use strict'; |
6 | 6 | ||
7 | -const _ = require('lodash'); | ||
8 | const library = '../../../library'; | 7 | const library = '../../../library'; |
9 | const captcha = require('../models/captcha-service'); | 8 | const captcha = require('../models/captcha-service'); |
10 | const helpers = require(library + '/helpers'); | 9 | const helpers = require(library + '/helpers'); |
11 | 10 | ||
12 | -exports.validateAPI = (req, res, next) => { | 11 | +const validateAPI = (req, res, next) => { |
13 | let captchaToken = (req.body.verifyCode || '').toLowerCase(); | 12 | let captchaToken = (req.body.verifyCode || '').toLowerCase(); |
14 | 13 | ||
15 | if (captchaToken === req.session.captcha) { | 14 | if (captchaToken === req.session.captcha) { |
16 | - next(); | ||
17 | - return; | 15 | + return next(); |
18 | } else { | 16 | } else { |
19 | return res.json({ | 17 | return res.json({ |
20 | - code: 400, | 18 | + code : 400, |
21 | message: '您输入的验证码不正确!' | 19 | message: '您输入的验证码不正确!' |
22 | }); | 20 | }); |
23 | } | 21 | } |
24 | }; | 22 | }; |
25 | 23 | ||
26 | -exports.validatePage = (req, res, next) => { | 24 | +const validatePage = (req, res, next) => { |
27 | let captchaToken = (req.body.verifyCode || '').toLowerCase(); | 25 | let captchaToken = (req.body.verifyCode || '').toLowerCase(); |
28 | 26 | ||
29 | if (captchaToken === req.session.captcha) { | 27 | if (captchaToken === req.session.captcha) { |
30 | - next(); | ||
31 | - return; | 28 | + return next(); |
32 | } else { | 29 | } else { |
33 | return res.redirect(helpers.urlFormat('/passport/back/index.html')); | 30 | return res.redirect(helpers.urlFormat('/passport/back/index.html')); |
34 | } | 31 | } |
35 | }; | 32 | }; |
36 | 33 | ||
37 | -exports.generatePage = (req, res, next) => { | 34 | +const validate = (req, res, next) => { |
35 | + | ||
36 | +}; | ||
37 | + | ||
38 | +const generatePage = (req, res, next) => { | ||
38 | let len = req.query.len || 4; | 39 | let len = req.query.len || 4; |
40 | + | ||
39 | captcha.generateAsync(len) | 41 | captcha.generateAsync(len) |
40 | .then(result => { | 42 | .then(result => { |
41 | req.session.captcha = result.text.toLowerCase(); | 43 | req.session.captcha = result.text.toLowerCase(); |
@@ -44,3 +46,10 @@ exports.generatePage = (req, res, next) => { | @@ -44,3 +46,10 @@ exports.generatePage = (req, res, next) => { | ||
44 | }) | 46 | }) |
45 | .catch(next); | 47 | .catch(next); |
46 | }; | 48 | }; |
49 | + | ||
50 | +module.exports = { | ||
51 | + validateAPI, | ||
52 | + validatePage, | ||
53 | + validate, | ||
54 | + generatePage, | ||
55 | +}; |
@@ -2,15 +2,10 @@ | @@ -2,15 +2,10 @@ | ||
2 | * Created by TaoHuang on 2016/6/15. | 2 | * Created by TaoHuang on 2016/6/15. |
3 | */ | 3 | */ |
4 | 4 | ||
5 | -/** | ||
6 | - * Created by Tao.Huang on 2016/6/14. | ||
7 | - */ | ||
8 | - | ||
9 | 'use strict'; | 5 | 'use strict'; |
10 | 6 | ||
11 | -var API = require('../../../library/api').API; | 7 | +var API = require('../../../library/api').API; |
12 | const library = '../../../library'; | 8 | const library = '../../../library'; |
13 | -const sign = require(`${library}/sign`); | ||
14 | 9 | ||
15 | var api = new API(); | 10 | var api = new API(); |
16 | 11 | ||
@@ -19,10 +14,10 @@ const YOHOBUY_URL = 'http://www.yohobuy.com/'; | @@ -19,10 +14,10 @@ const YOHOBUY_URL = 'http://www.yohobuy.com/'; | ||
19 | /** | 14 | /** |
20 | * 获取地区数据 | 15 | * 获取地区数据 |
21 | */ | 16 | */ |
22 | -module.exports.getAreaDataAsync = () => { | ||
23 | - return api.get('', sign.apiSign({ | 17 | +const getAreaDataAsync = () => { |
18 | + return api.get('', { | ||
24 | method: 'app.passport.getArea' | 19 | method: 'app.passport.getArea' |
25 | - })).then(result => { | 20 | + }).then(result => { |
26 | result.data = result.data.map(value => { | 21 | result.data = result.data.map(value => { |
27 | value.areaCode = `+${value.area}`; | 22 | value.areaCode = `+${value.area}`; |
28 | 23 | ||
@@ -45,11 +40,11 @@ module.exports.getAreaDataAsync = () => { | @@ -45,11 +40,11 @@ module.exports.getAreaDataAsync = () => { | ||
45 | * | 40 | * |
46 | * @param string mail 邮箱地址 | 41 | * @param string mail 邮箱地址 |
47 | */ | 42 | */ |
48 | -module.exports.sendCodeToEmailAsync = (email) => { | ||
49 | - return api.get('', sign.apiSign({ | 43 | +const sendCodeToEmailAsync = (email) => { |
44 | + return api.get('', { | ||
50 | method: 'app.register.backpwdByEmail', | 45 | method: 'app.register.backpwdByEmail', |
51 | - email: email | ||
52 | - })); | 46 | + email : email |
47 | + }); | ||
53 | }; | 48 | }; |
54 | 49 | ||
55 | /** | 50 | /** |
@@ -58,13 +53,13 @@ module.exports.sendCodeToEmailAsync = (email) => { | @@ -58,13 +53,13 @@ module.exports.sendCodeToEmailAsync = (email) => { | ||
58 | * @param string pwd 新密码 | 53 | * @param string pwd 新密码 |
59 | * @param string code 邮箱验证码 | 54 | * @param string code 邮箱验证码 |
60 | */ | 55 | */ |
61 | -module.exports.modifyPasswordByEmailAsync = (pwd, code) => { | 56 | +const modifyPasswordByEmailAsync = (pwd, code) => { |
62 | const options = { | 57 | const options = { |
63 | - url: `${YOHOBUY_URL}passport/back/update`, | ||
64 | - form: { | ||
65 | - pwd: pwd, | 58 | + url : `${YOHOBUY_URL}passport/back/update`, |
59 | + form : { | ||
60 | + pwd : pwd, | ||
66 | 're-input': pwd, | 61 | 're-input': pwd, |
67 | - code: code | 62 | + code : code |
68 | }, | 63 | }, |
69 | timeout: 3000 | 64 | timeout: 3000 |
70 | }; | 65 | }; |
@@ -78,14 +73,14 @@ module.exports.modifyPasswordByEmailAsync = (pwd, code) => { | @@ -78,14 +73,14 @@ module.exports.modifyPasswordByEmailAsync = (pwd, code) => { | ||
78 | * @param string mobile 手机号 | 73 | * @param string mobile 手机号 |
79 | * @param integer area 地区码ID | 74 | * @param integer area 地区码ID |
80 | */ | 75 | */ |
81 | -module.exports.sendCodeToMobileAsync = (mobile, area) => { | 76 | +const sendCodeToMobileAsync = (mobile, area) => { |
82 | area = area || 86; | 77 | area = area || 86; |
83 | 78 | ||
84 | - return api.get('', sign.apiSign({ | 79 | + return api.get('', { |
85 | mobile: mobile, | 80 | mobile: mobile, |
86 | - area: area, | 81 | + area : area, |
87 | method: 'app.register.sendBackpwdCodeToMobile' | 82 | method: 'app.register.sendBackpwdCodeToMobile' |
88 | - })); | 83 | + }); |
89 | }; | 84 | }; |
90 | 85 | ||
91 | /** | 86 | /** |
@@ -95,14 +90,14 @@ module.exports.sendCodeToMobileAsync = (mobile, area) => { | @@ -95,14 +90,14 @@ module.exports.sendCodeToMobileAsync = (mobile, area) => { | ||
95 | * @param string code 验证码 | 90 | * @param string code 验证码 |
96 | * @param integer area 地区码ID | 91 | * @param integer area 地区码ID |
97 | */ | 92 | */ |
98 | -module.exports.validateMobileCodeAsync = (mobile, code, area) => { | 93 | +const validateMobileCodeAsync = (mobile, code, area) => { |
99 | area = area || 86; | 94 | area = area || 86; |
100 | - return api.get('', sign.apiSign({ | 95 | + return api.get('', { |
101 | mobile: mobile, | 96 | mobile: mobile, |
102 | - code: code, | ||
103 | - area: area, | 97 | + code : code, |
98 | + area : area, | ||
104 | method: 'app.register.validBackpwdCode' | 99 | method: 'app.register.validBackpwdCode' |
105 | - })); | 100 | + }); |
106 | }; | 101 | }; |
107 | 102 | ||
108 | /** | 103 | /** |
@@ -112,34 +107,45 @@ module.exports.validateMobileCodeAsync = (mobile, code, area) => { | @@ -112,34 +107,45 @@ module.exports.validateMobileCodeAsync = (mobile, code, area) => { | ||
112 | * @param string token 验证手机验证码返回的token | 107 | * @param string token 验证手机验证码返回的token |
113 | * @param integer area 地区码ID | 108 | * @param integer area 地区码ID |
114 | */ | 109 | */ |
115 | -module.exports.modifyPasswordByMobileAsync = (mobile, token, newpwd, area)=> { | 110 | +const modifyPasswordByMobileAsync = (mobile, token, newpwd, area)=> { |
116 | area = area || 86; | 111 | area = area || 86; |
117 | - return api.get('', sign.apiSign({ | 112 | + return api.get('', { |
118 | mobile: mobile, | 113 | mobile: mobile, |
119 | - token: token, | 114 | + token : token, |
120 | newpwd: newpwd, | 115 | newpwd: newpwd, |
121 | - area: area, | 116 | + area : area, |
122 | method: 'app.register.changepwdByMobileCode' | 117 | method: 'app.register.changepwdByMobileCode' |
123 | - })); | 118 | + }); |
124 | }; | 119 | }; |
125 | 120 | ||
126 | /** | 121 | /** |
127 | * 验证找回邮件code | 122 | * 验证找回邮件code |
128 | */ | 123 | */ |
129 | -module.exports.checkEmailCodeAsync = (code) => { | ||
130 | - return api.get('', sign.apiSign({ | ||
131 | - code: code, | 124 | +const checkEmailCodeAsync = (code) => { |
125 | + return api.get('', { | ||
126 | + code : code, | ||
132 | method: 'web.passport.checkCodeValid' | 127 | method: 'web.passport.checkCodeValid' |
133 | - })); | 128 | + }); |
134 | }; | 129 | }; |
135 | 130 | ||
136 | /** | 131 | /** |
137 | * 根据邮箱code修改密码 | 132 | * 根据邮箱code修改密码 |
138 | */ | 133 | */ |
139 | -module.exports.modifyPasswordByEmailCodeAsync = (code, password) => { | ||
140 | - return api.get('', sign.apiSign({ | ||
141 | - code: code, | 134 | +const modifyPasswordByEmailCodeAsync = (code, password) => { |
135 | + return api.get('', { | ||
136 | + code : code, | ||
142 | newPwd: password, | 137 | newPwd: password, |
143 | method: 'app.register.resetPwdByCode' | 138 | method: 'app.register.resetPwdByCode' |
144 | - })); | 139 | + }); |
140 | +}; | ||
141 | + | ||
142 | +module.exports = { | ||
143 | + getAreaDataAsync, | ||
144 | + sendCodeToEmailAsync, | ||
145 | + modifyPasswordByEmailAsync, | ||
146 | + sendCodeToMobileAsync, | ||
147 | + validateMobileCodeAsync, | ||
148 | + modifyPasswordByMobileAsync, | ||
149 | + checkEmailCodeAsync, | ||
150 | + modifyPasswordByEmailCodeAsync | ||
145 | }; | 151 | }; |
@@ -5,31 +5,31 @@ | @@ -5,31 +5,31 @@ | ||
5 | 'use strict'; | 5 | 'use strict'; |
6 | 6 | ||
7 | const helpers = require(`${library}/helpers`); | 7 | const helpers = require(`${library}/helpers`); |
8 | -const api = require('./back-api'); | 8 | +const api = require('./back-api'); |
9 | const Promise = require('bluebird'); | 9 | const Promise = require('bluebird'); |
10 | -const co = Promise.coroutine; | ||
11 | -const _ = require('lodash'); | ||
12 | -const moment = require('moment'); | 10 | +const co = Promise.coroutine; |
11 | +const _ = require('lodash'); | ||
12 | +const moment = require('moment'); | ||
13 | 13 | ||
14 | -const userService = require('./user-service'); | 14 | +const userService = require('./user-service'); |
15 | const passportHelper = require('./passport-helper'); | 15 | const passportHelper = require('./passport-helper'); |
16 | -const authHelper = require('./auth-helper'); | 16 | +const authHelper = require('./auth-helper'); |
17 | 17 | ||
18 | const BACK_LEFT_BANNER_CODE = '3bbaf502c447a2ddad60879042e286d8'; //找回密码左边的banner | 18 | const BACK_LEFT_BANNER_CODE = '3bbaf502c447a2ddad60879042e286d8'; //找回密码左边的banner |
19 | 19 | ||
20 | -module.exports.validateEmailOrMobileAsync = (userInput, areaCode) => { | 20 | +const validateEmailOrMobileAsync = (userInput, areaCode) => { |
21 | return new Promise(function (resolve, rejected) { | 21 | return new Promise(function (resolve, rejected) { |
22 | let result = {type: 'email', area: '', phone: ''}; | 22 | let result = {type: 'email', area: '', phone: ''}; |
23 | 23 | ||
24 | if (helpers.verifyEmail(userInput)) { | 24 | if (helpers.verifyEmail(userInput)) { |
25 | - result.type = 'email'; | ||
26 | - result.area = ''; | 25 | + result.type = 'email'; |
26 | + result.area = ''; | ||
27 | result.phone = userInput; | 27 | result.phone = userInput; |
28 | 28 | ||
29 | resolve(result); | 29 | resolve(result); |
30 | } else if (helpers.verifyAreaMobile(helpers.makeAreaMobile(areaCode, userInput))) { | 30 | } else if (helpers.verifyAreaMobile(helpers.makeAreaMobile(areaCode, userInput))) { |
31 | - result.type = 'mobile'; | ||
32 | - result.area = areaCode; | 31 | + result.type = 'mobile'; |
32 | + result.area = areaCode; | ||
33 | result.phone = userInput; | 33 | result.phone = userInput; |
34 | 34 | ||
35 | resolve(result); | 35 | resolve(result); |
@@ -40,16 +40,16 @@ module.exports.validateEmailOrMobileAsync = (userInput, areaCode) => { | @@ -40,16 +40,16 @@ module.exports.validateEmailOrMobileAsync = (userInput, areaCode) => { | ||
40 | 40 | ||
41 | }; | 41 | }; |
42 | 42 | ||
43 | -module.exports.findUserAsync = (type, phone, area) => { | 43 | +const findUserAsync = (type, phone, area) => { |
44 | return co(function * () { | 44 | return co(function * () { |
45 | const MESSAGE = { | 45 | const MESSAGE = { |
46 | mobile: '您输入的手机号码尚未注册!', | 46 | mobile: '您输入的手机号码尚未注册!', |
47 | - email: '您输入的邮件账户尚未注册!', | ||
48 | - ok: '验证成功' | 47 | + email : '您输入的邮件账户尚未注册!', |
48 | + ok : '验证成功' | ||
49 | }; | 49 | }; |
50 | 50 | ||
51 | const findBy = { | 51 | const findBy = { |
52 | - email: userService.findByEmailAsync, | 52 | + email : userService.findByEmailAsync, |
53 | mobile: userService.findByMobileAsync | 53 | mobile: userService.findByMobileAsync |
54 | }; | 54 | }; |
55 | 55 | ||
@@ -59,7 +59,7 @@ module.exports.findUserAsync = (type, phone, area) => { | @@ -59,7 +59,7 @@ module.exports.findUserAsync = (type, phone, area) => { | ||
59 | 59 | ||
60 | if (_.isEmpty(user)) { | 60 | if (_.isEmpty(user)) { |
61 | return { | 61 | return { |
62 | - code: 402, | 62 | + code : 402, |
63 | message: MESSAGE[type] | 63 | message: MESSAGE[type] |
64 | }; | 64 | }; |
65 | } | 65 | } |
@@ -68,7 +68,7 @@ module.exports.findUserAsync = (type, phone, area) => { | @@ -68,7 +68,7 @@ module.exports.findUserAsync = (type, phone, area) => { | ||
68 | })(); | 68 | })(); |
69 | }; | 69 | }; |
70 | 70 | ||
71 | -function sendCodeToEmailAsync(input) { | 71 | +const _sendCodeToEmailAsync = input => { |
72 | return api.sendCodeToEmailAsync(input).then(result => { | 72 | return api.sendCodeToEmailAsync(input).then(result => { |
73 | if (!result.code || result.code !== 200) { | 73 | if (!result.code || result.code !== 200) { |
74 | return Promise.reject('request error!'); | 74 | return Promise.reject('request error!'); |
@@ -80,7 +80,7 @@ function sendCodeToEmailAsync(input) { | @@ -80,7 +80,7 @@ function sendCodeToEmailAsync(input) { | ||
80 | }); | 80 | }); |
81 | } | 81 | } |
82 | 82 | ||
83 | -function sendCodeToMobileAsync(areaCode, userInput) { | 83 | +const _sendCodeToMobileAsync = (areaCode, userInput) => { |
84 | return api.sendCodeToMobileAsync(areaCode, userInput).then(result => { | 84 | return api.sendCodeToMobileAsync(areaCode, userInput).then(result => { |
85 | if (!result.code || result.code !== 200) { | 85 | if (!result.code || result.code !== 200) { |
86 | return Promise.reject('request error'); | 86 | return Promise.reject('request error'); |
@@ -92,10 +92,10 @@ function sendCodeToMobileAsync(areaCode, userInput) { | @@ -92,10 +92,10 @@ function sendCodeToMobileAsync(areaCode, userInput) { | ||
92 | }); | 92 | }); |
93 | } | 93 | } |
94 | 94 | ||
95 | -module.exports.sendCodeToUserAsync = (type, mobile, areaCode) => { | 95 | +const sendCodeToUserAsync = (type, mobile, areaCode) => { |
96 | let sendTo = { | 96 | let sendTo = { |
97 | - email: sendCodeToEmailAsync, | ||
98 | - mobile: sendCodeToMobileAsync | 97 | + email : _sendCodeToEmailAsync, |
98 | + mobile: _sendCodeToMobileAsync | ||
99 | }; | 99 | }; |
100 | 100 | ||
101 | return sendTo[type](mobile, areaCode); | 101 | return sendTo[type](mobile, areaCode); |
@@ -104,36 +104,36 @@ module.exports.sendCodeToUserAsync = (type, mobile, areaCode) => { | @@ -104,36 +104,36 @@ module.exports.sendCodeToUserAsync = (type, mobile, areaCode) => { | ||
104 | /** | 104 | /** |
105 | * 发送找回手机号短信 | 105 | * 发送找回手机号短信 |
106 | */ | 106 | */ |
107 | -module.exports.sendCodeToMobileAsync = (areaCode, mobile) => { | 107 | +const sendCodeToMobileAsync = (areaCode, mobile) => { |
108 | return api.sendCodeToMobileAsync(mobile, areaCode); | 108 | return api.sendCodeToMobileAsync(mobile, areaCode); |
109 | }; | 109 | }; |
110 | 110 | ||
111 | /** | 111 | /** |
112 | * 获得首页的数据 | 112 | * 获得首页的数据 |
113 | */ | 113 | */ |
114 | -module.exports.indexPageDataAsync = () => { | 114 | +const indexPageDataAsync = () => { |
115 | return co(function *() { | 115 | return co(function *() { |
116 | - let banner = yield passportHelper.getLeftBannerAsync(BACK_LEFT_BANNER_CODE); | 116 | + let banner = yield passportHelper.getLeftBannerAsync(BACK_LEFT_BANNER_CODE); |
117 | let countryList = passportHelper.getCountry(); | 117 | let countryList = passportHelper.getCountry(); |
118 | 118 | ||
119 | return { | 119 | return { |
120 | back: { | 120 | back: { |
121 | - coverHref: banner.url, | ||
122 | - coverImg: banner.img, | 121 | + coverHref : banner.url, |
122 | + coverImg : banner.img, | ||
123 | countryCode: 86, | 123 | countryCode: 86, |
124 | countryName: "中国", | 124 | countryName: "中国", |
125 | - captchaUrl: helpers.urlFormat('/passport/images', {t: moment().unix()}), | 125 | + captchaUrl : helpers.urlFormat('/passport/images', {t: moment().unix()}), |
126 | countryList: countryList | 126 | countryList: countryList |
127 | } | 127 | } |
128 | } | 128 | } |
129 | })(); | 129 | })(); |
130 | }; | 130 | }; |
131 | 131 | ||
132 | -module.exports.verifyCodyByMobileAsync = (area, mobile, mobileCode) => { | 132 | +const verifyCodyByMobileAsync = (area, mobile, mobileCode) => { |
133 | const ERR = { | 133 | const ERR = { |
134 | - code: 400, | 134 | + code : 400, |
135 | message: '验证码错误!', | 135 | message: '验证码错误!', |
136 | - data: helpers.urlFormat('/passport/back/index.html') | 136 | + data : helpers.urlFormat('/passport/back/index.html') |
137 | }; | 137 | }; |
138 | 138 | ||
139 | api.validateMobileCodeAsync(mobile, mobileCode, area) | 139 | api.validateMobileCodeAsync(mobile, mobileCode, area) |
@@ -143,29 +143,28 @@ module.exports.verifyCodyByMobileAsync = (area, mobile, mobileCode) => { | @@ -143,29 +143,28 @@ module.exports.verifyCodyByMobileAsync = (area, mobile, mobileCode) => { | ||
143 | } | 143 | } |
144 | 144 | ||
145 | let data = { | 145 | let data = { |
146 | - mobile: mobile, | ||
147 | - area: area, | ||
148 | - token: result.data.token, | 146 | + mobile : mobile, |
147 | + area : area, | ||
148 | + token : result.data.token, | ||
149 | create_time: moment().unix() | 149 | create_time: moment().unix() |
150 | }; | 150 | }; |
151 | 151 | ||
152 | data.code = new Buffer(authHelper.makeToken(data)).toString('base64'); | 152 | data.code = new Buffer(authHelper.makeToken(data)).toString('base64'); |
153 | - | ||
154 | return { | 153 | return { |
155 | - code: 200, | 154 | + code : 200, |
156 | message: '验证成功', | 155 | message: '验证成功', |
157 | - data: helpers.urlFormat('/passport/back/backcode', data) | 156 | + data : helpers.urlFormat('/passport/back/backcode', data) |
158 | }; | 157 | }; |
159 | }) | 158 | }) |
160 | 159 | ||
161 | }; | 160 | }; |
162 | 161 | ||
163 | -module.exports.authRequest = (data, token) => { | 162 | +const authRequest = (data, token) => { |
164 | if (!authHelper.validateToken(data, token)) { | 163 | if (!authHelper.validateToken(data, token)) { |
165 | return {}; | 164 | return {}; |
166 | } | 165 | } |
167 | - let existTime = moment.duration(1, 'hours').seconds(); | ||
168 | 166 | ||
167 | + let existTime = moment.duration(1, 'hours').seconds(); | ||
169 | let isExpired = (moment().unix() - data.create_time) > existTime; | 168 | let isExpired = (moment().unix() - data.create_time) > existTime; |
170 | 169 | ||
171 | if (isExpired) { | 170 | if (isExpired) { |
@@ -175,44 +174,49 @@ module.exports.authRequest = (data, token) => { | @@ -175,44 +174,49 @@ module.exports.authRequest = (data, token) => { | ||
175 | } | 174 | } |
176 | }; | 175 | }; |
177 | 176 | ||
178 | -module.exports.updatePwdAsync = (emailToken, mobileToken, newPassword) => { | 177 | +const updatePwdAsync = (emailToken, mobileToken, newPassword) => { |
179 | return co(function * () { | 178 | return co(function * () { |
180 | let result = {type: 'mobile', status: false}; | 179 | let result = {type: 'mobile', status: false}; |
181 | - | ||
182 | - const ERR = {type: '', status: false}; | 180 | + const ERR = {type: '', status: false}; |
183 | 181 | ||
184 | if (!_.isEmpty(mobileToken)) { | 182 | if (!_.isEmpty(mobileToken)) { |
185 | if (!mobileToken.mobile || mobileToken.uid) { | 183 | if (!mobileToken.mobile || mobileToken.uid) { |
186 | return ERR; | 184 | return ERR; |
187 | } | 185 | } |
188 | 186 | ||
189 | - let mobile = mobileToken.mobile; | ||
190 | - | ||
191 | - let area = mobileToken.area; | ||
192 | - | ||
193 | - let token = mobileToken.token; | 187 | + let mobile = mobileToken.mobile; |
188 | + let area = mobileToken.area; | ||
189 | + let token = mobileToken.token; | ||
190 | + let modifyStatus = yield api.modifyPasswordByMobileAsync(mobile, token, newPassword, area); | ||
194 | 191 | ||
195 | - let data = yield api.modifyPasswordByMobileAsync(mobile, token, newPassword, area); | ||
196 | - | ||
197 | - if (!data.code || data.code !== 200) { | 192 | + if (!modifyStatus.code || modifyStatus.code !== 200) { |
198 | return ERR; | 193 | return ERR; |
199 | } | 194 | } |
200 | 195 | ||
201 | - result.type = 'mobile'; | 196 | + result.type = 'mobile'; |
202 | result.status = true; | 197 | result.status = true; |
203 | - | ||
204 | } else { | 198 | } else { |
205 | - let data = yield api.modifyPasswordByEmailCodeAsync(emailToken, newPassword); | 199 | + let modifyStatus = yield api.modifyPasswordByEmailCodeAsync(emailToken, newPassword); |
206 | 200 | ||
207 | - if (!data.code || data.code !== 200) { | 201 | + if (!modifyStatus.code || modifyStatus.code !== 200) { |
208 | return ERR; | 202 | return ERR; |
209 | } | 203 | } |
210 | 204 | ||
211 | - result.type = 'email'; | 205 | + result.type = 'email'; |
212 | result.status = true; | 206 | result.status = true; |
213 | } | 207 | } |
214 | 208 | ||
215 | return result; | 209 | return result; |
216 | - | ||
217 | })(); | 210 | })(); |
218 | }; | 211 | }; |
212 | + | ||
213 | +module.exports = { | ||
214 | + validateEmailOrMobileAsync, | ||
215 | + findUserAsync, | ||
216 | + sendCodeToUserAsync, | ||
217 | + sendCodeToMobileAsync, | ||
218 | + indexPageDataAsync, | ||
219 | + verifyCodyByMobileAsync, | ||
220 | + authRequest, | ||
221 | + updatePwdAsync | ||
222 | +}; |
@@ -7,7 +7,7 @@ const Promise = require('bluebird'); | @@ -7,7 +7,7 @@ const Promise = require('bluebird'); | ||
7 | const co = Promise.coroutine; | 7 | const co = Promise.coroutine; |
8 | const fs = require('fs'); | 8 | const fs = require('fs'); |
9 | 9 | ||
10 | -module.exports.generateAsync = () => { | 10 | +const generateAsync = () => { |
11 | const path = './fake_captcha_mer2.png'; | 11 | const path = './fake_captcha_mer2.png'; |
12 | 12 | ||
13 | const readFileAsync = Promise.promisify(fs.readFile); | 13 | const readFileAsync = Promise.promisify(fs.readFile); |
@@ -22,3 +22,7 @@ module.exports.generateAsync = () => { | @@ -22,3 +22,7 @@ module.exports.generateAsync = () => { | ||
22 | } | 22 | } |
23 | })(); | 23 | })(); |
24 | }; | 24 | }; |
25 | + | ||
26 | +module.exports = { | ||
27 | + generateAsync | ||
28 | +}; |
@@ -3,15 +3,11 @@ | @@ -3,15 +3,11 @@ | ||
3 | */ | 3 | */ |
4 | 'use strict'; | 4 | 'use strict'; |
5 | 5 | ||
6 | -const library = '../../../library'; | ||
7 | -var ServiceAPI = require(library + "/api").ServiceAPI; | ||
8 | -const sign = require(`${library}/sign`); | ||
9 | -const _ = require('lodash'); | ||
10 | - | ||
11 | -var serviceAPI = new ServiceAPI(); | 6 | +const ServiceAPI = require(library + "/api").ServiceAPI; |
7 | +const serviceAPI = new ServiceAPI(); | ||
12 | 8 | ||
13 | module.exports.getResourceAsync = (resourceCode) => { | 9 | module.exports.getResourceAsync = (resourceCode) => { |
14 | - return serviceAPI.get('/operations/api/v5/resource/get', sign.apiSign({ | 10 | + return serviceAPI.get('/operations/api/v5/resource/get', { |
15 | content_code: resourceCode | 11 | content_code: resourceCode |
16 | - }), true); | 12 | + }); |
17 | }; | 13 | }; |
@@ -12,7 +12,8 @@ module.exports.getResourceAsync = (resourceCode) => { | @@ -12,7 +12,8 @@ module.exports.getResourceAsync = (resourceCode) => { | ||
12 | } else { | 12 | } else { |
13 | return {}; | 13 | return {}; |
14 | } | 14 | } |
15 | - }).catch(() => { | 15 | + }) |
16 | + .catch(() => { | ||
16 | return {}; | 17 | return {}; |
17 | }); | 18 | }); |
18 | }; | 19 | }; |
@@ -7,8 +7,8 @@ | @@ -7,8 +7,8 @@ | ||
7 | 7 | ||
8 | const helpers = require(library + '/helpers'); | 8 | const helpers = require(library + '/helpers'); |
9 | const Promise = require('bluebird'); | 9 | const Promise = require('bluebird'); |
10 | -const co = Promise.coroutine; | ||
11 | -const _ = require('lodash'); | 10 | +const co = Promise.coroutine; |
11 | +const _ = require('lodash'); | ||
12 | 12 | ||
13 | const indexService = require('./index-service'); | 13 | const indexService = require('./index-service'); |
14 | 14 | ||
@@ -20,7 +20,6 @@ module.exports.getLeftBannerAsync = (resourceCode) => { | @@ -20,7 +20,6 @@ module.exports.getLeftBannerAsync = (resourceCode) => { | ||
20 | }; | 20 | }; |
21 | 21 | ||
22 | return co(function * () { | 22 | return co(function * () { |
23 | - | ||
24 | let resource = yield indexService.getResourceAsync(resourceCode); | 23 | let resource = yield indexService.getResourceAsync(resourceCode); |
25 | 24 | ||
26 | if (_.isEmpty(resource)) { | 25 | if (_.isEmpty(resource)) { |
@@ -41,62 +40,62 @@ module.exports.getCountry = () => { | @@ -41,62 +40,62 @@ module.exports.getCountry = () => { | ||
41 | { | 40 | { |
42 | areaCode: '+61', | 41 | areaCode: '+61', |
43 | selected: false, | 42 | selected: false, |
44 | - name: '澳大利亚' | 43 | + name : '澳大利亚' |
45 | }, | 44 | }, |
46 | { | 45 | { |
47 | areaCode: '+82', | 46 | areaCode: '+82', |
48 | selected: false, | 47 | selected: false, |
49 | - name: '韩国' | 48 | + name : '韩国' |
50 | }, | 49 | }, |
51 | { | 50 | { |
52 | areaCode: '+1', | 51 | areaCode: '+1', |
53 | selected: false, | 52 | selected: false, |
54 | - name: '加拿大' | 53 | + name : '加拿大' |
55 | }, | 54 | }, |
56 | { | 55 | { |
57 | areaCode: '+60', | 56 | areaCode: '+60', |
58 | selected: false, | 57 | selected: false, |
59 | - name: '马来西亚' | 58 | + name : '马来西亚' |
60 | }, | 59 | }, |
61 | { | 60 | { |
62 | areaCode: '+1', | 61 | areaCode: '+1', |
63 | selected: false, | 62 | selected: false, |
64 | - name: '美国' | 63 | + name : '美国' |
65 | }, | 64 | }, |
66 | { | 65 | { |
67 | areaCode: '+81', | 66 | areaCode: '+81', |
68 | selected: false, | 67 | selected: false, |
69 | - name: '日本' | 68 | + name : '日本' |
70 | }, | 69 | }, |
71 | { | 70 | { |
72 | areaCode: '+65', | 71 | areaCode: '+65', |
73 | selected: false, | 72 | selected: false, |
74 | - name: '新加坡' | 73 | + name : '新加坡' |
75 | }, | 74 | }, |
76 | { | 75 | { |
77 | areaCode: '+44', | 76 | areaCode: '+44', |
78 | selected: false, | 77 | selected: false, |
79 | - name: '英国' | 78 | + name : '英国' |
80 | }, | 79 | }, |
81 | { | 80 | { |
82 | areaCode: '+86', | 81 | areaCode: '+86', |
83 | selected: true, | 82 | selected: true, |
84 | - name: '中国' | 83 | + name : '中国' |
85 | }, | 84 | }, |
86 | { | 85 | { |
87 | areaCode: '+853', | 86 | areaCode: '+853', |
88 | selected: false, | 87 | selected: false, |
89 | - name: '中国澳门' | 88 | + name : '中国澳门' |
90 | }, | 89 | }, |
91 | { | 90 | { |
92 | areaCode: '+886', | 91 | areaCode: '+886', |
93 | selected: false, | 92 | selected: false, |
94 | - name: '中国台湾' | 93 | + name : '中国台湾' |
95 | }, | 94 | }, |
96 | { | 95 | { |
97 | areaCode: '+852', | 96 | areaCode: '+852', |
98 | selected: false, | 97 | selected: false, |
99 | - name: '中国香港' | 98 | + name : '中国香港' |
100 | } | 99 | } |
101 | ]; | 100 | ]; |
102 | }; | 101 | }; |
@@ -4,49 +4,56 @@ | @@ -4,49 +4,56 @@ | ||
4 | 'use strict'; | 4 | 'use strict'; |
5 | 5 | ||
6 | const library = '../../../library'; | 6 | const library = '../../../library'; |
7 | -var API = require('../../../library/api').API; | ||
8 | -const sign = require(`${library}/sign`); | ||
9 | -const _ = require('lodash'); | ||
10 | - | ||
11 | -var api = new API(); | 7 | +const API = require('../../../library/api').API; |
8 | +const _ = require('lodash'); | ||
12 | 9 | ||
10 | +const api = new API(); | ||
13 | const EMPTY = {}; | 11 | const EMPTY = {}; |
14 | 12 | ||
15 | /** | 13 | /** |
16 | * 根据手机号获取用户信息 | 14 | * 根据手机号获取用户信息 |
17 | */ | 15 | */ |
18 | -module.exports.findByMobileAsync = (area, mobile) => { | ||
19 | - return api.get('', sign.apiSign({ | ||
20 | - mobile: mobile, | ||
21 | - area: area, | ||
22 | - method: 'app.passport.getProfileByMobile' | ||
23 | - })).then(result => { | ||
24 | - if (!result.code || result.code !== 200 || !result.data || _.isEmpty(result.data)) { | 16 | +const findByMobileAsync = (area, mobile) => { |
17 | + return api.get('', { | ||
18 | + mobile: mobile, | ||
19 | + area : area, | ||
20 | + method: 'app.passport.getProfileByMobile' | ||
21 | + }) | ||
22 | + .then(result => { | ||
23 | + if (!result.code || result.code !== 200 || !result.data || _.isEmpty(result.data)) { | ||
24 | + return EMPTY; | ||
25 | + } | ||
26 | + | ||
27 | + return result.data; | ||
28 | + | ||
29 | + }) | ||
30 | + .catch(() => { | ||
25 | return EMPTY; | 31 | return EMPTY; |
26 | - } | ||
27 | - | ||
28 | - return result.data; | ||
29 | - | ||
30 | - }).catch(() => { | ||
31 | - return EMPTY; | ||
32 | - }); | 32 | + }); |
33 | }; | 33 | }; |
34 | 34 | ||
35 | /** | 35 | /** |
36 | * 根据邮箱获取用户信息 | 36 | * 根据邮箱获取用户信息 |
37 | */ | 37 | */ |
38 | -module.exports.findByEmailAsync = (email) => { | ||
39 | - return api.get('', sign.apiSign({ | ||
40 | - email: email, | ||
41 | - method: 'app.passport.getProfileByEmail' | ||
42 | - })).then(result => { | ||
43 | - if (!result.code || result.code !== 200 || !result.data || _.isEmpty(result.data)) { | 38 | +const findByEmailAsync = (email) => { |
39 | + return api.get('', { | ||
40 | + email : email, | ||
41 | + method: 'app.passport.getProfileByEmail' | ||
42 | + }) | ||
43 | + .then(result => { | ||
44 | + if (!result.code || result.code !== 200 || !result.data || _.isEmpty(result.data)) { | ||
45 | + return EMPTY; | ||
46 | + } | ||
47 | + | ||
48 | + return result.data; | ||
49 | + | ||
50 | + }) | ||
51 | + .catch(() => { | ||
44 | return EMPTY; | 52 | return EMPTY; |
45 | - } | ||
46 | - | ||
47 | - return result.data; | 53 | + }); |
54 | +}; | ||
48 | 55 | ||
49 | - }).catch(() => { | ||
50 | - return EMPTY; | ||
51 | - }); | 56 | +module.exports = { |
57 | + findByMobileAsync, | ||
58 | + findByEmailAsync | ||
52 | }; | 59 | }; |
@@ -7,11 +7,11 @@ | @@ -7,11 +7,11 @@ | ||
7 | 'use strict'; | 7 | 'use strict'; |
8 | 8 | ||
9 | const express = require('express'); | 9 | const express = require('express'); |
10 | -const cRoot = './controllers'; | ||
11 | -const login = require(cRoot + '/login'); | 10 | +const cRoot = './controllers'; |
11 | +const login = require(cRoot + '/login'); | ||
12 | 12 | ||
13 | const Captcha = require(cRoot + '/captcha'); | 13 | const Captcha = require(cRoot + '/captcha'); |
14 | -const Back = require(cRoot + '/back'); | 14 | +const Back = require(cRoot + '/back'); |
15 | 15 | ||
16 | const router = express.Router(); // eslint-disable-line | 16 | const router = express.Router(); // eslint-disable-line |
17 | 17 | ||
@@ -25,47 +25,78 @@ router.get('/login/wechat/callback', login.wechat.callback); | @@ -25,47 +25,78 @@ router.get('/login/wechat/callback', login.wechat.callback); | ||
25 | router.get('/back/index.html', Back.indexPage); | 25 | router.get('/back/index.html', Back.indexPage); |
26 | 26 | ||
27 | // 实时验证输入是否正确 | 27 | // 实时验证输入是否正确 |
28 | -router.post('/back/authcode', Captcha.validateAPI, Back.validateInputAPI, Back.getUserInfoAPI); | 28 | +router.post('/back/authcode', |
29 | + Captcha.validateAPI, | ||
30 | + Back.validateInputAPI, | ||
31 | + Back.getUserInfoAPI); | ||
29 | 32 | ||
30 | // 提交按钮邮件API | 33 | // 提交按钮邮件API |
31 | -router.post('/back/email', Captcha.validatePage, Back.validateUserPage, Back.sendCodePage, Back.saveInSession); | 34 | +router.post('/back/email', |
35 | + Captcha.validatePage, | ||
36 | + Back.validateUserPage, | ||
37 | + Back.sendCodePage, | ||
38 | + Back.saveInSession); | ||
32 | 39 | ||
33 | // 提交按钮手机API | 40 | // 提交按钮手机API |
34 | -router.post('/back/mobile', Captcha.validatePage, Back.validateUserPage, Back.sendCodePage, Back.saveInSession); | 41 | +router.post('/back/mobile', |
42 | + Captcha.validatePage, | ||
43 | + Back.validateUserPage, | ||
44 | + Back.sendCodePage, | ||
45 | + Back.saveInSession); | ||
35 | 46 | ||
36 | /** | 47 | /** |
37 | * 邮件找回密码 | 48 | * 邮件找回密码 |
38 | */ | 49 | */ |
39 | // 发送邮件成功页面 | 50 | // 发送邮件成功页面 |
40 | -router.get('/back/sendEmail.html', Back.validateEmailInSession, Back.sendEmailPage); | 51 | +router.get('/back/sendEmail.html', |
52 | + Back.validateEmailInSession, | ||
53 | + Back.sendEmailPage); | ||
41 | 54 | ||
42 | /** | 55 | /** |
43 | * 短信找回密码 | 56 | * 短信找回密码 |
44 | */ | 57 | */ |
45 | // 验证手机短信页面 | 58 | // 验证手机短信页面 |
46 | -router.get('/back/verification.html', Back.validateMobileInSession, Captcha.validatePage, Back.verifyCodeByMobilePage); | 59 | +router.get('/back/verification.html', |
60 | + Back.validateMobileInSession, | ||
61 | + Captcha.validatePage, | ||
62 | + Back.verifyCodeByMobilePage); | ||
47 | 63 | ||
48 | // 重新发送短信接口 | 64 | // 重新发送短信接口 |
49 | -router.post('/back/sendBackMobile', Captcha.validateAPI, Back.validateMobileAPI, Back.sendBackMobileAPI); | 65 | +router.post('/back/sendBackMobile', |
66 | + Captcha.validateAPI, | ||
67 | + Back.validateMobileAPI, | ||
68 | + Back.sendBackMobileAPI); | ||
50 | 69 | ||
51 | // 验证手机验证码接口 | 70 | // 验证手机验证码接口 |
52 | -router.post('/back/backMobile', Captcha.validateAPI, Back.verifyCodeByMobileAPI); | 71 | +router.post('/back/backMobile', |
72 | + Captcha.validateAPI, | ||
73 | + Back.verifyCodeByMobileAPI); | ||
53 | 74 | ||
54 | /** | 75 | /** |
55 | * 重置密码 | 76 | * 重置密码 |
56 | */ | 77 | */ |
57 | // 重置密码页面 | 78 | // 重置密码页面 |
58 | -router.get('/back/backcode', Back.validateExistCodePage, Back.validateCodeByMobilePage, Back.validateCodeByEmailPage, Back.resetPasswordPage); | 79 | +router.get('/back/backcode', |
80 | + Back.validateExistCodePage, | ||
81 | + Back.validateCodeByMobilePage, | ||
82 | + Back.validateCodeByEmailPage, | ||
83 | + Back.resetPasswordPage); | ||
59 | 84 | ||
60 | // 重置密码接口 | 85 | // 重置密码接口 |
61 | -router.post('/back/update', Back.validateExistCodePage, Back.validateCodeByMobilePage, Back.validatePwdPage, Back.updatePwdAPI); | 86 | +router.post('/back/update', |
87 | + Back.validateExistCodePage, | ||
88 | + Back.validateCodeByMobilePage, | ||
89 | + Back.validatePwdPage, | ||
90 | + Back.updatePwdAPI); | ||
62 | 91 | ||
63 | // 重置密码成功页面 | 92 | // 重置密码成功页面 |
64 | -router.get('/back/resetSuccess.html', Back.checkSuccessStatusPage, Back.resetPwdSuccessPage); | 93 | +router.get('/back/resetSuccess.html', |
94 | + Back.checkSuccessStatusPage, | ||
95 | + Back.resetPwdSuccessPage); | ||
65 | 96 | ||
66 | /** | 97 | /** |
67 | * 验证码生成 | 98 | * 验证码生成 |
68 | */ | 99 | */ |
69 | -router.get('/images',Captcha.generatePage); | 100 | +router.get('/images', Captcha.generatePage); |
70 | 101 | ||
71 | module.exports = router; | 102 | module.exports = router; |
-
Please register or login to post a comment