|
@@ -10,20 +10,20 @@ const service = require('../models/back-service'); |
|
@@ -10,20 +10,20 @@ const service = require('../models/back-service'); |
10
|
const passportHelper = require('../models/passport-helper');
|
10
|
const passportHelper = require('../models/passport-helper');
|
11
|
const _ = require('lodash');
|
11
|
const _ = require('lodash');
|
12
|
|
12
|
|
13
|
-//helpers.urlFormat = (url, qs) => {
|
|
|
14
|
-// let localhost = 'http://localhost:6002';
|
|
|
15
|
-//
|
|
|
16
|
-// if (_.isEmpty(qs)) {
|
|
|
17
|
-// return localhost + url;
|
|
|
18
|
-// }
|
|
|
19
|
-//
|
|
|
20
|
-// const queryString = require('queryString');
|
|
|
21
|
-//
|
|
|
22
|
-// let str = queryString.stringify(qs);
|
|
|
23
|
-//
|
|
|
24
|
-// return localhost + url + '?' + str;
|
|
|
25
|
-//
|
|
|
26
|
-//};
|
13
|
+helpers.urlFormat = (url, qs) => {
|
|
|
14
|
+ let localhost = 'http://localhost:6002';
|
|
|
15
|
+
|
|
|
16
|
+ if (_.isEmpty(qs)) {
|
|
|
17
|
+ return localhost + url;
|
|
|
18
|
+ }
|
|
|
19
|
+
|
|
|
20
|
+ const queryString = require('queryString');
|
|
|
21
|
+
|
|
|
22
|
+ let str = queryString.stringify(qs);
|
|
|
23
|
+
|
|
|
24
|
+ return localhost + url + '?' + str;
|
|
|
25
|
+
|
|
|
26
|
+};
|
27
|
|
27
|
|
28
|
/**
|
28
|
/**
|
29
|
* 找回密码主页面
|
29
|
* 找回密码主页面
|
|
@@ -33,8 +33,8 @@ const index = (req, res, next) => { |
|
@@ -33,8 +33,8 @@ const index = (req, res, next) => { |
33
|
.then(result => {
|
33
|
.then(result => {
|
34
|
res.render('back/index', Object.assign({
|
34
|
res.render('back/index', Object.assign({
|
35
|
module: 'passport',
|
35
|
module: 'passport',
|
36
|
- page : 'back-index',
|
|
|
37
|
- title : '找回密码'
|
36
|
+ page: 'back-index',
|
|
|
37
|
+ title: '找回密码'
|
38
|
}, result));
|
38
|
}, result));
|
39
|
})
|
39
|
})
|
40
|
.catch(next);
|
40
|
.catch(next);
|
|
@@ -54,7 +54,7 @@ const validateInputAPI = (req, res, next) => { |
|
@@ -54,7 +54,7 @@ const validateInputAPI = (req, res, next) => { |
54
|
})
|
54
|
})
|
55
|
.catch(err => {
|
55
|
.catch(err => {
|
56
|
res.json({
|
56
|
res.json({
|
57
|
- code : 400,
|
57
|
+ code: 400,
|
58
|
message: err
|
58
|
message: err
|
59
|
});
|
59
|
});
|
60
|
});
|
60
|
});
|
|
@@ -93,11 +93,11 @@ const sendCodePage = (req, res, next) => { |
|
@@ -93,11 +93,11 @@ const sendCodePage = (req, res, next) => { |
93
|
service.sendCodeToUserAsync(inputInfo.type, inputInfo.phone, inputInfo.area)
|
93
|
service.sendCodeToUserAsync(inputInfo.type, inputInfo.phone, inputInfo.area)
|
94
|
.then(result => {
|
94
|
.then(result => {
|
95
|
|
95
|
|
96
|
- if (result.code && result.code === 200) {
|
|
|
97
|
- return next();
|
|
|
98
|
- } else {
|
96
|
+ if (!(result.code && result.code === 200)) {
|
99
|
return res.redirect(helpers.urlFormat('/passport/back/index'));
|
97
|
return res.redirect(helpers.urlFormat('/passport/back/index'));
|
100
|
}
|
98
|
}
|
|
|
99
|
+
|
|
|
100
|
+ return next();
|
101
|
})
|
101
|
})
|
102
|
.catch(next);
|
102
|
.catch(next);
|
103
|
};
|
103
|
};
|
|
@@ -105,22 +105,22 @@ const sendCodePage = (req, res, next) => { |
|
@@ -105,22 +105,22 @@ const sendCodePage = (req, res, next) => { |
105
|
const saveInSession = (req, res) => {
|
105
|
const saveInSession = (req, res) => {
|
106
|
switch (req.inputInfo.type) {
|
106
|
switch (req.inputInfo.type) {
|
107
|
case 'email':
|
107
|
case 'email':
|
108
|
- {
|
|
|
109
|
- req.session.email = req.inputInfo.phone;
|
|
|
110
|
- res.redirect(helpers.urlFormat('/passport/back/sendEmail'));
|
|
|
111
|
- break;
|
|
|
112
|
- }
|
108
|
+ {
|
|
|
109
|
+ req.session.email = req.inputInfo.phone;
|
|
|
110
|
+ res.redirect(helpers.urlFormat('/passport/back/sendEmail'));
|
|
|
111
|
+ break;
|
|
|
112
|
+ }
|
113
|
case 'mobile':
|
113
|
case 'mobile':
|
114
|
- {
|
|
|
115
|
- req.session.mobile = req.inputInfo.phone;
|
|
|
116
|
- req.session.area = req.inputInfo.area;
|
|
|
117
|
- res.redirect(helpers.urlFormat('/passport/back/verification'));
|
|
|
118
|
- break;
|
|
|
119
|
- }
|
114
|
+ {
|
|
|
115
|
+ req.session.mobile = req.inputInfo.phone;
|
|
|
116
|
+ req.session.area = req.inputInfo.area;
|
|
|
117
|
+ res.redirect(helpers.urlFormat('/passport/back/verification'));
|
|
|
118
|
+ break;
|
|
|
119
|
+ }
|
120
|
default:
|
120
|
default:
|
121
|
- {
|
|
|
122
|
- res.redirect(helpers.urlFormat('/passport/back/index'));
|
|
|
123
|
- }
|
121
|
+ {
|
|
|
122
|
+ res.redirect(helpers.urlFormat('/passport/back/index'));
|
|
|
123
|
+ }
|
124
|
}
|
124
|
}
|
125
|
};
|
125
|
};
|
126
|
|
126
|
|
|
@@ -142,24 +142,23 @@ const validateMobileAPI = (req, res, next) => { |
|
@@ -142,24 +142,23 @@ const validateMobileAPI = (req, res, next) => { |
142
|
|
142
|
|
143
|
if (!passportHelper.validator.isAreaMobile(passportHelper.makeAreaMobile(area, mobile))) {
|
143
|
if (!passportHelper.validator.isAreaMobile(passportHelper.makeAreaMobile(area, mobile))) {
|
144
|
return res.json(ERR);
|
144
|
return res.json(ERR);
|
145
|
- } else {
|
|
|
146
|
- return next();
|
|
|
147
|
}
|
145
|
}
|
|
|
146
|
+
|
|
|
147
|
+ next();
|
148
|
};
|
148
|
};
|
149
|
|
149
|
|
150
|
const validateEmailInSession = (req, res, next) => {
|
150
|
const validateEmailInSession = (req, res, next) => {
|
151
|
let email = req.session.email || '';
|
151
|
let email = req.session.email || '';
|
152
|
|
152
|
|
153
|
if (!email) {
|
153
|
if (!email) {
|
154
|
- res.redirect(helpers.urlFormat('/passport/back/index'));
|
154
|
+ return res.redirect(helpers.urlFormat('/passport/back/index'));
|
155
|
}
|
155
|
}
|
156
|
|
156
|
|
|
|
157
|
+ let isp = email.split('@')[1];
|
157
|
const mapperEmailISP = {
|
158
|
const mapperEmailISP = {
|
158
|
'yoho.cn': 'http://smail.yoho.cn'
|
159
|
'yoho.cn': 'http://smail.yoho.cn'
|
159
|
};
|
160
|
};
|
160
|
|
161
|
|
161
|
- let isp = email.split('@')[1];
|
|
|
162
|
-
|
|
|
163
|
req.body.emailUrl = mapperEmailISP[isp] || `http://mail.${isp}`;
|
162
|
req.body.emailUrl = mapperEmailISP[isp] || `http://mail.${isp}`;
|
164
|
next();
|
163
|
next();
|
165
|
};
|
164
|
};
|
|
@@ -169,13 +168,13 @@ const sendEmailPage = (req, res, next) => { |
|
@@ -169,13 +168,13 @@ const sendEmailPage = (req, res, next) => { |
169
|
.then(result => {
|
168
|
.then(result => {
|
170
|
res.render('back/send-email', Object.assign({
|
169
|
res.render('back/send-email', Object.assign({
|
171
|
module: 'passport',
|
170
|
module: 'passport',
|
172
|
- page : 'back-send-email-ok',
|
|
|
173
|
- title : '邮件发送成功'
|
171
|
+ page: 'back-send-email-ok',
|
|
|
172
|
+ title: '邮件发送成功'
|
174
|
}, {
|
173
|
}, {
|
175
|
sendEmail: {
|
174
|
sendEmail: {
|
176
|
coverHref: result.url,
|
175
|
coverHref: result.url,
|
177
|
- coverImg : result.img,
|
|
|
178
|
- email : req.body.emailUrl
|
176
|
+ coverImg: result.img,
|
|
|
177
|
+ email: req.body.emailUrl
|
179
|
}
|
178
|
}
|
180
|
}));
|
179
|
}));
|
181
|
})
|
180
|
})
|
|
@@ -187,8 +186,7 @@ const validateCodeByEmailPage = (req, res, next) => { |
|
@@ -187,8 +186,7 @@ const validateCodeByEmailPage = (req, res, next) => { |
187
|
let code = req.query.code || '';
|
186
|
let code = req.query.code || '';
|
188
|
|
187
|
|
189
|
if (!_.isEmpty(req.mobileAuth)) {
|
188
|
if (!_.isEmpty(req.mobileAuth)) {
|
190
|
- next();
|
|
|
191
|
- return;
|
189
|
+ return next();
|
192
|
}
|
190
|
}
|
193
|
|
191
|
|
194
|
service.checkEmailCodeAsync(code)
|
192
|
service.checkEmailCodeAsync(code)
|
|
@@ -209,13 +207,13 @@ const resetPasswordPage = (req, res, next) => { |
|
@@ -209,13 +207,13 @@ const resetPasswordPage = (req, res, next) => { |
209
|
.then(result => {
|
207
|
.then(result => {
|
210
|
res.render('back/reset-pwd', Object.assign({
|
208
|
res.render('back/reset-pwd', Object.assign({
|
211
|
module: 'passport',
|
209
|
module: 'passport',
|
212
|
- page : 'back-reset-pwd',
|
|
|
213
|
- title : '重置密码'
|
210
|
+ page: 'back-reset-pwd',
|
|
|
211
|
+ title: '重置密码'
|
214
|
}, {
|
212
|
}, {
|
215
|
resetPwd: Object.assign({
|
213
|
resetPwd: Object.assign({
|
216
|
coverHref: result.url,
|
214
|
coverHref: result.url,
|
217
|
- coverImg : result.img,
|
|
|
218
|
- code : code
|
215
|
+ coverImg: result.img,
|
|
|
216
|
+ code: code
|
219
|
}, req.mobileAuth)
|
217
|
}, req.mobileAuth)
|
220
|
}));
|
218
|
}));
|
221
|
})
|
219
|
})
|
|
@@ -235,14 +233,14 @@ const verifyCodeByMobilePage = (req, res, next) => { |
|
@@ -235,14 +233,14 @@ const verifyCodeByMobilePage = (req, res, next) => { |
235
|
.then(result => {
|
233
|
.then(result => {
|
236
|
res.render('back/verification', Object.assign({
|
234
|
res.render('back/verification', Object.assign({
|
237
|
module: 'passport',
|
235
|
module: 'passport',
|
238
|
- page : 'back-verify-mobile-code',
|
|
|
239
|
- title : '手机验证'
|
236
|
+ page: 'back-verify-mobile-code',
|
|
|
237
|
+ title: '手机验证'
|
240
|
}, {
|
238
|
}, {
|
241
|
verification: {
|
239
|
verification: {
|
242
|
- coverHref : result.url,
|
|
|
243
|
- coverImg : result.img,
|
|
|
244
|
- mobile : req.body.mobile,
|
|
|
245
|
- area : req.body.area,
|
240
|
+ coverHref: result.url,
|
|
|
241
|
+ coverImg: result.img,
|
|
|
242
|
+ mobile: req.body.mobile,
|
|
|
243
|
+ area: req.body.area,
|
246
|
verifyCode: req.body.verifyCode
|
244
|
verifyCode: req.body.verifyCode
|
247
|
}
|
245
|
}
|
248
|
}));
|
246
|
}));
|
|
@@ -253,12 +251,12 @@ const verifyCodeByMobilePage = (req, res, next) => { |
|
@@ -253,12 +251,12 @@ const verifyCodeByMobilePage = (req, res, next) => { |
253
|
const checkSuccessStatusPage = (req, res, next) => {
|
251
|
const checkSuccessStatusPage = (req, res, next) => {
|
254
|
let successType = req.session.successType || '';
|
252
|
let successType = req.session.successType || '';
|
255
|
|
253
|
|
256
|
- if (successType) {
|
|
|
257
|
- delete req.session.successType;
|
|
|
258
|
- next();
|
|
|
259
|
- } else {
|
|
|
260
|
- res.redirect(helpers.urlFormat('/passport/back/index'));
|
254
|
+ if (!successType) {
|
|
|
255
|
+ return res.redirect(helpers.urlFormat('/passport/back/index'));
|
261
|
}
|
256
|
}
|
|
|
257
|
+
|
|
|
258
|
+ delete req.session.successType;
|
|
|
259
|
+ next();
|
262
|
};
|
260
|
};
|
263
|
|
261
|
|
264
|
const resetPwdSuccessPage = (req, res, next) => {
|
262
|
const resetPwdSuccessPage = (req, res, next) => {
|
|
@@ -266,12 +264,12 @@ const resetPwdSuccessPage = (req, res, next) => { |
|
@@ -266,12 +264,12 @@ const resetPwdSuccessPage = (req, res, next) => { |
266
|
.then(result => {
|
264
|
.then(result => {
|
267
|
res.render('back/reset-success', Object.assign({
|
265
|
res.render('back/reset-success', Object.assign({
|
268
|
module: 'passport',
|
266
|
module: 'passport',
|
269
|
- page : 'back-index',
|
|
|
270
|
- title : '重置密码成功'
|
267
|
+ page: 'back-index',
|
|
|
268
|
+ title: '重置密码成功'
|
271
|
}, {
|
269
|
}, {
|
272
|
resetSuccess: {
|
270
|
resetSuccess: {
|
273
|
coverHref: result.url,
|
271
|
coverHref: result.url,
|
274
|
- coverImg : result.img
|
272
|
+ coverImg: result.img
|
275
|
}
|
273
|
}
|
276
|
}));
|
274
|
}));
|
277
|
})
|
275
|
})
|
|
@@ -282,12 +280,13 @@ const verifyCodeByMobileAPI = (req, res) => { |
|
@@ -282,12 +280,13 @@ const verifyCodeByMobileAPI = (req, res) => { |
282
|
let mobile = req.param('mobile', '');
|
280
|
let mobile = req.param('mobile', '');
|
283
|
let area = req.param('area', '86');
|
281
|
let area = req.param('area', '86');
|
284
|
let mobileCode = req.param('code', '');
|
282
|
let mobileCode = req.param('code', '');
|
285
|
- const session = req.session;
|
283
|
+
|
|
|
284
|
+ // const session = req.session;
|
286
|
|
285
|
|
287
|
const ERR = {
|
286
|
const ERR = {
|
288
|
- code : 400,
|
287
|
+ code: 400,
|
289
|
message: '验证码错误!',
|
288
|
message: '验证码错误!',
|
290
|
- data : helpers.urlFormat('/passport/back/index')
|
289
|
+ data: helpers.urlFormat('/passport/back/index')
|
291
|
};
|
290
|
};
|
292
|
|
291
|
|
293
|
// if (!code || mobile !== session.mobile || area !== session.area) {
|
292
|
// if (!code || mobile !== session.mobile || area !== session.area) {
|
|
@@ -304,7 +303,7 @@ const verifyCodeByMobileAPI = (req, res) => { |
|
@@ -304,7 +303,7 @@ const verifyCodeByMobileAPI = (req, res) => { |
304
|
};
|
303
|
};
|
305
|
|
304
|
|
306
|
const validateExistCodePage = (req, res, next) => {
|
305
|
const validateExistCodePage = (req, res, next) => {
|
307
|
- let code = req.param('code', '');
|
306
|
+ let code = req.query.code || req.body.code;
|
308
|
|
307
|
|
309
|
if (!code) {
|
308
|
if (!code) {
|
310
|
return res.redirect(helpers.urlFormat('/passport/back/index'));
|
309
|
return res.redirect(helpers.urlFormat('/passport/back/index'));
|
|
@@ -314,24 +313,25 @@ const validateExistCodePage = (req, res, next) => { |
|
@@ -314,24 +313,25 @@ const validateExistCodePage = (req, res, next) => { |
314
|
};
|
313
|
};
|
315
|
|
314
|
|
316
|
const validateCodeByMobilePage = (req, res, next) => {
|
315
|
const validateCodeByMobilePage = (req, res, next) => {
|
317
|
- let code = req.param('code', '');
|
|
|
318
|
- let mobile = req.param('mobile', '');
|
316
|
+ let code = req.query.code || req.body.code;
|
|
|
317
|
+ let mobile = req.query.mobile || req.body.mobile;
|
|
|
318
|
+ let area = req.query.area || req.body.area;
|
|
|
319
|
+ let token = req.query.token || req.body.token;
|
|
|
320
|
+ let createdAt = req.query.createdAt || req.body.createdAt;
|
319
|
|
321
|
|
320
|
if (!mobile) {
|
322
|
if (!mobile) {
|
321
|
req.mobileAuth = {};
|
323
|
req.mobileAuth = {};
|
322
|
- next();
|
|
|
323
|
- return;
|
324
|
+ return next();
|
324
|
}
|
325
|
}
|
325
|
|
326
|
|
326
|
let data = {
|
327
|
let data = {
|
327
|
- mobile : mobile,
|
|
|
328
|
- area : req.param('area', ''),
|
|
|
329
|
- token : req.param('token', ''),
|
|
|
330
|
- create_time: req.param('create_time', 0)
|
328
|
+ mobile: mobile,
|
|
|
329
|
+ area: area,
|
|
|
330
|
+ token: token,
|
|
|
331
|
+ createdAt: createdAt
|
331
|
};
|
332
|
};
|
332
|
|
333
|
|
333
|
code = new Buffer(code, 'base64').toString();
|
334
|
code = new Buffer(code, 'base64').toString();
|
334
|
-
|
|
|
335
|
req.mobileAuth = service.authRequest(data, code);
|
335
|
req.mobileAuth = service.authRequest(data, code);
|
336
|
|
336
|
|
337
|
next();
|
337
|
next();
|
|
@@ -340,11 +340,11 @@ const validateCodeByMobilePage = (req, res, next) => { |
|
@@ -340,11 +340,11 @@ const validateCodeByMobilePage = (req, res, next) => { |
340
|
const validatePwdPage = (req, res, next) => {
|
340
|
const validatePwdPage = (req, res, next) => {
|
341
|
let pwd = req.body.pwd || '';
|
341
|
let pwd = req.body.pwd || '';
|
342
|
|
342
|
|
343
|
- if (helpers.isPassword(pwd)) {
|
|
|
344
|
- next();
|
|
|
345
|
- } else {
|
|
|
346
|
- res.redirect(helpers.urlFormat('/passport/back/index'));
|
343
|
+ if (!passportHelper.validator.isPassword(pwd)) {
|
|
|
344
|
+ return res.redirect(helpers.urlFormat('/passport/back/index'));
|
347
|
}
|
345
|
}
|
|
|
346
|
+
|
|
|
347
|
+ next();
|
348
|
};
|
348
|
};
|
349
|
|
349
|
|
350
|
const updatePwdAPI = (req, res, next) => {
|
350
|
const updatePwdAPI = (req, res, next) => {
|
|
@@ -365,20 +365,15 @@ const updatePwdAPI = (req, res, next) => { |
|
@@ -365,20 +365,15 @@ const updatePwdAPI = (req, res, next) => { |
365
|
};
|
365
|
};
|
366
|
|
366
|
|
367
|
const validateMobileInSession = (req, res, next) => {
|
367
|
const validateMobileInSession = (req, res, next) => {
|
368
|
-
|
|
|
369
|
- console.log(req.session.mobile);
|
|
|
370
|
- console.log(req.session.area);
|
|
|
371
|
-
|
|
|
372
|
-
|
|
|
373
|
req.body.mobile = req.session.mobile || '';
|
368
|
req.body.mobile = req.session.mobile || '';
|
374
|
req.body.verifyCode = req.session.verifyCode || '';
|
369
|
req.body.verifyCode = req.session.verifyCode || '';
|
375
|
req.body.area = req.session.area || '';
|
370
|
req.body.area = req.session.area || '';
|
376
|
|
371
|
|
377
|
- if (req.body.mobile && req.body.verifyCode) {
|
|
|
378
|
- return next();
|
|
|
379
|
- } else {
|
372
|
+ if (!(req.body.mobile && req.body.verifyCode)) {
|
380
|
return res.redirect(helpers.urlFormat('/passport/back/index'));
|
373
|
return res.redirect(helpers.urlFormat('/passport/back/index'));
|
381
|
}
|
374
|
}
|
|
|
375
|
+
|
|
|
376
|
+ next();
|
382
|
};
|
377
|
};
|
383
|
|
378
|
|
384
|
module.exports = {
|
379
|
module.exports = {
|