-
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathpwa.js
146 lines (134 loc) · 5.19 KB
/
pwa.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
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
"use strict";
var express = require("express");
var router = express.Router();
var ErrorSerializer = require("../serializers/error");
router.get("/", function(req, res) {
res.setHeader("Cache-Control", "public, max-age=86400");
res.render("index", {
currentUrl: req.path,
user: req.session.user
});
});
router.get("/applicationStart", function(req, res) {
res.render("applicationStart", {
currentUrl: req.path,
user: req.session.user
});
});
router.get("/networkError", function(req, res) {
res.render("networkError", {
currentUrl: req.path,
user: req.session.user
});
});
router.get("/stories/?:story_id([0-9a-zA-Z\-]+)?", function(req, res) {
var story_id = req.params.story_id;
res.render("story", {
currentUrl: req.path,
baseUrl_https: baseUrl_https,
user: req.session.user,
story: {id: story_id}
});
});
/**
* @api {get} /mail/:mail/unsubscribe/:list/:unsubscription_token/ Unsubscribe from a Notification list
* @apiName Unsubscribe from a Notification list
* @apiGroup 8. Notifications
* @apiVersion 2.0.1
*
* @apiUse Auth
* @apiParam {string} mail Email address from the user
* @apiParam {string} list List to unsubscribe
* @apiParam {string} unsubscription_token Uniq token to approve the transaction
*
* @apiUse 200
* @apiUse 403
* @apiUse 404
*/
router.get("/mail/:mail/unsubscribe/:list([0-9a-zA-Z\-]+)/:unsubscription_token([0-9a-zA-Z\-]+)/", function(req, res) {
var mail = req.params.mail;
var list = req.params.list;
var unsubscription_token = req.params.unsubscription_token;
if ( list === "changePassword" || list === "reminder" || list === "newsletter" || list === "monthlyreport" ) {
let result;
let time;
users.chain().find({ "email": mail, "unsubscription_token": unsubscription_token }).update(function(user) {
time = parseInt(moment().format("x"), 10);
user.unsubscription = typeof user.unsubscription!=="undefined"?user.unsubscription:{};
user.subscription = typeof user.subscription!=="undefined"?user.subscription:{};
user.unsubscription[""+list] = time;
user.subscription[""+list] = null;
t6console.debug("unsubscription", user.unsubscription);
t6console.debug("subscription", user.subscription);
result = user;
});
db_users.save();
if (req.headers && typeof req.headers["content-type"]!=="undefined" && req.headers["content-type"].indexOf("json") !== 0) {
res.status(200).send({"status": "unsubscribed", "list": list, "time": null});
} else {
res.render("notifications-unsubscribe", {
currentUrl: req.path,
user: typeof result!=="undefined"?result:{"email": mail, "unsubscription_token": unsubscription_token, "unsubscription": {} },
mail: mail,
list: list,
time: null,
moment: moment,
});
}
t6events.addStat("t6App", "unsubscribe", typeof result!=="undefined"?result.id:"??"+mail, typeof result!=="undefined"?result.id:"??"+mail, {"list": list});
} else {
res.status(404).send(new ErrorSerializer({"id": 11271, "code": 404, "message": "Not Found"}).serialize());
}
});
/**
* @api {get} /mail/:mail/subscribe/:list/:unsubscription_token/ Subscribe from a Notification list
* @apiName Subscribe from a Notification list
* @apiGroup 8. Notifications
* @apiVersion 2.0.1
*
* @apiUse Auth
* @apiParam {string} mail Email address from the user
* @apiParam {string} list List to subscribe
* @apiParam {string} unsubscription_token Uniq token to approve the transaction
*
* @apiUse 200
* @apiUse 403
* @apiUse 404
*/
router.get("/mail/:mail/subscribe/:list([0-9a-zA-Z\-]+)/:unsubscription_token([0-9a-zA-Z\-]+)/", function(req, res) {
var mail = req.params.mail;
var list = req.params.list;
var unsubscription_token = req.params.unsubscription_token;
if ( list === "changePassword" || list === "reminder" || list === "newsletter" || list === "monthlyreport" ) {
let result;
let time;
users.chain().find({ "email": mail, "unsubscription_token": unsubscription_token }).update(function(user) {
time = parseInt(moment().format("x"), 10);
user.unsubscription = typeof user.unsubscription!=="undefined"?user.unsubscription:{};
user.subscription = typeof user.subscription!=="undefined"?user.subscription:{};
user.unsubscription[""+list] = null;
user.subscription[""+list] = time;
t6console.debug("unsubscription", user.unsubscription);
t6console.debug("subscription", user.subscription);
result = user;
});
db_users.save();
if (req.headers && typeof req.headers["content-type"]!=="undefined" && req.headers["content-type"].indexOf("json") !== 0) {
res.status(200).send({"status": "subscribed", "list": list, "time": time});
} else {
res.render("notifications-subscribe", {
currentUrl: req.path,
user: typeof result!=="undefined"?result:{"email": mail, "unsubscription_token": unsubscription_token, "unsubscription": {} },
mail: mail,
list: list,
time: time,
moment: moment,
});
}
t6events.addStat("t6App", "subscribe", typeof result!=="undefined"?result.id:"??"+mail, typeof result!=="undefined"?result.id:"??"+mail, {"list": list});
} else {
res.status(404).send(new ErrorSerializer({"id": 11271, "code": 404, "message": "Not Found"}).serialize());
}
});
t6console.log(`Route ${path.basename(__filename)} loaded`.padEnd(59));
module.exports = router;