routes.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. Router.configure({
  2. loadingTemplate: 'loading'
  3. });
  4. Router.onBeforeAction(function() {
  5. var self = this;
  6. var next = self.next;
  7. if (Meteor.userId()) {
  8. Meteor.call("isBanned", function(err, res) {
  9. if (res) {
  10. self.render('banned');
  11. } else {
  12. next();
  13. }
  14. });
  15. } else {
  16. next();
  17. }
  18. });
  19. Router.route("/", {
  20. template: "home"
  21. });
  22. Router.route("/login", {
  23. action: function() {
  24. var user = Meteor.user();
  25. if (user === undefined || user === null) {
  26. this.render("login");
  27. } else {
  28. this.redirect("/");
  29. }
  30. }
  31. });
  32. Router.route("/signup", {
  33. action: function() {
  34. var user = Meteor.user();
  35. if (user === undefined || user === null) {
  36. this.render("register");
  37. } else {
  38. this.redirect("/");
  39. }
  40. }
  41. });
  42. Router.route("/settings", {
  43. action: function() {
  44. if (!Meteor.userId()) {
  45. this.redirect("/");
  46. } else {
  47. this.render("settings");
  48. }
  49. }
  50. });
  51. Router.route("/terms", {
  52. template: "terms"
  53. });
  54. Router.route("/contact", {
  55. template: "contact"
  56. });
  57. Router.route("/faq", {
  58. template: "faq"
  59. });
  60. Router.route("/privacy", {
  61. template: "privacy"
  62. });
  63. Router.route("/about", {
  64. template: "about"
  65. });
  66. Router.route("/admin", {
  67. waitOn: function() {
  68. return [Meteor.subscribe("isModerator", Meteor.userId()), Meteor.subscribe("isAdmin", Meteor.userId())];
  69. },
  70. action: function() {
  71. var user = Meteor.users.findOne({});
  72. if (user !== undefined && user.profile !== undefined && (user.profile.rank === "admin" || user.profile.rank === "moderator")) {
  73. this.render("admin");
  74. } else {
  75. this.redirect("/");
  76. }
  77. }
  78. });
  79. Router.route("/admin/stations", {
  80. waitOn: function() {
  81. return [Meteor.subscribe("isModerator", Meteor.userId()), Meteor.subscribe("isAdmin", Meteor.userId())];
  82. },
  83. action: function() {
  84. var user = Meteor.users.findOne({});
  85. if (user !== undefined && user.profile !== undefined && (user.profile.rank === "admin" || user.profile.rank === "moderator")) {
  86. this.render("stations");
  87. } else {
  88. this.redirect("/");
  89. }
  90. }
  91. });
  92. Router.route("/admin/queues", {
  93. waitOn: function() {
  94. return [Meteor.subscribe("isModerator", Meteor.userId()), Meteor.subscribe("isAdmin", Meteor.userId())];
  95. },
  96. action: function() {
  97. var user = Meteor.users.findOne({});
  98. if (user !== undefined && user.profile !== undefined && (user.profile.rank === "admin" || user.profile.rank === "moderator")) {
  99. this.render("queues");
  100. } else {
  101. this.redirect("/");
  102. }
  103. }
  104. });
  105. Router.route("/admin/alerts", {
  106. waitOn: function() {
  107. return [Meteor.subscribe("isModerator", Meteor.userId()), Meteor.subscribe("isAdmin", Meteor.userId())];
  108. },
  109. action: function() {
  110. var user = Meteor.users.findOne({});
  111. if (user !== undefined && user.profile !== undefined && (user.profile.rank === "admin" || user.profile.rank === "moderator")) {
  112. this.render("alertsDashboard");
  113. } else {
  114. this.redirect("/");
  115. }
  116. }
  117. });
  118. Router.route("/:type", {
  119. waitOn: function() {
  120. return [Meteor.subscribe("isModerator", Meteor.userId()), Meteor.subscribe("isAdmin", Meteor.userId())];
  121. },
  122. action: function() {
  123. var user = Meteor.users.findOne({});
  124. if (user !== undefined && user.profile !== undefined && (user.profile.rank === "admin" || user.profile.rank === "moderator")) {
  125. this.render("room");
  126. } else {
  127. this.redirect("/");
  128. }
  129. }
  130. });
  131. Router.route("/u/:user", {
  132. template: "profile"
  133. });