p5.js-web-editor/server/routes/server.routes.js

115 lines
2.8 KiB
JavaScript
Raw Normal View History

2016-06-24 00:29:55 +02:00
import { Router } from 'express';
import { renderIndex } from '../views/index';
2017-01-06 21:05:02 +01:00
import { get404Sketch } from '../views/404Page';
import { userExists } from '../controllers/user.controller';
import { projectExists, projectForUserExists } from '../controllers/project.controller';
const router = new Router();
2016-06-19 00:33:49 +02:00
2016-06-24 00:29:55 +02:00
// this is intended to be a temporary file
2016-06-19 00:33:49 +02:00
// until i figure out isomorphic rendering
router.get('/', (req, res) => {
res.send(renderIndex());
2016-06-19 00:33:49 +02:00
});
router.get('/signup', (req, res) => {
if (req.user) {
return res.redirect('/');
}
2017-10-16 05:27:05 +02:00
return res.send(renderIndex());
2016-06-19 00:33:49 +02:00
});
router.get('/projects/:project_id', (req, res) => {
projectExists(req.params.project_id, exists => (
exists ? res.send(renderIndex()) : get404Sketch(html => res.send(html))
));
2016-06-19 00:33:49 +02:00
});
router.get('/:username/sketches/:project_id', (req, res) => {
projectForUserExists(req.params.username, req.params.project_id, exists => (
exists ? res.send(renderIndex()) : get404Sketch(html => res.send(html))
));
});
router.get('/:username/full/:project_id', (req, res) => {
projectForUserExists(req.params.username, req.params.project_id, exists => (
exists ? res.send(renderIndex()) : get404Sketch(html => res.send(html))
));
});
router.get('/full/:project_id', (req, res) => {
projectExists(req.params.project_id, exists => (
exists ? res.send(renderIndex()) : get404Sketch(html => res.send(html))
));
});
2016-08-18 00:13:17 +02:00
router.get('/login', (req, res) => {
if (req.user) {
return res.redirect('/');
}
2017-10-16 05:27:05 +02:00
return res.send(renderIndex());
2016-06-19 00:33:49 +02:00
});
router.get('/reset-password', (req, res) => {
res.send(renderIndex());
2016-10-12 18:02:46 +02:00
});
router.get('/reset-password/:reset_password_token', (req, res) => {
res.send(renderIndex());
});
router.get('/verify', (req, res) => {
Email verification (#369) * Re-introduce Email Verification code Revert "Revert "Email verification"" This reverts commit d154d8bff259350523a0f139e844db96c43d2ee1. * Uses MJML to generate Reset Password email * Sends Password Reset and Email Confirmation emails using MJML template * Sends verified status along with user data * API endpoint for resending email verification confirmation * Displays verification status on Account page and allows resending * Send back error string * Passes email address through to sign/verify helper * Uses enum-style object to set verified state * Sends minimal info when user verifies since it can be done without login * Provides /verify UI and sends confirmation token to API * Better name for JWT secret token env var * Adds mail config variables to Readme * Encrypts email address in JWT The JWT sent as the token in the Confirm Password URL can be unencoded by anyone, although it's signature can only be verified by us. To ensure that no passwords are leaked, we encrypt the email address before creating the token. * Removes unused mail templates * Resets verified flag when email is changed and sends another email * Moves email confirmation functions next to each other * Extracts random token generator to helper * Moves email confirmation actions into Redux - updates the AccountForm label with a message to check inbox - show status when verifying email token * Uses generated token stored in DB for email confirmation * Sets email confirmation status to verified if logging in from Github * Sends email using new method on account creation * Fixes linting errors * Removes replyTo config
2017-06-26 18:48:28 +02:00
res.send(renderIndex());
});
router.get('/sketches', (req, res) => {
2018-05-30 23:23:11 +02:00
if (req.user) {
res.send(renderIndex());
} else {
res.redirect('/login');
}
});
router.get('/assets', (req, res) => {
2018-05-30 23:23:11 +02:00
if (req.user) {
res.send(renderIndex());
} else {
res.redirect('/login');
}
});
router.get('/:username/assets', (req, res) => {
userExists(req.params.username, (exists) => {
const isLoggedInUser = req.user && req.user.username === req.params.username;
const canAccess = exists && isLoggedInUser;
return canAccess ?
res.send(renderIndex()) :
get404Sketch(html => res.send(html));
});
});
router.get('/account', (req, res) => {
2018-05-30 23:23:11 +02:00
if (req.user) {
res.send(renderIndex());
} else {
res.redirect('/login');
}
2016-07-05 22:04:14 +02:00
});
router.get('/about', (req, res) => {
res.send(renderIndex());
2016-08-22 18:35:59 +02:00
});
2018-02-09 22:32:06 +01:00
router.get('/feedback', (req, res) => {
res.send(renderIndex());
});
router.get('/:username/sketches', (req, res) => {
userExists(req.params.username, exists => (
exists ? res.send(renderIndex()) : get404Sketch(html => res.send(html))
));
});
2016-06-24 00:29:55 +02:00
export default router;