-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
684 lines (573 loc) · 22.8 KB
/
app.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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
require('dotenv').config();
const express = require('express');
const bodyParser = require('body-parser');
const Neo4jApi = require('./neo4j-api');
const session = require('client-sessions'); // ADD SESSION MANAGEMENT
const crypto = require('crypto');
const multer = require('multer');
const path = require('path');
const fs = require('fs');
var lastUpload;
var eventx;
var user;
let fileUploaded = false;
const db = new Neo4jApi();
const storageProfile = multer.diskStorage({
destination: './uploadsProfile/',
filename(req, file, cb) {
crypto.pseudoRandomBytes(16, (err, raw) => {
if (err) return cb(err);
/*if (req.session.usr[0].foto != null) {
const pathFoto = req.session.usr[0].foto;
fs.unlink(pathFoto);
}*/
req.session.usr[0].foto = `./uploadsProfile/${raw.toString('hex')}${path.extname(file.originalname)}`;
db.updateProfileImage(req.session.usr[0].email, req.session.usr[0].foto);
cb(null, raw.toString('hex') + path.extname(file.originalname));
});
}
});
const storagePost = multer.diskStorage({
destination: './uploadsPost/',
filename(req, file, cb) {
crypto.pseudoRandomBytes(16, (err, raw) => {
if (err) return cb(err);
lastUpload = `./uploadsPost/${raw.toString('hex')}${path.extname(file.originalname)}`;
fileUploaded = true;
cb(null, raw.toString('hex') + path.extname(file.originalname));
});
}
});
var maxSize = 1 * 1000 * 1000*1000*1000;
const uploadProfile = multer({
storage: storageProfile,
limits: { fileSize: maxSize }
});
const uploadPost = multer({
storage: storagePost,
limits: { fileSize: maxSize },
});
const app = express();
const port = process.env.PORT;
/* PATHS*/
app.use('/', express.static(`${__dirname}/www`)); // redirect root
app.use('/js', express.static(`${__dirname}/public/js`));
app.use('/js', express.static(`${__dirname}/node_modules/bootstrap/dist/js`));
app.use('/js', express.static(`${__dirname}/node_modules/jquery/dist`)); // redirect JS jQuery
app.use('/js', express.static(`${__dirname}/node_modules/jquery-validation/dist`));
app.use('/js', express.static(`${__dirname}/node_modules/moment/min`));
app.use('/js', express.static(`${__dirname}/node_modules/fullcalendar/dist`));
app.use('/js', express.static(`${__dirname}/node_modules/materialize-css/dist/js`));
app.use('/css', express.static(`${__dirname}/node_modules/bootstrap/dist/css`));
app.use('/css', express.static(`${__dirname}/node_modules/materialize-css/dist/css`));
app.use('/css', express.static(`${__dirname}/node_modules/w3-css`));
app.use('/images', express.static(`${__dirname}/public/images`));
app.use('/images', express.static(`${__dirname}/public/images/pictograms`));
app.use('/style', express.static(`${__dirname}/public/style`));
app.use('/css', express.static(`${__dirname}/node_modules/font-awesome/css`));
app.use('/fonts', express.static(`${__dirname}/node_modules/font-awesome/fonts`));
app.use('/css',express.static(`${__dirname}/node_modules/fullcalendar/dist`));
app.use('/uploadsProfile', express.static(`${__dirname}/uploadsProfile`));
app.use('/uploadsPost', express.static(`${__dirname}/uploadsPost`));
app.set('view engine', 'pug');
app.use(bodyParser.urlencoded({ extended: true }));
/* SESSION COOKIE & COOKIE MANAGEMENT*/
app.use(session({
cookieName: 'session',
secret: 'randomWord',
duration: 30 * 60 * 1000,
activeDuration: 5 * 60 * 1000,
//ephemeral: true
}));
function setLogin(email, password, res, req, page, pageer) {
db.findUser(email).then((usr) => {
if (!usr[0]) {
res.render(pageer, { error: 'Invalid email or password.' });
} else {
const hash = crypto.createHash('sha256').update(password).digest('base64');
if (usr[0].password == hash) {
user = usr[0];
req.session.usr = usr;
res.redirect(page);
} else {
res.render(pageer, { error: 'Invalid email or password.' });
}
}
});
}
function requireLogin(req, res, next) {
if (!req.session.usr) {
if (req.get('accept-language').includes('ca')) {
res.redirect('/login-ca');
} else if (req.get('accept-language').includes('es')) {
res.redirect('/login-en'); // /////////////////////////////////////////////////FALTA PAGINA CASTELLÀ
} else res.redirect('/login-en');
} else {
next();
}
}
app.get('/logout', (req, res) => {
req.session.reset();
user = null;
res.redirect('/');
});
/* AJAX FUNCTIONS*/
app.get('/getUsers', (req, res) => {
db.getAllUsers().then((users) => {
res.send(users);
});
});
/* INITIAL REDIRECT*/
app.get('/', requireLogin, (req, res) => {
if (req.get('accept-language').includes('ca')) {
res.redirect('/main-page-ca');
} else if (req.get('accept-language').includes('es')) {
res.redirect('/main-page-en'); // /////////////////////////////////////////////////FALTA PAGINA CASTELLÀ
} else res.redirect('/main-page-en');
});
/* LOGIN*/
app.get('/login-en', (req, res) => {
var passedVariable = req.query.fromreg;
res.render('./login/login-en.pug',{passedVariable});
});
app.get('/login-ca', (req, res) => {
var passedVariable = req.query.valid;
res.render('./login/login-ca.pug',{passedVariable}); // ///////////////////////////////////////////// INFO CATALÀ I CAT REQUIRED FIELDS
});
app.post('/login-en', (req, res) => {
const email = req.body.email.toLowerCase();
const password = req.body.pass1.toLowerCase();
setLogin(email, password, res, req, '/main-page-en', './login/login-en.pug');
});
app.post('/login-ca', (req, res) => {
const email = req.body.email.toLowerCase();
const password = req.body.pass1.toLowerCase();
setLogin(email, password, res, req, '/main-page-ca', './login/login-ca.pug');
});
// /////////////////////////////////////////////////////////////////////////////////////// FALTA CASTELLÀ
/* REGISTRE*/
app.get('/register-ca', (req, res) => {
res.render('./register/register-ca.pug'); // ////////////////////////////////////////////// CAT REQUIRED FIELDS
});
app.get('/register-en', (req, res) => {
res.render('./register/register-en.pug');
});
app.post('/register-ca', (req, res) => {
const name = req.body.name;
const surname = req.body.surname;
const gender = req.body.gender;
const birthday = req.body.birthday;
const email = req.body.email;
const about = req.body.about;
const password = req.body.pass1;
db.createUser(name, surname, gender, birthday, email, about, password)
.then(() => res.redirect('/'))
.catch(error => res.status(500).send(error));
});
app.post('/register-en', (req, res) => {
const name = req.body.name;
const surname = req.body.surname;
const gender = req.body.gender;
const code = req.body.code;
// FORMAT TO STANDAR DATE
const auxDate = req.body.birthday;
const parts = auxDate.split('/');
const birthday = `${parts[1]}/${parts[0]}/${parts[2]}`;
const email = req.body.email.toLowerCase();
const about = req.body.about;
const password = req.body.pass1.toLowerCase();
db.createUser(name, surname, gender, birthday, email, about, password, code)
.then(() => res.redirect('/login-en?fromreg=YES'))
.catch(error => res.status(500).send(error));
});
// ///////////////////////////////////////////////////////////////////////////////////////// FALTA CASTELLÀ
/* MAIN PAGE*/
app.get('/main-page-en', requireLogin, (req, res) => {
console.log(req.session.usr);
res.render('./mainPage/main-page-en.pug', { user: req.session.usr[0] });
});
app.get('/main-page-ca', requireLogin, (req, res) => { // ////////////////////////////////// FALTA FER
res.render('./mainPage/main-page-ca.pug', { user: req.session.usr[0] });
});
app.get('/main-page-es', requireLogin, (req, res) => { // ////////////////////////////////// FALTA FER
res.render('./mainPage/main-page-es.pug', { user: req.session.usr[0] });
});
/* MY PROFILE*/
app.get('/profile-en', requireLogin, (req, res) => {
db.getFriends(req.session.usr[0].email).then((friends) => {
db.getMyStories(req.session.usr[0].email,req.session.usr[0].email).then((posts) => {
res.render('./profile/profile-en.pug', { user:req.session.usr[0], friends, posts });
});
});
});
app.get('/profile-ca', requireLogin, (req, res) => { // ////////////////////////////////// FALTA FER
res.render('./profile/profile-ca.pug', { user });
});
app.get('/profile-es', requireLogin, (req, res) => { // ////////////////////////////////// FALTA FER
res.render('./profile/profile-es.pug', { user });
});
/* EDIT PROFILE*/
app.get('/profile-edit-en', requireLogin, (req, res) => {
res.render('./profile-edit/profile-edit-en.pug', { user:req.session.usr[0] }); // ////////////////////////////////// BULDING
});
app.get('/profile-edit-ca', requireLogin, (req, res) => { // ////////////////////////////////// FALTA FER
res.render('./profile-edit/profile-edit-ca.pug', { user:req.session.usr[0] });
});
app.get('/profile-edit-es', requireLogin, (req, res) => { // ////////////////////////////////// FALTA FER
res.render('./profile-edit/profile-edit-es.pug', { user:req.session.usr[0] });
});
app.post('/upload-profile-image', uploadProfile.single('file'), (req, res) => {
res.send('OK');
//res.redirect('/profile-en');
});
app.post('/redirect-after-profile-image', requireLogin, (req, res) => {
//res.send('OK');
res.redirect('/profile-en');
});
app.post('/upload-profile-about', requireLogin, (req, res) => {
const about = req.body.about;
req.session.usr[0].about = about;
db.updateProfileAbout(req.session.usr[0].email, about);
res.redirect('/profile-en');
});
/* NEW POST*/
app.get('/new-post-en', requireLogin, (req, res) => { // ////////////////////////////////// BULDING
res.render('./new-post/new-post-en.pug');
});
app.get('/new-post-es', requireLogin, (req, res) => { // ////////////////////////////////// FALTA FER
res.render('./new-post/new-post-es.pug');
});
app.get('/new-post-en', requireLogin, (req, res) => { // ////////////////////////////////// FALTA FER
res.render('./new-post/new-post-ca.pug');
});
app.post('/post-image', uploadPost.single('file'), (req, res) => {
res.send('OK');
});
app.post('/post-story/:description', requireLogin, (req, res) => {
const description = req.params.description;
const date = new Date();
const dateInMilliseconds = date.getTime();
const usuari = `${req.session.usr[0].name} ${req.session.usr[0].surname}`;
console.log("ehehehehehhehehe");
if(fileUploaded===true){
console.log("1");
db.newPost(req.session.usr[0].email, description, lastUpload, dateInMilliseconds, usuari).then(() => {
console.log("POST");
db.relationToNewPost(req.session.usr[0].email, dateInMilliseconds);
});
console.log("LOG");
}
else{
console.log("2");
db.newPost(req.session.usr[0].email, description, 'nothing', dateInMilliseconds, usuari).then(() => {
console.log("POST");
db.relationToNewPost(req.session.usr[0].email, dateInMilliseconds);
});
console.log("LOG");
}
fileUploaded=false;
res.send('OK');
});
app.post('/redirect-after-post', requireLogin, (req, res) => { // ////////////////////////////////// FALTA FER
res.redirect('/main-page-en');
});
/* MY STORIES*/
app.get('/my-posts-en', requireLogin, (req, res) => { // ////////////////////////////////// BULDING
db.getMyStories(req.session.usr[0].email,req.session.usr[0].email).then((posts) => {
res.render('./my-posts/my-posts-en.pug', { posts, user:req.session.usr[0] });
});
});
app.get('/my-posts-es', requireLogin, (req, res) => { // ////////////////////////////////// FALTA FER
db.getMyStories(req.session.usr[0].email,req.session.usr[0].email).then((posts) => {
res.render('./my-posts/my-posts-es.pug', { posts, user:req.session.usr[0] });
});
});
app.get('/my-posts-ca', requireLogin, (req, res) => { // ////////////////////////////////// FALTA FER
db.getMyStories(req.session.usr[0].email,req.session.usr[0].email).then((posts) => {
res.render('./my-posts/my-posts-ca.pug', { posts, user:req.session.usr[0] });
});
});
/* SEARCH PEOPLE*/
app.get('/search-people-en', requireLogin, (req, res) => { // ////////////////////////////////// BULDING
res.render('./search-people/search-people-en.pug');
});
app.get('/search-people-es', requireLogin, (req, res) => { // ////////////////////////////////// FALTA FER
res.render('./search-people/search-people-es.pug');
});
app.get('/search-people-en', requireLogin, (req, res) => { // ////////////////////////////////// FALTA FER
res.render('./search-people/search-people-ca.pug');
});
app.get('/get-people-by-name/:letters', requireLogin, (req, res) => {
const letters = req.params.letters;
db.getUsersByName(letters, req.session.usr[0].email).then((users) => {
res.send(users);
});
});
app.get('/get-people', requireLogin, (req, res) => {
db.getAllUsersPossible(req.session.usr[0].email).then((users) => {
res.send(users);
});
});
app.post('/send-friend-request/:targetEmail', requireLogin, (req, res) => {
const targetEmail = req.params.targetEmail;
db.sendRequest(req.session.usr[0].email, targetEmail).then(() => {
res.send('OK');
});
});
/* MY FRIENDS*/
app.get('/my-friends-en', requireLogin, (req, res) => { // ////////////////////////////////// BULDING
db.getFriends(req.session.usr[0].email).then((friends) => {
res.render('./my-friends/my-friends-en.pug', { friends });
});
});
app.get('/my-friends-es', requireLogin, (req, res) => { // ////////////////////////////////// FALTA FER
res.render('./my-friends/my-friends-es.pug');
});
app.get('/my-friends-en', requireLogin, (req, res) => { // ////////////////////////////////// FALTA FER
res.render('./my-friends/my-friends-ca.pug');
});
app.get('/get-my-requests', requireLogin, (req, res) => {
db.getMyFriendResquests(req.session.usr[0].email).then((users) => {
res.send(users);
});
});
app.get('/get-friends', requireLogin, (req, res) => {
db.getFriends(req.session.usr[0].email).then((users) => {
res.send(users);
});
});
app.get('/get-requests', requireLogin, (req, res) => {
db.getFriendResquests(req.session.usr[0].email).then((users) => {
res.send(users);
});
});
app.post('/accept-request/:targetEmail', requireLogin, (req, res) => {
const targetEmail = req.params.targetEmail;
db.deleteRequest(req.session.usr[0].email, targetEmail).then(() => {
db.createFriend(req.session.usr[0].email, targetEmail).then(() => {
db.createFriend(targetEmail, req.session.usr[0].email).then(() => {
res.send('OK');
});
});
});
});
app.post('/decline-request/:targetEmail', requireLogin, (req, res) => {
const targetEmail = req.params.targetEmail;
db.deleteRequest(req.session.usr[0].email, targetEmail).then(() => {
res.send("OK");
});
});
/* OTHER PROFILE*/
app.get('/profile-out-en/:targetEmail', requireLogin, (req, res) => {
const email = req.params.targetEmail;
if (email == req.session.usr[0].email) res.redirect('/profile-en');
else {
db.findUser(email).then((result) => {
const usuari = result[0];
db.getFriends(email).then((result2) => {
const friends = result2;
db.getMyStories(email,req.session.usr[0].email).then((result3) => {
const posts = result3;
db.getIfFriend(email,req.session.usr[0].email).then((result4) => {
var isFriend = false;
if(result4[0]!=null) isFriend=true;
res.render('./profile-out/profile-out-en.pug', { usuari, friends, posts,isFriend});
});
});
});
});
}
});
app.post('/delete-friend/:targetEmail', requireLogin, (req, res) => {
const targetEmail = req.params.targetEmail;
db.deleteFriend(req.session.usr[0].email, targetEmail).then(() => {
db.deleteFriend(targetEmail, req.session.usr[0].email).then(() => {
res.send("OK");
});
});
});
app.get('/profile-out-ca/:targetEmail', requireLogin, (req, res) => {
res.render('./profile-out/profile-out-ca.pug', { user:req.session.usr[0] });
});
app.get('/profile-out-es/:targetEmail', requireLogin, (req, res) => {
res.render('./profile-out/profile-out-es.pug', { user:req.session.usr[0] });
});
/*TIMELINE*/
app.get('/timeline-en', requireLogin, (req, res) => {
db.getFriendsPosts(req.session.usr[0].email).then((result3) => {
const posts = result3;
res.render('./timeline/timeline-en.pug', { posts });
});
});
app.get('/timeline-ca', requireLogin, (req, res) => {
db.getFriendsPosts(req.session.usr[0].email).then((result3) => {
const posts = result3;
res.render('./timeline/timeline-ca.pug', { posts });
});
});
app.get('/timeline-es', requireLogin, (req, res) => {
db.getFriendsPosts(req.session.usr[0].email).then((result3) => {
const posts = result3;
res.render('./timeline/timeline-es.pug', { posts });
});
});
/*CREATE EVENT*/ //TODO
app.get('/create-event-en', requireLogin, (req, res) => { //DONE
res.render('./create-event/create-event-en.pug');
});
app.get('/create-event-es', requireLogin, (req, res) => {
db.getFriendsPosts(req.session.usr[0].email).then((result3) => {
const posts = result3;
res.render('./timeline/create-event-es.pug', { posts });
});
});
app.get('/create-event-es', requireLogin, (req, res) => {
db.getFriendsPosts(req.session.usr[0].email).then((result3) => {
const posts = result3;
res.render('./timeline/create-event-es.pug', { posts });
});
});
app.post('/create-event', requireLogin, (req, res) => {
const description = req.body.description;
const title = req.body.title;
const place = req.body.place;
const start = req.body.start;
const end = req.body.end;
const date = new Date();
const dateInMilliseconds = date.getTime();
const usuari = `${req.session.usr[0].name} ${req.session.usr[0].surname}`;
db.newEvent(req.session.usr[0].email, title, start, end, place, description, dateInMilliseconds, usuari)
.then((resp) => {
db.relationToNewEvent(req.session.usr[0].email, dateInMilliseconds).then(() =>{
db.getEventByTime(dateInMilliseconds).then((response) =>{
eventx = response[0].uuid;
res.redirect('/event-invitations-en');
});
});
});
});
/*EVENT INVITATIONS*/
app.get('/event-invitations-en',requireLogin, (req,res) =>{
db.getFriendsForEvent(req.session.usr[0].email,eventx).then((friends) => {
res.render('./event-invitations/event-invitations-en.pug', {friends});
});
});
app.get('/event-invitations-en/:event',requireLogin, (req,res) =>{
eventx = req.params.event;
db.getFriendsForEvent(req.session.usr[0].email,eventx).then((friends) => {
res.render('./event-invitations/event-invitations-en.pug', {friends});
});
});
app.get('/event-invitations-es',requireLogin, (req,res) =>{
db.getFriends(req.session.usr[0].email).then((friends) => {
res.render('./event-invitations/event-invitations-es.pug', {friends});
});
});
app.get('/event-invitations-ca',requireLogin, (req,res) =>{
db.getFriends(req.session.usr[0].email).then((friends) => {
res.render('./event-invitations/event-invitations-ca.pug', {friends});
});
});
app.post('/send-invitation/:targetEmail', requireLogin, (req, res) => {
const targetEmail = req.params.targetEmail;
console.log("here");
db.sendInvitation(eventx, targetEmail).then(() => {
res.send('OK');
});
});
/*EVENT MANAGING*/ //TODO
app.get('/getevents', requireLogin, (req,res) =>{
db.getMyEvents(req.session.usr[0].email).then((events) => {
res.send(events);
});
});
app.get('/see-events-en', requireLogin, (req, res) => {
db.getMyEventsInvitations(req.session.usr[0].email).then((invitations) => {
if(req.session.usr[0].isadmin=='YES'){
db.getMyEventsOnly(req.session.usr[0].email).then((events) => {
res.render('./see-events/see-events-en.pug', { invitations,events,user:req.session.usr[0] });
});
}
else res.render('./see-events/see-events-en.pug', { invitations,user:req.session.usr[0] });
});
});
app.post('/accept-invitation/:uuid', requireLogin, (req, res) => {
const uuid = req.params.uuid;
db.deleteRequestEvent(req.session.usr[0].email, uuid).then(() => {
db.createEventRelationship(req.session.usr[0].email, uuid).then(() => {
res.send('OK');
});
});
});
app.post('/delete-invitation/:uuid', requireLogin, (req, res) => {
const uuid = req.params.uuid;
console.log("deleted");
db.deleteRequestEvent(req.session.usr[0].email, uuid).then(() => {
res.send('OK');
});
});
app.post('/delete-event/:uuid', requireLogin, (req, res) => {
const uuid = req.params.uuid;
db.deleteEvent(uuid).then(() => {
res.send("OK");
});
});
/*ADMIN-CONSOLE*/ //TODO
app.get('/admin-console-en', requireLogin, (req, res) => {
db.getUsersWithCode(req.session.usr[0].uuid).then((result3) => {
const friends = result3;
res.render('./admin-console/admin-console-en.pug', { friends,user:req.session.usr[0] });
});
});
app.get('/admin-console-ca', requireLogin, (req, res) => {
db.getFriendsPosts(req.session.usr[0].email).then((result3) => {
const posts = result3;
res.render('./admin-console/admin-console-ca.pug', { posts });
});
});
app.get('/admin-console-es', requireLogin, (req, res) => {
db.getFriendsPosts(req.session.usr[0].email).then((result3) => {
const posts = result3;
res.render('./admin-console/admin-console-es.pug', { posts });
});
});
/*LIKE/UNLIKE/DELETE POST*/
app.post('/like/:uuid', requireLogin, (req, res) => {
const uuid = req.params.uuid;
db.like(req.session.usr[0].email, uuid).then(() => {
res.send('OK');
});
});
app.post('/unlike/:uuid', requireLogin, (req, res) => {
const uuid = req.params.uuid;
db.unlike(req.session.usr[0].email, uuid).then(() => {
res.send('OK');
});
});
app.post('/deletePost/:uuid', requireLogin, (req, res) => {
const uuid = req.params.uuid;
db.deletePost(uuid).then(() => {
res.send('OK');
});
});
/* SOMETHING */
app.post('/aux', (req, res) => {
const name = req.body.name;
db.createNode(name)
.then(() => res.redirect('/'))
.catch(error => res.status(500).send(error));
});
app.post('/clear', (req, res) => {
db.clearNodes()
.then(() => res.redirect('/'))
.catch(error => res.status(500).send(error));
});
app.get('/aux', requireLogin, (req, res) => {
db.getNodes()
.then((nodes) => {
res.render('./home.pug', { nodes });
})
.catch(error => res.status(500).send(error));
});
app.listen(port,
() => console.log(`Server listening on http://localhost:${port}`));