auth.js
883 Bytes
var urlFormat = require('../util/url');
/**
* 登录判断
* @author: xuqi<qi.xu@yoho.cn>
* @date: 2016/4/5
*/
module.exports = (req, res, next) => {
var loginUrl = 'http://www.yohobuy.com/signin.html',
referrer = urlFormat(req.originalUrl || '/', null, 'activity');
if (req.isApp && !req.query.uid) {
referrer = referrer.split('?')[0];
loginUrl += '?openby:yohobuy={"action":"go.weblogin","params":{"jumpurl":{"url":"' + referrer.replace(/\//g, '\\/') + '","param":{"from":"app"}},"requesturl":{"url":"","param":{}},"priority":"N"}}';
return res.redirect(loginUrl); // 跳转APP登录页
} else if (!req.isApp && !req.cookies._UID) {
loginUrl = loginUrl + '?refer=' + encodeURIComponent(referrer);
return req.xhr ? res.json({loginUrl: loginUrl}) : res.redirect(loginUrl); // 跳转登录页
}
next();
};