text: var express                 = require("express"),
      router                  = express.Router(),
      User                    = require("../models/user"),
      middleware              = require("../middleware");
  
  // SHOW(GET): DASHBOARD/REFERRERS
  router.get('/referrers/:id/dashboard', middleware.isUserLoggedIn, middleware.isReferrerAuthorized, function (req, res) {
      User.findOne({ typeOfUser: "referrer", _id: req.params.id }, function(err, user) {
          if(!err) {
              if(user) {
                  return res.render("referrers/dashboard");
              }
              req.flash("error", "Please login or create an account.");
              res.redirect("/login");
              return;
          }
          req.flash("error", "Oops! An error occurred.");
          res.redirect("back");
      });
  });
  
  // SHOW(GET): CONTACT TEMPLATE/REFERRERS
  router.get('/referrers/:id/contact', middleware.isUserLoggedIn, middleware.isReferrerAuthorized, function (req, res) {
      User.findOne({ typeOfUser: "referrer", _id: req.params.id }, function(err, user) {
          if(!err) {
              if(user) {
                  return res.render("referrers/contact");
              }
              req.flash("error", "Please login or create an account.");
              res.redirect("/login");
              return;
          }
          req.flash("error", "Oops! An error occurred.");
          res.redirect("back");
      });
  });
  
  // SHOW(GET): NOTIFICATIONS/REFERRERS
  router.get("/referrers/:id/notifications", middleware.isUserLoggedIn, middleware.isReferrerAuthorized, function(req, res) {
      User.findOne({ typeOfUser: "referrer", _id: req.params.id }, function(err, user) {
          if(!err) {
              if(user) {
                  return res.render("referrers/notifications");
              }
              req.flash("error", "Please login or create an account.");
              res.redirect("/login");
              return;
          }
          req.flash("error", "Oops! An error occurred.");
          res.redirect("back");
      });
  });
  
  // SHOW(GET): OPEN NOTIFICATION/REFERRERS
  router.get("/referrers/:id/notifications/:id1", middleware.isUserLoggedIn, middleware.isReferrerAuthorized, function(req, res) {
      User.findOne({ typeOfUser: "referrer", _id: req.params.id }, function(err, user) {
          if(!err) {
              if(user) {
                  var notification = user.referrerDetails.notifications.find(function(el) {
                      el._id = req.params.id2
                  });
                  return res.render("referrers/showNotification");
              }
              req.flash("error", "Please login or create an account.");
              res.redirect("/login");
              return;
          }
          req.flash("error", "Oops! An error occurred.");
          res.redirect("back");
      });
  });
  
  module.exports = router;