Authored by 毕凯

Merge branch 'master' into release/6.0.2

... ... @@ -121,11 +121,14 @@ module.exports = class extends global.yoho.BaseModel {
return {};
}
if (parseInt(order.attribute, 10) === 9) {
let attribute = _.parseInt(order.attribute);
if (attribute === 9 || attribute === 11) {
/* 预售商品,不能进行任何操作 */
orderBtn.push({
isAdvance: true
});
return {orderBtn: orderBtn};
}
... ... @@ -204,8 +207,6 @@ module.exports = class extends global.yoho.BaseModel {
break;
}
});
return {orderBtn: orderBtn};
}
/**
... ...
... ... @@ -62,12 +62,13 @@ module.exports = class extends global.yoho.BaseModel {
return {};
}
if (parseInt(order.attribute, 10) === 9) {
let attribute = _.parseInt(order.attribute);
if (attribute === 9 || attribute === 11) {
/* 预售商品,不能进行任何操作 */
orderBtn.push({
isAdvance: true
});
return {orderBtn: orderBtn};
}
/* 倒计时时间 订单详情页倒计时不在同一级*/
... ...
... ... @@ -228,10 +228,11 @@ const bind = {
let refer = helpers.urlFormat('/passport/bind/success?type=bind');
if (result && result.code && result.code === 200 && result.data.uid) {
return AuthHelper.syncUserSession(result.data.uid, req, res, result.data.session_key).then(() => {
result.data.refer = refer;
return result;
});
return AuthHelper.syncUserSession(result.data.uid, req, res, result.data.session_key)
.then((authData) => {
result.data.refer = _.get(authData, 'refer') || refer;
return result;
});
} else {
return { code: 400, message: '绑定失败', data: '' };
}
... ... @@ -262,10 +263,11 @@ const bind = {
let refer = helpers.urlFormat('/passport/bind/success', { sourceType: sourceType });
if (result && result.code && result.code === 200 && result.data.uid) {
return AuthHelper.syncUserSession(result.data.uid, req, res, result.data.session_key).then(() => {
result.data.refer = refer;
return result;
});
return AuthHelper.syncUserSession(result.data.uid, req, res, result.data.session_key)
.then((authData) => {
result.data.refer = _.get(authData, 'refer') || refer;
return result;
});
} else {
return { code: 400, message: '关联失败', data: '' };
}
... ...
... ... @@ -8,8 +8,9 @@
const _ = require('lodash');
const passport = require('passport');
// const md5 = require('yoho-md5');
const uuid = require('uuid');
const url = require('url');
const moment = require('moment');
const co = Promise.coroutine;
const cookie = global.yoho.cookie;
const helpers = global.yoho.helpers;
... ... @@ -19,6 +20,8 @@ const cache = global.yoho.cache;
const utils = require(global.utils);
const RegService = require('../models/reg-service');
const AuthHelper = require('../models/auth-helper');
const thirdAccount = require('../data/third-account.json');
const auth = require('../models/auth-helper');
const loginPage = `${config.siteUrl}/signin.html`;
... ... @@ -50,9 +53,10 @@ function doPassportCallback(openId, nickname, sourceType, req, res) {
refer: refer
});
} else if (result.code === 200 && result.data.uid) {
return AuthHelper.syncUserSession(result.data.uid, req, res, result.data.session_key).then(() => {
return refer;
});
return AuthHelper.syncUserSession(result.data.uid, req, res, result.data.session_key)
.then((authData) => {
return _.get(authData, 'refer') || refer;
});
}
}).then((redirectTo) => {
return res.redirect(redirectTo);
... ... @@ -63,6 +67,73 @@ function doPassportCallback(openId, nickname, sourceType, req, res) {
}
const common = {
// 第三方登录有货逻辑
thirdLogin(req, res, next) {
let refer = req.get('referer');
let thirdRefer = req.cookies.third_refer;
if (thirdRefer && !/signin|login|passport\/international/.test(refer)) {
res.clearCookie('third_refer', {
domain: 'yohobuy.com'
});
}
// TODO 记录token并验证有效期或者实现oauth
if (req.query.yh_type &&
req.query.yh_sign &&
req.query.yh_time &&
req.query.yh_backurl) {
let reqTime = moment(req.query.yh_time);
let timeDiff = moment().diff(reqTime);
if (!reqTime.isValid() ||
timeDiff >= 1000 * 60 * 5 || // 如果服务器之间大于5分钟验证失败
timeDiff < 0) {
return res.json({
code: 401,
message: 'yh_time已过期或者格式错误'
});
}
let account = thirdAccount[req.query.yh_type];
if (!account) {
return res.json({
code: 401,
message: 'yh_type验证失败'
});
}
let backurl = url.parse(req.query.yh_backurl);
let regDomain = new RegExp(`${account.domain.replace(/\./g, '\\.')}$`);
if (!regDomain.test(backurl.host || '')) {
return res.json({
code: 401,
message: 'yh_backurl回调域名验证失败'
});
}
let signStr = auth.thirdSign(req.query, account.clientSecret);
if (signStr.toLowerCase() !== req.query.yh_sign.toLowerCase()) {
return res.json({
code: 401,
message: 'yh_sign签名验证错误'
});
}
res.cookie('third_refer', refer, {
domain: 'yohobuy.com'
});
res.cookie('third_type', req.query.yh_type, {
domain: 'yohobuy.com'
});
res.cookie('third_backurl', req.query.yh_backurl, {
domain: 'yohobuy.com'
});
req.query.from = req.query.yh_type;
}
next();
},
beforeLogin: (req, res, next) => {
if (req.session.passwordWeak) {
return res.redirect('/passport/password/resetpage');
... ... @@ -297,10 +368,11 @@ const local = {
return res.json(passwordWeakReturn);
}
AuthHelper.syncUserSession(user.uid, req, res, user.session_key).then(() => {
AuthHelper.syncUserSession(user.uid, req, res, user.session_key).then((authData) => {
if (user.weakPassword) {
return res.json(passwordWeakReturn);
} else {
user.href = _.get(authData, 'refer', user.href);
res.json({
code: 200,
data: user
... ...
... ... @@ -127,7 +127,7 @@ class Reg {
return res.json(regMobileAesResult);
}
yield AuthHelper.syncUserSession(regMobileAesResult.data.uid,
let authData = yield AuthHelper.syncUserSession(regMobileAesResult.data.uid,
req, res, regMobileAesResult.data.session_key);
// 返回跳转到来源页面
... ... @@ -156,7 +156,7 @@ class Reg {
message: '注册成功',
data: {
session: refer,
href: '//m.yohobuy.com/activity/invite-reg',
href: _.get(authData, 'refer') || '//m.yohobuy.com/activity/invite-reg',
msgDelivery: _.get(regMobileAesResult, 'data.msgDelivery', '')
}
});
... ...
... ... @@ -406,7 +406,7 @@ let setPassword = (req, res, next) => {
resultCopy = result;
return AuthHelper.syncUserSession(result.data.uid, req, res, result.data.session_key);
}).then(() => {
}).then((authData) => {
if (!resultCopy) {
return;
}
... ... @@ -438,7 +438,7 @@ let setPassword = (req, res, next) => {
message: '注册成功',
data: {
session: refer,
href: '//m.yohobuy.com/activity/invite-reg',
href: _.get(authData, 'refer') || '//m.yohobuy.com/activity/invite-reg',
msgDelivery: _.get(resultCopy, 'data.msgDelivery', '')
}
});
... ...
... ... @@ -351,11 +351,11 @@ exports.check = (req, res, next) => {
});
return AuthHelper.syncUserSession(info.data.uid, req, res, info.data.session_key);
})
.then(() => {
.then((authData) => {
res.json({
code: 200,
message: LOGIN_SUCCSS,
redirect: utils.refererLimit(req.cookies.refer)
redirect: _.get(authData, 'refer') || utils.refererLimit(req.cookies.refer)
});
delete req.session.smsLogin;
... ... @@ -418,14 +418,14 @@ exports.password = (req, res, next) => {
resultCopy = result;
return AuthHelper.syncUserSession(result.data.uid, req, res, result.data.session_key);
}).then(() => {
}).then((authData) => {
if (!resultCopy) {
return;
}
res.json({
code: 200,
message: LOGIN_SUCCSS,
redirect: utils.refererLimit(req.cookies.refer)
redirect: _.get(authData, 'refer') || utils.refererLimit(req.cookies.refer)
});
delete req.session.smsLogin;
}).catch(next);
... ...
{
"mars": {
"clientSecret": "f30368d65fcad4a265074948a2a2e6e6",
"domain": "yohomars.com"
},
"activity": {
"clientSecret": "3bd815162342d9733f06ab6811082c64",
"domain": "yoho.cn"
}
}
\ No newline at end of file
... ...
... ... @@ -6,6 +6,11 @@ const logger = global.yoho.logger;
const sign = global.yoho.sign;
const api = global.yoho.API;
const uuid = require('uuid');
const url = require('url');
const md5 = require('yoho-md5');
const moment = require('moment');
const querystring = require('querystring');
const thirdAccount = require('../data/third-account.json');
class Auth {
... ... @@ -73,6 +78,54 @@ class Auth {
return api.get('', param);
}
static thirdSign(params, clientSecret) {
let secretParams = {},
secretStr = '';
for (const k of Object.keys(params).sort()) {
if (k === 'yh_sign') {
continue;
}
secretParams[k] = params[k];
}
secretStr = _.join(_.map(secretParams, (v, k) => {
return `${k}=${v}`;
}), '&');
return md5(secretStr + clientSecret);
}
static thirdLogin(req, res, uid) {
if (req.cookies.third_type && req.cookies.third_backurl && req.cookies.third_refer) {
let backurl = url.parse(req.cookies.third_backurl),
account = thirdAccount[req.cookies.third_type];
let params = Object.assign({
yh_uid: uid,
yh_type: req.cookies.third_type,
yh_time: moment().format('YYYY-MM-DD HH:mm:ss')
}, querystring.parse(backurl.query));
let signStr = this.thirdSign(params, account.clientSecret);
params.yh_sign = signStr;
let queryStr = _.join(_.map(params, (v, k) => {
return `${k}=${encodeURIComponent(v)}`;
}), '&');
return {
refer: `${backurl.protocol}//${backurl.host}?${queryStr}`
};
}
res.clearCookie('third_type', {
domain: 'yohobuy.com'
});
res.clearCookie('third_backurl', {
domain: 'yohobuy.com'
});
res.clearCookie('third_refer', {
domain: 'yohobuy.com'
});
}
static syncUserSession(uid, req, res, sessionKey) {
let userId = {
toString: () => {
... ... @@ -132,6 +185,9 @@ class Auth {
domain: 'yohobuy.com',
expires: new Date(Date.now() + 2592000000) // 有效期一年
});
// 第三方登录逻辑
return this.thirdLogin(req, res, uid);
});
}
}
... ...
... ... @@ -203,6 +203,7 @@ router.get('/signin.html',
validateCode.load,
login.common.beforeLogin,
login.common.clearCookie,
login.common.thirdLogin,
smsNew.smsLoginPage); // 短信验证码登录
router.get('/reg.html',
validateCode.load,
... ...
... ... @@ -79,6 +79,7 @@ module.exports = () => {
}
}
res.locals.isLogin = Boolean(req.user.uid); // 用户是否登录
next();
};
};
... ...
... ... @@ -72,6 +72,10 @@
var s = document.getElementsByTagName("script")[0];
s.parentNode.insertBefore(hm, s);
})();
{{#if @root.isLogin}}
_hmt.push(['_setCustomVar', 1, 'login', true, 2]);
{{/if}}
}, 1000);
}());
... ...
... ... @@ -6,7 +6,7 @@
<li><span class="hours">{{leftTime}}</span></li>
</ul>
{{else if isAdvance}}
<span class="order-opt-info">*定金预售订单只能在APP端操作</span>
<span class="order-opt-info">*订单只能在APP端操作</span>
{{else if refundApply}}
<span class="btn refund">申请退款</span>
{{else if modifyAddress}}
... ...
This diff could not be displayed because it is too large.
{
"name": "m-yohobuy-node",
"version": "6.0.13",
"version": "6.0.14",
"private": true,
"description": "A New Yohobuy Project With Express",
"repository": {
... ...
... ... @@ -425,3 +425,23 @@
}
}
}
.is-mars-app {
.chose-panel {
.block {
&.chosed {
background-color: #89b374;
color: #fff;
border-color: #89b374;
}
}
.btn-wrap {
.btn-sure,
.btn-sure-addtocart {
background-color: #89b374 !important;
color: #fff;
}
}
}
}
... ...