Authored by 陈峰

app内嵌h5跳转登录

... ... @@ -738,7 +738,7 @@ const setMasterCard = (req, res, next) => {
};
const sessionKeyAuth = (req, res, next) => {
let uid = req.user.uid || req.query.uid || req.cookies.installmentUid;
let uid = req.user.uid;
let sessionKey = _.get(req, 'user.uid.sessionKey');
if (sessionKey && !req.session.SESSION_KEY) {
... ...
... ... @@ -58,6 +58,7 @@ exports.serverError = () => {
return res.render('error/app-auth', {
module: 'common',
page: 'app-update',
localCss: true,
message: err.message
});
}
... ... @@ -65,6 +66,7 @@ exports.serverError = () => {
module: 'common',
page: 'app-redirect-login',
message: '验证失败,请登录',
localCss: true,
refer: err.refer
});
} else {
... ...
... ... @@ -33,47 +33,21 @@ module.exports = () => {
};
}
if (!req.user.uid) {
if (req.cookies.app_uid) {
req.cookies.app_uid = _.parseInt(req.cookies.app_uid);
}
if (req.query.uid) {
req.query.uid = _.parseInt(req.query.uid);
}
if (req.cookies.app_uid && req.cookies.app_session_key) {
// 调用接口传参时切勿使用toString获得字符串
req.user.uid = {
toString: () => {
return req.cookies.app_uid;
},
sessionKey: req.cookies.app_session_key,
appVersion: req.cookies.app_version || void 0,
appSessionType: req.cookies.app_client_type || void 0
};
}
// if ((req.query.uid || req.cookies.app_uid) &&
// (req.query.client_type || req.cookies.app_client_type) &&
// (req.query.app_version || req.cookies.app_version)) {
// let uid = req.query.uid || req.cookies.app_uid;
// req.query.uid = {
// toString: () => {
// return uid;
// },
// appVersion: req.query.app_version || req.cookies.app_version || void 0,
// appSessionType: req.query.client_type || req.cookies.app_client_type || void 0
// };
// res.cookie('app_uid', req.query.uid.toString(), {
// domain: 'm.yohobuy.com'
// });
// res.cookie('app_client_type', req.query.uid.appSessionType, {
// domain: 'm.yohobuy.com'
// });
// res.cookie('app_version', req.query.uid.appVersion, {
// domain: 'm.yohobuy.com'
// });
// }
if (!req.user.uid &&
req.cookies.app_uid &&
req.cookies.app_uid !== '0' &&
req.cookies.app_session_key &&
req.cookies.app_version &&
req.cookies.app_client_type) {
// 调用接口传参时切勿使用toString获得字符串
req.user.uid = {
toString: () => {
return _.parseInt(req.cookies.app_uid);
},
sessionKey: req.cookies.app_session_key,
appVersion: req.cookies.app_version,
appSessionType: req.cookies.app_client_type
};
}
next();
};
... ...
require('common/_app-auth.css');
let yohoApp = require('../yoho-app'),
$ = require('yoho-jquery'),
cookie = require('yoho-cookie');
let $refer = $('#refer');
((function() {
require('common/_app-auth.css');
let yohoApp = require('../yoho-app'),
$ = require('yoho-jquery'),
cookie = require('yoho-cookie');
let $refer = $('#refer');
let href = location.href;
let href = location.href;
if ($refer.length) {
href = $refer.val();
if (href.indexOf(location.host) < 0) {
href = `${location.protocol}//${location.host}${href}`;
if ($refer.length) {
href = $refer.val();
if (href.indexOf(location.host) < 0) {
href = `${location.protocol}//${location.host}${href}`;
}
}
}
let oldSessionKey = cookie.get('app_old_session_key');
let sessionKey = cookie.get('app_session_key');
if (!sessionKey || (sessionKey && oldSessionKey !== sessionKey)) {
cookie.set('app_old_session_key', sessionKey, {
domain: '.m.yohobuy.com',
path: '/'
});
yohoApp.goLogin(href);
}
let oldSessionKey = localStorage.getItem('oldSessionKey') || '';
let oldSessionKeyErr = parseInt(localStorage.getItem('oldSessionKeyErr') || -1, 10);
let sessionKey = cookie.get('app_session_key');
if (!sessionKey) {
return;
}
if (oldSessionKey === sessionKey) {
if (oldSessionKeyErr < 3) {
localStorage.setItem('oldSessionKeyErr', oldSessionKeyErr + 1);
} else {
localStorage.removeItem('oldSessionKeyErr');
return;
}
}
localStorage.setItem('oldSessionKey', sessionKey);
yohoApp.goLogin(href);
})());
... ...
... ... @@ -156,7 +156,8 @@ yoho = {
jumpurl: {
url: refer.path,
param: refer.query
}
},
needlogout: 'Y'
}
}));
}
... ...