yohoAuth.js
1.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
/**
* YOHO授权登录
* @author: lq
* @date: 2017/9/1
*/
'use strict';
const _ = require('lodash');
const moment = require('moment');
const authYoho = require('../../utils/authYoho');
const activityModel = require('../models/activity');
const queryString = require('queryString');
const isProd = process.env.NODE_ENV === 'production';
module.exports = (req, res, next) => {
const actId = req.query.actId;
req.ctx(activityModel).authType(actId)
.then(type => {
if (type === 2) {
const refer = req.get('Referer') || '';
const yhAuthId = _.get(req.session, 'yh_auth_id', 0);
if (!yhAuthId) {
let params = {
yh_type: 'activity',
yh_time: moment(new Date()).format('YYYY-MM-DD HH:mm:ss'),
yh_backurl: `${isProd ? 'https' : 'http'}://action.yoho.cn/passport/yohoAuth`
};
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();
});
};