entry_control.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. var _ = require('lodash');
  2. var async = require('async');
  3. var crypto = require('crypto');
  4. var nodemailer = require('nodemailer');
  5. var passport = require('passport');
  6. var User = require('../models/user');
  7. var Entry = require('../models/entry');
  8. var secure = require('../config/secure');
  9. /********** GET / Entry **************/
  10. exports.getEntry = function (req, res) {
  11. res.render('entry/entry', {
  12. title: 'Entry'
  13. });
  14. };
  15. /********** GET / New Entry **************/
  16. exports.getEntry_new = function (req, res) {
  17. res.render('entry/entry_new', {
  18. title: 'Create an Entry'
  19. });
  20. };
  21. /********** POST / New Entry **************/
  22. exports.postEntry_new= function(req, res, next) {
  23. var errors = req.validationErrors();
  24. var event = new Entry ({
  25. entryname: req.body.evenname
  26. });
  27. Event.findOne({ eventname: req.body.eventname }, function(err, existingEvent) {
  28. if (existingEvent) {
  29. req.flash('errors', { msg: 'Event with that name already exists.' });
  30. return res.redirect('/entry/error');
  31. }
  32. event.save(function(err) {
  33. if (err) {
  34. return next(err);
  35. }
  36. req.flash('success', { msg: 'Success!' });
  37. res.redirect(req.session.returnTo || '/');
  38. });
  39. });
  40. };