user.js
2.29 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
const moment = require('moment');
const _ = require('lodash');
const aes = require('./aes');
const {yoho} = global.yoho.utils;
const {yohoSecret} = global.yoho.config;
const UserModel = require('../models/user');
const isProd = process.env.NODE_ENV === 'production';
const user = {
getLoginUrl(req, res) {
const url = req.query.url;
if (!url) {
return res.json({
code: 400,
loginUrl: '#'
});
}
let params = {
yh_type: 'activity',
yh_time: moment().format('YYYY-MM-DD HH:mm:ss'),
yh_backurl: url
};
params.yh_sign = yoho.getSign(params, yohoSecret);
let queryStr = _.join(_.map(params, (v, k) => {
return `${k}=${encodeURIComponent(v)}`;
}), '&');
return res.json({
code: 200,
loginUrl: `http${isProd ? 's' : ''}://m.yohobuy.com/signin.html?${queryStr}`
});
},
loginLog(req, res, next) {
const uid = req.body.uid;
if (!uid) {
return res.json({
code: 400
});
}
const ip = req.get['X-Forwarded-For'] || req.ip || req.connection.remoteAddress;
const loginTime = Date.now();
let platform;
const ua = req.get('user-agent');
const referer = req.get('referer');
if (/Android/.test(ua)) {
platform = 'Android';
} else if (/(iPhone)|(iPad)|(iPod)/.test(ua)) {
platform = 'iPhone';
} else {
platform = 'Other';
}
return req.ctx(UserModel).loginLog({
uid,
ip,
loginTime,
platform,
referer
}).then(() => {
return res.json({code: 200});
}).catch(next);
},
/**
* 有货用户基础信息
* @param req
* @param res
* @param next
*/
userBaseInfo(req, res, next) {
let uid = req.body.uid;
let encryptUid = req.body.encryptUid;
if (encryptUid) {
uid = parseInt(aes.decryptUid(encryptUid), 10);
}
return req.ctx(UserModel).userBaseInfo(uid)
.then(result => {
return res.json(result);
}).catch(next);
}
};
module.exports = user;