event_control.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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 Event = require('../models/event');
  8. var secure = require('../config/secure');
  9. /********** GET / Event **************/
  10. exports.getEvent = function (req, res) {
  11. res.render('event/event', {
  12. title: 'Event'
  13. });
  14. };
  15. /********** GET / New Event **************/
  16. exports.getEvent_new = function (req, res) {
  17. res.render('event/event_new', {
  18. title: 'Create an Event'
  19. });
  20. };
  21. /********** POST / New Event **************/
  22. exports.postEvent_new= function(req, res, next) {
  23. var event = new Event({
  24. eventname: req.body.eventname,
  25. eventdesc: req.body.eventdesc,
  26. eventopendate: req.body.eventopendate,
  27. eventenddate: req.body.eventenddate,
  28. registrationtype: req.body.registrationtype,
  29. jurytype: req.body.jurytype,
  30. });
  31. var errors = req.validationErrors();
  32. Event.findOne({ eventname: req.body.eventname }, function(err, existingEvent) {
  33. if (existingEvent) {
  34. req.flash('errors', { msg: 'Event with that name already exists.' });
  35. }
  36. event.save(function(err) {
  37. if (err) {
  38. return next(err);
  39. }
  40. req.flash('success', { msg: 'Success!' });
  41. res.redirect(req.session.returnTo || '/');
  42. });
  43. });
  44. };