Browse Source

entry/event routes

windhamdavid 3 years ago
parent
commit
0feb6fb863

+ 30 - 8
app.js

@@ -102,7 +102,6 @@ app.use(function(req, res, next) {
 
 var router = express.Router();
 app.use(router);
-var routes = require('./routes/routes');
 
 var homeController = require('./controllers/home');
 var userController = require('./controllers/user');
@@ -115,7 +114,6 @@ var apiController = require('./controllers/api');
 /********** user routes **************/
 
 router.get('/', homeController.index);
-
 router.get('/login', userController.getLogin);
 router.post('/login', userController.postLogin);
 router.get('/logout', userController.logout);
@@ -125,26 +123,30 @@ router.get('/reset/:token', userController.getReset);
 router.post('/reset/:token', userController.postReset);
 router.get('/register', userController.getSignup);
 router.post('/register', userController.postSignup);
-router.get('/contact', contactController.getContact);
-router.post('/contact', contactController.postContact);
 router.get('/account', passportConf.isAuthenticated, userController.getAccount);
 router.post('/account/profile', passportConf.isAuthenticated, userController.postUpdateProfile);
 router.post('/account/password', passportConf.isAuthenticated, userController.postUpdatePassword);
 router.post('/account/delete', passportConf.isAuthenticated, userController.postDeleteAccount);
 router.get('/account/unlink/:provider', passportConf.isAuthenticated, userController.getOauthUnlink);
 
+
 /********** event routes **************/
 
-router.get('/events', eventsController.getEvent);
+var eventRouter = require('./routes/events');
+app.use('/event', eventRouter);
 
 
 /********** entry routes **************/
 
-router.get('/entry', entriesController.getEntry);
+var entryRouter = require('./routes/entry');
+app.use('/entry', entryRouter);
 
 
 /********** static routes controllers **************/
 
+router.get('/contact', contactController.getContact);
+router.post('/contact', contactController.postContact);
+
 router.get('/about', function(req, res) {
   res.render('pages/about', { title: 'About' });
 });
@@ -166,10 +168,8 @@ router.get('/support', function(req, res) {
 
 
 
-
 /************* log **************/
 
-
 app.use(logger('common', {
     stream: fs.createWriteStream('./log/access.log', {flags: 'a'})
 }));
@@ -197,6 +197,28 @@ app.use(function handleNotFound(req, res, next){
   };
 });
 
+// development error handler
+// will print stacktrace
+if (app.get('env') === 'development') {
+  app.use(function(err, req, res, next) {
+    res.status(err.status || 500);
+    res.render('error', {
+      message: err.message,
+      error: err
+    });
+  });
+}
+
+// production error handler
+// no stacktraces leaked to user
+app.use(function(err, req, res, next) {
+  res.status(err.status || 500);
+  res.render('error', {
+    message: err.message,
+    error: {}
+  });
+});
+
 if (process.env.NODE_ENV === 'development') {
   app.use(errorHandler())
 };

+ 2 - 2
controllers/events.js

@@ -7,10 +7,10 @@ var User = require('../models/user');
 var secure = require('../config/secure');
 
 
-/********** GET / Login **************/
+/********** GET / Event **************/
 
 exports.getEvent = function (req, res) {
   res.render('events/event', {
     title: 'Events'
   });
-};
+};

+ 6 - 1
controllers/home.js

@@ -1,5 +1,10 @@
 exports.index = function(req, res) {
-  res.render('index', {
+  if (req.user) {
+    if (req.user) {
+      return res.redirect('/:username');
+    }
+  }
+  res.render('pages/index', {
     title: 'You Be the Judge'
   });
 };

+ 1 - 0
controllers/user.js

@@ -132,6 +132,7 @@ exports.postUpdateProfile = function(req, res, next) {
     user.profile.gender = req.body.gender || '';
     user.profile.location = req.body.location || '';
     user.profile.website = req.body.website || '';
+    user.profile.bio = req.body.bio || '';
     user.save(function(err) {
       if (err) {
         return next(err);

+ 1 - 0
models/user.js

@@ -13,6 +13,7 @@ var userSchema = new mongoose.Schema({
     gender: { type: String, default: '' },
     location: { type: String, default: '' },
     website: { type: String, default: '' },
+    bio: { type: String, default: '' },
     picture: { type: String, default: '' }
   },
 

+ 8 - 0
routes/entry.js

@@ -0,0 +1,8 @@
+var express = require('express');
+var app = express();
+var router = express.Router();
+var eventsController = require('../controllers/events');
+
+router.get('/entry', eventsController.getEvent);
+
+module.exports = router;

+ 8 - 0
routes/events.js

@@ -0,0 +1,8 @@
+var express = require('express');
+var app = express();
+var router = express.Router();
+var eventsController = require('../controllers/events');
+
+router.get('../event', eventsController.getEvent);
+
+module.exports = router;

+ 0 - 58
routes/routes.js

@@ -1,58 +0,0 @@
-var express = require('express');
-var app = express();
-var router = express.Router();
-
-var path = require('path');
-var secure = require('../config/secure');
-var passportConf = require('../config/passport');
-
-
-/********** routes controllers **************/
-
-var homeController = require('../controllers/home');
-var userController = require('../controllers/user');
-var contactController = require('../controllers/contact');
-var apiController = require('../controllers/api');
-
-
-/*************** routes *******************/
-
-router.get('/', homeController.index);
-router.get('/login', userController.getLogin);
-router.post('/login', userController.postLogin);
-router.get('/logout', userController.logout);
-router.get('/forgot', userController.getForgot);
-router.post('/forgot', userController.postForgot);
-router.get('/reset/:token', userController.getReset);
-router.post('/reset/:token', userController.postReset);
-router.get('/register', userController.getSignup);
-router.post('/register', userController.postSignup);
-router.get('/contact', contactController.getContact);
-router.post('/contact', contactController.postContact);
-router.get('/account', passportConf.isAuthenticated, userController.getAccount);
-router.post('/account/profile', passportConf.isAuthenticated, userController.postUpdateProfile);
-router.post('/account/password', passportConf.isAuthenticated, userController.postUpdatePassword);
-router.post('/account/delete', passportConf.isAuthenticated, userController.postDeleteAccount);
-router.get('/account/unlink/:provider', passportConf.isAuthenticated, userController.getOauthUnlink);
-
-
-/********** oauth routes controllers **************/
-
-
-/********** static routes controllers **************/
-
-router.get('/about', function(req, res) {
-  res.render('pages/about', { title: 'Privacy Policy' });
-});
-router.get('/privacy', function(req, res) {
-  res.render('pages/privacy', { title: 'Privacy Policy' });
-});
-router.get('/terms', function(req, res) {
-  res.render('pages/terms', { title: 'Terms & Conditions' });
-});
-
-
-
-
-
-module.exports = router

+ 27 - 0
routes/static.js

@@ -0,0 +1,27 @@
+var express = require('express');
+var app = express();
+var router = express.Router();
+
+
+/********** static routes **************/
+
+router.get('/about', function(req, res) {
+  res.render('pages/about', { title: 'About' });
+});
+router.get('/docs', function(req, res) {
+  res.render('pages/docs', { title: 'Documentation' });
+});
+router.get('/privacy', function(req, res) {
+  res.render('pages/privacy', { title: 'Privacy Policy' });
+});
+router.get('/terms', function(req, res) {
+  res.render('pages/terms', { title: 'Terms & Conditions' });
+});
+router.get('/status', function(req, res) {
+  res.render('pages/status', { title: 'System Status' });
+});
+router.get('/support', function(req, res) {
+  res.render('pages/support', { title: 'Support' });
+});
+
+module.exports = router

+ 11 - 0
routes/user.js

@@ -0,0 +1,11 @@
+app.param('user_id', function(req, res, next, user_id) {
+
+  UserDatabase.find(user_id, function(err, user) {
+    if (err) return next(err);
+    if (!user) return next(
+      
+    );
+    req.user = user;
+    next()
+  });
+});

+ 4 - 0
src/views/account/profile.jade

@@ -40,6 +40,10 @@ block content
             .col-sm-7
               input.form-control(type='text', name='website', id='website', value='#{user.profile.website}')
           .form-group
+            label.col-sm-3.control-label(for='bio') Bio
+            .col-sm-7
+              input.form-control(type='text', name='bio', id='bio', value='#{user.profile.bio}')     
+          .form-group
             label.col-sm-3.control-label(for='gravatar') Gravatar
             .col-sm-4
               img(src="#{user.gravatar()}", class='profile', width='100', height='100')

+ 72 - 0
src/views/home.jade

@@ -0,0 +1,72 @@
+extends layout
+
+block content
+header
+  .container-fluid
+    .header-content
+      .header-content-inner
+        .row
+          .col-sm-8
+            h1 Juryd
+            h2 You be the Judge
+            hr
+            h4 Juryd is an application that allows the participants to register and vote.
+          .col-sm-4
+            img.svg(src="img/ribbon.svg")
+  section#about
+    .container
+      .row
+        .col-sm-8
+          img.svg(src="img/ipad.svg")
+        .col-sm-4.text-center
+          h2.section-heading How It Works
+          hr.light
+          p Some Copy
+  section#details
+    .container
+      .row.text-center
+        .col-sm-4
+          h3.section-heading Juried Competition
+          p Some Copy
+        .col-sm-4
+          h3.section-heading Registrant Jury
+          p Some Copy
+        .col-sm-4
+          h3.section-heading Registered Judges
+          p Some Copy
+  section#features
+    .container
+      .row.text-center
+        .col-sm-6
+          h2.section-heading Features
+          p Some Copy
+          img.svg.icon-small.blue-ribbon(src="img/ribbon.svg")
+          img.svg.icon-small.red-ribbon(src="img/ribbon.svg")
+          img.svg.icon-small.yellow-ribbon(src="img/ribbon.svg")
+        .col-sm-6
+          img.svg(src="img/phone.svg")
+  section#account
+    .container
+      .row.text-center
+        .col-sm-6
+          h2.section-heading About
+          p Some Copy
+        .col-sm-6
+          h2.section-heading About
+          p Some Copy
+  section#call
+    .container
+      .row
+        .col-sm-4.col-lg-offset-2.text-center
+          h4.section-heading Connect
+          hr.light
+          p (Social Media Icons)
+        .col-sm-4.text-center
+          h4.section-heading Get the Latest
+          form.form-inline
+            .form-group
+              label.sr-only(for="exampleInputAmount") Email Addresss
+              .input-group
+                input#email-address.form-control(type="text", placeholder="Email Address")
+                .input-group-addon
+                  button.btn.btn-primary(type="submit") GO

+ 1 - 1
src/views/pages/about.jade

@@ -1,4 +1,4 @@
-extends layout
+extends ../layout
 
 block content
 

+ 0 - 72
src/views/pages/home.jade

@@ -1,72 +0,0 @@
-extends layout
-
-block content
-header
-  .container-fluid
-    .header-content
-      .header-content-inner
-        .row
-          .col-sm-8
-            h1 Juryd
-            h2 You be the Judge
-            hr
-            h4 Juryd is an application that allows the participants to register and vote.
-          .col-sm-4
-            img.svg(src="img/ribbon.svg")
-section#about
-  .container
-    .row
-      .col-sm-8
-        img.svg(src="img/ipad.svg")
-      .col-sm-4.text-center
-        h2.section-heading How It Works
-        hr.light
-        p Some Copy
-section#details
-  .container
-    .row.text-center
-      .col-sm-4
-        h3.section-heading Juried Competition
-        p Some Copy
-      .col-sm-4
-        h3.section-heading Registrant Jury
-        p Some Copy
-      .col-sm-4
-        h3.section-heading Registered Judges
-        p Some Copy
-section#features
-  .container
-    .row.text-center
-      .col-sm-6
-        h2.section-heading Features
-        p Some Copy
-        img.svg.icon-small.blue-ribbon(src="img/ribbon.svg")
-        img.svg.icon-small.red-ribbon(src="img/ribbon.svg")
-        img.svg.icon-small.yellow-ribbon(src="img/ribbon.svg")
-      .col-sm-6
-        img.svg(src="img/phone.svg")
-section#account
-  .container
-    .row.text-center
-      .col-sm-6
-        h2.section-heading About
-        p Some Copy
-      .col-sm-6
-        h2.section-heading About
-        p Some Copy
-section#call
-  .container
-    .row
-      .col-sm-4.col-lg-offset-2.text-center
-        h4.section-heading Connect
-        hr.light
-        p (Social Media Icons)
-      .col-sm-4.text-center
-        h4.section-heading Get the Latest
-        form.form-inline
-          .form-group
-            label.sr-only(for="exampleInputAmount") Email Addresss
-            .input-group
-              input#email-address.form-control(type="text", placeholder="Email Address")
-              .input-group-addon
-                button.btn.btn-primary(type="submit") GO

+ 1 - 1
src/views/index.jade

@@ -1,4 +1,4 @@
-extends layout
+extends ../layout
 
 block content
 

+ 1 - 1
src/views/partials/header.jade

@@ -7,7 +7,7 @@ nav#mainNav.navbar.navbar-default.navbar-fixed-top
         span.icon-bar
         span.icon-bar
       a.navbar-brand(href='/')
-        img.svg.icon-small(src="img/ribbon.svg")
+        img.svg.icon-small(src="/img/ribbon.svg")
     .collapse.navbar-collapse
       ul.nav.navbar-nav