Authored by 郝肖肖

找回密码,发送邮件,接口合并

... ... @@ -88,6 +88,21 @@ const getUserInfoAPI = (req, res, next) => {
.catch(next);
};
// 成功 next ,否则 return err json
const getUserInfoAPINoRes = (req, res, next) => {
let inputInfo = req.inputInfo;
req.session.type = 'back-step1';
service.findUserAsync(inputInfo.type, inputInfo.phone, inputInfo.area).then(d => {
if (d.code === 200) {
return next();
} else {
return res.json(d);
}
}).catch(next);
};
const fakeGetUserInfoAPI = (req, res) => {
return res.json({code: 200, message: '验证成功'});
};
... ... @@ -489,6 +504,7 @@ module.exports = {
index, // 首页
fakeGetUserInfoAPI, // 通过邮箱或手机号获得用户信息
getUserInfoAPI, // 通过邮箱或手机号获得用户信息
getUserInfoAPINoRes, // 通过邮箱或手机号获得用户信息
sendCodePage, // 发送验证码到邮箱或者手机,然后跳转页面
saveInSession, // 保存状态到session中
... ...
... ... @@ -130,7 +130,9 @@ router.post('/passport/back/authcode',
// 提交按钮邮件API
router.post('/passport/back/email',
back.validateInputPage,
captcha.requiredAPI,
back.validateInputAPI,
back.getUserInfoAPINoRes,
back.sendCodePage,
back.saveInSession);
... ...
... ... @@ -14,7 +14,7 @@
{{/ countryList}}
</ul>
</div>
<form id="back-form" class="back-form" action="/passport/back/email" method="post">
<form id="back-form" class="back-form">
<input id="country-code-hide" type="hidden" name="area" value="+86">
<ul>
<li class="input-container-li clearfix">
... ...
... ... @@ -29,33 +29,6 @@ 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');
captcha.refresh();
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,
... ... @@ -166,38 +139,37 @@ $btn.click(function(e) {
return;
}
if (!captcha.getResults()) {
captcha.showTip();
return;
}
if (/^[0-9]+$/.test($.trim($phoneNum.val()))) {
$('#find-form').attr('action', '/passport/back/mobile');
}
$('#captcha-value').val(captcha.getResults());
if (hasPh) {
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);
$.post('/passport/back/email', {
verifyCode: captcha.getResults(),
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 === 402) {
$accErr.removeClass('hide').find('em').text('该账号不存在');
$phoneNum.addClass('error');
});
captcha.refresh();
return $.Deferred().reject().promise();//eslint-disable-line
}
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');
});
}
... ...