Advertisement
Guest User

Untitled

a guest
Nov 27th, 2015
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.19 KB | None | 0 0
  1. showVideo: function(req, res) {
  2.  
  3. // Find the video to play
  4. Video.findOne({
  5. id: +req.param('id')
  6. }).exec(function (err, foundVideo){
  7.  
  8. // If not logged in
  9. if (!req.session.userId) {
  10. return res.view('show-video', {
  11. me: null,
  12. video: foundVideo,
  13. tutorialId: req.param('tutorialId')
  14. });
  15. }
  16.  
  17. // If logged in...
  18. User.findOne({
  19. id: +req.session.userId
  20. }).exec(function (err, foundUser) {
  21. if (err) {
  22. return res.negotiate(err);
  23. }
  24.  
  25. if (!foundUser) {
  26. sails.log.verbose('Session refers to a user who no longer exists- did you delete a user, then try to refresh the page with an open tab logged-in as that user?');
  27. return res.view('show-video', {
  28. me: null,
  29. video: foundVideo,
  30. tutorialId: req.param('tutorialId')
  31. });
  32. }
  33.  
  34. return res.view('show-video', {
  35. me: {
  36. username: foundUser.username,
  37. gravatarURL: foundUser.gravatarURL,
  38. admin: foundUser.admin
  39. },
  40. video: foundVideo,
  41. tutorialId: req.param('tutorialId')
  42. });
  43. });
  44. });
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement