...
|
...
|
@@ -68,14 +68,19 @@ const validateInputPage = (req, res, next) => { |
|
|
req.inputInfo = result;
|
|
|
next();
|
|
|
})
|
|
|
.catch(()=> {
|
|
|
res.redirect(helpers.urlFormat('/passport/back/index'));
|
|
|
.catch((err) => {
|
|
|
res.json({
|
|
|
code: 400,
|
|
|
message: err
|
|
|
});
|
|
|
});
|
|
|
};
|
|
|
|
|
|
const getUserInfoAPI = (req, res, next) => {
|
|
|
let inputInfo = req.inputInfo;
|
|
|
|
|
|
req.session.type = 'back-step1';
|
|
|
|
|
|
service.findUserAsync(inputInfo.type, inputInfo.phone, inputInfo.area)
|
|
|
.then(result => {
|
|
|
res.json(result);
|
...
|
...
|
@@ -93,7 +98,13 @@ const sendCodePage = (req, res, next) => { |
|
|
service.sendCodeToUserAsync(inputInfo.type, inputInfo.phone, inputInfo.area)
|
|
|
.then(result => {
|
|
|
if (!(result.code && result.code === 200)) {
|
|
|
return res.redirect(helpers.urlFormat('/passport/back/index'));
|
|
|
return res.json({
|
|
|
code: 400,
|
|
|
message: '发送验证码错误',
|
|
|
data: {
|
|
|
refer: helpers.urlFormat('/passport/back/index')
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
|
|
|
return next();
|
...
|
...
|
@@ -102,19 +113,45 @@ const sendCodePage = (req, res, next) => { |
|
|
};
|
|
|
|
|
|
const saveInSession = (req, res) => {
|
|
|
if (req.session.type !== 'back-step1') {
|
|
|
return res.json({
|
|
|
code: 400,
|
|
|
message: '未验证',
|
|
|
data: {
|
|
|
refer: helpers.urlFormat('/passport/back/index')
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
|
|
|
req.session.type = 'back-step2';
|
|
|
|
|
|
switch (req.inputInfo.type) {
|
|
|
case 'email':
|
|
|
req.session.email = req.inputInfo.phone;
|
|
|
res.redirect(helpers.urlFormat('/passport/back/sendEmail'));
|
|
|
break;
|
|
|
return res.json({
|
|
|
code: 200,
|
|
|
data: {
|
|
|
refer: helpers.urlFormat('/passport/back/sendemail')
|
|
|
}
|
|
|
});
|
|
|
case 'mobile':
|
|
|
req.session.mobile = req.inputInfo.phone;
|
|
|
req.session.area = req.inputInfo.area;
|
|
|
req.session.captcha = req.body.verifyCode;
|
|
|
res.redirect(helpers.urlFormat('/passport/back/verification'));
|
|
|
break;
|
|
|
|
|
|
return res.json({
|
|
|
code: 200,
|
|
|
data: {
|
|
|
refer: helpers.urlFormat('/passport/back/verification')
|
|
|
}
|
|
|
});
|
|
|
default:
|
|
|
res.redirect(helpers.urlFormat('/passport/back/index'));
|
|
|
return res.json({
|
|
|
code: 500,
|
|
|
data: {
|
|
|
refer: helpers.urlFormat('/passport/back/index')
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
};
|
|
|
|
...
|
...
|
@@ -133,6 +170,10 @@ const validateMobileAPI = (req, res, next) => { |
|
|
let mobile = req.body.mobile || '';
|
|
|
const ERR = {code: 400, message: '验证失败'};
|
|
|
|
|
|
if (req.session.type !== 'back-step3') {
|
|
|
return res.json(ERR);
|
|
|
}
|
|
|
|
|
|
if (!passportHelper.validator.isMobile(mobile)) {
|
|
|
return res.json(ERR);
|
|
|
}
|
...
|
...
|
@@ -157,6 +198,12 @@ const validateEmailInSession = (req, res, next) => { |
|
|
};
|
|
|
|
|
|
const sendEmailPage = (req, res, next) => {
|
|
|
if (req.session.type !== 'back-step2') {
|
|
|
return res.redirect(helpers.urlFormat('/passport/back/index'));
|
|
|
}
|
|
|
|
|
|
req.session.type = 'back-step3';
|
|
|
|
|
|
passportHelper.getLeftBannerAsync()
|
|
|
.then(result => {
|
|
|
res.render('back/send-email', Object.assign({
|
...
|
...
|
@@ -215,7 +262,11 @@ const resetPasswordPage = (req, res, next) => { |
|
|
};
|
|
|
|
|
|
const verifyCodeByMobilePage = (req, res, next) => {
|
|
|
req.session.type = 'back-step2';
|
|
|
if (req.session.type !== 'back-step2') {
|
|
|
return res.redirect(helpers.urlFormat('/passport/back/index'));
|
|
|
}
|
|
|
|
|
|
req.session.type = 'back-step3';
|
|
|
|
|
|
passportHelper.getLeftBannerAsync()
|
|
|
.then(result => {
|
...
|
...
|
@@ -282,7 +333,7 @@ const verifyCodeByMobileAPI = (req, res) => { |
|
|
return res.json(ERR);
|
|
|
}
|
|
|
|
|
|
if (session.type !== 'back-step2') {
|
|
|
if (session.type !== 'back-step3') {
|
|
|
return res.json(ERR);
|
|
|
}
|
|
|
|
...
|
...
|
@@ -359,10 +410,9 @@ const updatePwdAPI = (req, res, next) => { |
|
|
|
|
|
const validateMobileInSession = (req, res, next) => {
|
|
|
req.body.mobile = req.session.mobile || '';
|
|
|
req.body.verifyCode = req.session.captcha || '';
|
|
|
req.body.area = req.session.area || '';
|
|
|
|
|
|
if (!(req.body.mobile && req.body.verifyCode)) {
|
|
|
if (!req.body.mobile) {
|
|
|
return res.redirect(helpers.urlFormat('/passport/back/index'));
|
|
|
}
|
|
|
|
...
|
...
|
|