Authored by shuaiguo

Merge remote-tracking branch 'refs/remotes/origin/feature/phoneCoupon' into develop

... ... @@ -85,7 +85,7 @@ exports.couponSend = (req, res, next) => {
// 接口要加 session 校验,跨域异步请求未添加相关参数
if (req.yoho.isApp || app.client_type === 'miniapp') {
if (app.app_version && app.client_type && app.session_key && app.uid) {
if (app.app_version && app.client_type && app.session_key && app.uid && !req.query.webSession) {
// 小程序调接口获取 session 的方式不同,H5 嵌小程序,client_type 标记为 h5
let isMiniApp = app.client_type === 'miniapp';
... ...
... ... @@ -25,7 +25,11 @@ const geetest = {
} else {
req.session.useYohoCaptcha = true;
}
if (req.query.callback) {
res.jsonp(data);
} else {
res.send(data);
}
}).catch(next);
},
validate(req, res, next) {
... ...
... ... @@ -89,7 +89,11 @@ class SmsLogin {
co(function* () {
let sendSmsResult = yield req.ctx(PhoneServiceModel).sendSMS(params);
if (req.query.callback) {
res.jsonp(sendSmsResult);
} else {
res.json(sendSmsResult);
}
})().catch(next);
}
... ... @@ -159,8 +163,14 @@ class SmsLogin {
let shopping_key = cookie.getShoppingKey(req); // eslint-disable-line
let from = req.cookies.from || 'yohobuy';
if (req.query.callback) {
res._sendFn = res.jsonp;
} else {
res._sendFn = res.json;
}
if (!mobile || !area) {
res.json({
res._sendFn({
code: 401,
message: VERIFY_ERROR
});
... ... @@ -171,13 +181,13 @@ class SmsLogin {
// 验证码 校验异常
if (r2.code !== 200) {
res.json(r2);
res._sendFn(r2);
return;
}
// 校验失败
if (r2.data.is_pass !== 'Y') {
res.json({
res._sendFn({
code: 401,
message: '短信验证码错误'
});
... ... @@ -218,7 +228,7 @@ class SmsLogin {
});
return req.ctx(AuthHelperModel).syncUserSession(info.data.uid, req, res, info.data.session_key);
}).then((authData) => {
res.json({
res._sendFn({
code: 200,
message: LOGIN_SUCCSS,
redirect: _.get(authData, 'refer') || utils.refererLimit(req.cookies.refer),
... ... @@ -228,7 +238,7 @@ class SmsLogin {
delete req.session.smsLogin;
}).catch(error => {
res.json(error);
res._sendFn(error);
});
}).catch(next);
}
... ...
... ... @@ -169,6 +169,15 @@ router.get('/passport/sms_login',
validateCode.load,
smsLogin.smsLoginPage); // 短信验证码登录
router.post('/passport/sms_login/step1_check', validateCode.check, smsLogin.indexCheck);
router.get('/passport/sms_login/step1_check', (req, res, next) => {
if (!req.query.callback) {
return res.json({code: 400});
}
req.body = req.body || {};
Object.assign(req.body, req.query);
next();
}, validateCode.check, smsLogin.indexCheck);
// 兼容老的路由
router.get('/signin.html',
... ...
... ... @@ -7,7 +7,8 @@ const config = global.yoho.config;
module.exports = () => {
return (req, res, next) => {
if (!req.yoho.isApp) {
// webSession: 活动模板手机号领券,使用web端登录信息
if (!req.yoho.isApp || req.query.webSession) {
// 从 SESSION 中获取到当前登录用户的 UID
if (req.session && _.isNumber(req.session.LOGIN_UID_)) {
// 调用接口传参时切勿使用toString获得字符串
... ...