watch.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. var Watch = require('../models/Watch');
  2. var mongoose = require('mongoose');
  3. const bodyParser = require('body-parser');
  4. // Get Movie or Series
  5. exports.watchGet = function(req, res){
  6. Watch.findOne({ 'permalink': req.params.permalink }, function(err, w){
  7. if (!w) {
  8. return res.redirect('/404');
  9. }
  10. else{
  11. res.render('watch', {
  12. title: w.title,
  13. layout: w.layout,
  14. subtitle: w.subtitle,
  15. sinopse: w.sinopse,
  16. year: w.year,
  17. imgbg: w.imgbg,
  18. video: w.video,
  19. thumb480: w.thumb480,
  20. thumb130: w.thumb130,
  21. runtime: w.runtime,
  22. eps: w.eps
  23. });
  24. }
  25. });
  26. };
  27. // GET New Production
  28. exports.newWatchGet = function(req, res) {
  29. if (!req.user) {
  30. return res.redirect('/login');
  31. }
  32. res.render('novo', {
  33. title: 'Criar Nova Produção'
  34. });
  35. };
  36. // POST New Production
  37. exports.newWatchPost = function(req, res, next) {
  38. var body = req.body;
  39. // para retornar depois do erro
  40. var form = {
  41. };
  42. var errors = req.validationErrors();
  43. if (errors) {
  44. req.flash('error', errors);
  45. return res.render('novo', {form: form});
  46. }
  47. Watch.findOne({ permalink: req.body.permalink }, function(err, watch) {
  48. if (watch) {
  49. req.flash('error', { msg: 'O permalink inserido já existe. Tente outro.' });
  50. return res.redirect('/novo');
  51. }
  52. // Para salvar no BD
  53. watch = new Watch({
  54. criador: req.user.id,
  55. permalink: req.body.permalink,
  56. layout: 'filme',
  57. featured : false,
  58. title: req.body.title,
  59. subtitle: req.body.subtitle,
  60. sinopse: req.body.sinopse,
  61. year: req.body.year,
  62. classind: req.body.classind,
  63. duration: req.body.duration,
  64. video: req.body.video,
  65. thumb480: req.body.thumb480,
  66. imgbg: req.body.imgbg,
  67. tags: req.body.tags
  68. });
  69. watch.save(function(err) {
  70. //req.logIn(campanha, function(err) {
  71. req.flash('success', { msg: 'Muito obrigado por sua colaboração. Em breve a produção estará no ar. <3' });
  72. res.redirect('/');
  73. //});
  74. });
  75. });
  76. };
  77. // GET Tags
  78. exports.tagsGet = function(req, res){
  79. Watch.find({ 'tags': req.params.tags }, null, {sort: '-year'}, function(err, w){
  80. if (!w) {
  81. return res.redirect('/404');
  82. }
  83. else{
  84. res.render('home', {
  85. title: 'Tag',
  86. tag: req.params.tags,
  87. watch: w
  88. });
  89. }
  90. });
  91. };