Authored by htoooth

fix black

... ... @@ -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'));
}
... ...
... ... @@ -119,7 +119,7 @@ router.get('/passport/reg/success', reg.success);
// 找回密码首页
router.get('/passport/back/index', back.index);
// 实时验证输入是否正确
// 验证输入是否正确
router.post('/passport/back/authcode',
captcha.requiredAPI,
back.validateInputAPI,
... ... @@ -127,14 +127,12 @@ router.post('/passport/back/authcode',
// 提交按钮邮件API
router.post('/passport/back/email',
captcha.requiredPage,
back.validateInputPage,
back.sendCodePage,
back.saveInSession);
// 提交按钮手机API
// 提交按钮手机AP
router.post('/passport/back/mobile',
captcha.requiredPage,
back.validateInputPage,
back.sendCodePage,
back.saveInSession);
... ...
... ... @@ -29,6 +29,32 @@ var $cr = $('#country-code-hide'),
require('../../simple-header');
require('yoho-jquery-placeholder');
require('../../common/promise');
require('../../common');
function authcode() {
return $.ajax({
type: 'POST',
url: '/passport/back/authcode',
data: {
verifyCode: captcha.getResults(),
phoneNum: $phoneNum.val(),
area: $cr.val()
}
}).then(function(data) {
if (data.code === 200) {
$('#captcha-value').val(captcha.getResults());
return $.Deferred().resolve().promise(); //eslint-disable-line
} else if (data.code === 402) {
$accErr.removeClass('hide').find('em').text('该账号不存在');
$phoneNum.addClass('error');
return $.Deferred().reject().promise();//eslint-disable-line
} else if (data.code === 405) {
captcha.showTip(data.message);
return $.Deferred().reject().promise();//eslint-disable-line
}
});
}
function vaPn(v) {
var pass = true,
... ... @@ -151,7 +177,27 @@ $btn.click(function(e) {
$('#captcha-value').val(captcha.getResults());
if (hasPh) {
$('#back-form').submit();
authcode().then(function() {
$.post($('#back-form').attr('action'), {
phoneNum: $('#phone-num').val(),
area: $('#country-code-hide').val()
}).then(function(result) {
if (result.code === 200) {
window.jumpUrl(result.data.refer);
return;
}
if (result.code === 405) {
captcha.showTip(result.message);
$accErr.addClass('hide');
$phoneNum.removeClass('error');
return;
}
$accErr.removeClass('hide').find('em').text(result.message);
$phoneNum.addClass('error');
});
});
}
e.preventDefault();
... ...