spacedeck-open/routes/root.js

146 lines
3.1 KiB
JavaScript
Raw Permalink Normal View History

2017-04-07 01:29:05 +02:00
"use strict";
const config = require('config');
const redis = require('../helpers/redis');
const express = require('express');
const crypto = require('crypto');
const router = express.Router();
const mailer = require('../helpers/mailer');
const _ = require('underscore');
2018-04-14 22:27:38 +02:00
const db = require('../models/db');
const Sequelize = require('sequelize');
const Op = Sequelize.Op;
const uuidv4 = require('uuid/v4');
2017-04-07 01:29:05 +02:00
router.get('/', (req, res) => {
res.render('index', { title: 'Spaces' });
});
router.get('/ping', (req, res) => {
res.status(200).json({"status": "ok"})
});
router.get('/spaces', (req, res) => {
res.render('spacedeck', { title: 'Spaces' });
});
router.get('/not_found', (req, res) => {
res.render('not_found', { title: 'Spaces' });
});
router.get('/confirm/:token', (req, res) => {
res.render('spacedeck', { title: 'Space' });
});
router.get('/folders/:id', (req, res) => {
res.render('spacedeck', {});
});
router.get('/signup', (req, res) => {
res.render('spacedeck', {});
});
router.get('/accept/:id', (req, res) => {
res.render('spacedeck', {});
});
router.get('/password-reset', (req, res) => {
res.render('spacedeck', { title: 'Signup' });
});
router.get('/password-confirm/:token', (req, res) => {
res.render('spacedeck', { title: 'Signup' });
});
router.get('/de/*', (req, res) => {
res.redirect("/t/de");
});
router.get('/de', (req, res) => {
res.redirect("/t/de");
});
router.get('/fr/*', (req, res) => {
res.redirect("/t/fr");
});
router.get('/fr', (req, res) => {
res.redirect("/t/fr");
});
router.get('/en/*', (req, res) => {
res.redirect("/t/en");
});
router.get('/en', (req, res) => {
res.redirect("/t/end");
});
router.get('/account', (req, res) => {
res.render('spacedeck');
});
router.get('/login', (req, res) => {
res.render('spacedeck');
});
router.get('/logout', (req, res) => {
res.render('spacedeck');
});
router.get('/contact', (req, res) => {
res.render('public/contact');
});
router.get('/about', (req, res) => {
res.render('public/about');
});
router.get('/terms', (req, res) => {
res.render('public/terms');
});
router.get('/privacy', (req, res) => {
res.render('public/privacy');
});
router.get('/t/:id', (req, res) => {
res.cookie('spacedeck_locale', req.params.id, { maxAge: 900000, httpOnly: true });
var path = "/";
if (req.query.r=="login" || req.query.r=="signup") {
path = "/"+req.query.r;
}
res.redirect(path);
});
router.get('/s/:token', (req, res) => {
2018-04-14 22:27:38 +02:00
var token = req.params.token;
if (token.split("-").length > 0) {
token = token.split("-")[0];
}
2017-04-07 01:29:05 +02:00
2018-04-14 22:27:38 +02:00
db.Space.findOne({where: {"edit_hash": token}}).then(function (space) {
if (space) {
if (req.accepts('text/html')){
2020-04-09 16:22:17 +02:00
res.redirect("/spaces/"+space._id + "?spaceAuth=" + token);
2018-04-14 22:27:38 +02:00
} else {
2020-04-09 16:22:17 +02:00
res.status(200).json(space);
2018-04-14 22:27:38 +02:00
}
2017-04-07 01:29:05 +02:00
} else {
2018-04-14 22:27:38 +02:00
if (req.accepts('text/html')) {
2020-04-09 16:22:17 +02:00
res.status(404).render('not_found', { title: 'Page Not Found.' });
2018-04-14 22:27:38 +02:00
} else {
2020-04-09 16:22:17 +02:00
res.status(404).json({});
2018-04-14 22:27:38 +02:00
}
2017-04-07 01:29:05 +02:00
}
});
});
router.get('/spaces/:id', (req, res) => {
2018-04-14 22:27:38 +02:00
res.render('spacedeck', { title: 'Space' });
2017-04-07 01:29:05 +02:00
});
module.exports = router;