|
|
/**
|
|
|
* 登录判断
|
|
|
* @author: lq
|
|
|
* @date: 2017/9/1
|
|
|
*/
|
|
|
'use strict';
|
|
|
const _ = require('lodash');
|
|
|
const moment = require('moment');
|
|
|
const authYoho = require('../../utils/authYoho');
|
|
|
const queryString = require('queryString');
|
|
|
|
|
|
module.exports = (req, res, next) => {
|
|
|
const refer = req.get('Referer') || '';
|
|
|
const yhAuthId = _.get(req.session, 'yh_auth_id', 0);
|
|
|
|
|
|
if (!yhAuthId) {
|
|
|
let params = {
|
|
|
yh_backurl: 'http://action.yoho.cn/passport/yohoAuth',
|
|
|
yh_type: 'activity',
|
|
|
yh_time: moment(new Date()).format('YYYY-MM-DD HH:mm:ss')
|
|
|
};
|
|
|
|
|
|
params.yh_sign = authYoho.sign(params);
|
|
|
_.set(req.session, 'auth_refer', refer);
|
|
|
return res.json({
|
|
|
code: 401,
|
|
|
message: '抱歉,您暂未登录!',
|
|
|
redirect: `//m.yohobuy.com/signin.html?${queryString.stringify(params)}`
|
|
|
});
|
|
|
}
|
|
|
|
|
|
next();
|
|
|
}; |
...
|
...
|
|