-
Notifications
You must be signed in to change notification settings - Fork 3
/
data.js
52 lines (43 loc) · 1.43 KB
/
data.js
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
var twitterAccount;
var Redis = require('./redis');
var redis = new Redis();
function Data(properties) {
twitterAccount = properties.admin.twitter;
}
Data.prototype.index = function(req,res) {
if (!checkAdminUser(req,res)) return;
res.render('data/index', {locals: {loginName:req.session.user.name}});
};
Data.prototype.messages = function(req,res) {
if (!checkAdminUser(req,res)) return;
var messages = [];
redis.obtainMessages(0,0,function(replies) {
replies.forEach(function (reply, i) {
messages.push(JSON.parse(reply));
});
res.render('data/messages', {locals: {loginName:req.session.user.name, messages:messages}});
});
};
Data.prototype.warnings = function(req,res) {
if (!checkAdminUser(req,res)) return;
var warnings = [];
redis.obtainWarnings(function(replies) {
replies.forEach(function (reply, i) {
console.log("warning: %s", reply);
warnings.push(JSON.parse(reply));
});
res.render('data/warnings', {locals: {loginName:req.session.user.name, warnings:warnings}});
});
};
function checkAdminUser(req,res) {
var loginName = '';
if (req.session.oauth && req.session.user) {
loginName = req.session.user.name;
if (req.session.user.name == twitterAccount) {
return true;
}
}
res.render('404',{locals: {loginName:loginName}});
return false;
}
module.exports = Data;