routes.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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("/register", {
  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("/feedback", {
  67. template: "feedback"
  68. })
  69. Router.route("/team", {
  70. template: "team"
  71. })
  72. Router.route("/project", {
  73. template: "project"
  74. })
  75. Router.route("/admin", {
  76. waitOn: function() {
  77. return [Meteor.subscribe("isModerator", Meteor.userId()), Meteor.subscribe("isAdmin", Meteor.userId())];
  78. },
  79. action: function() {
  80. var user = Meteor.users.findOne({});
  81. if (user !== undefined && user.profile !== undefined && (user.profile.rank === "admin" || user.profile.rank === "moderator")) {
  82. this.render("admin");
  83. } else {
  84. this.redirect("/");
  85. }
  86. }
  87. });
  88. Router.route("/admin/stations", {
  89. waitOn: function() {
  90. return [Meteor.subscribe("isModerator", Meteor.userId()), Meteor.subscribe("isAdmin", Meteor.userId())];
  91. },
  92. action: function() {
  93. var user = Meteor.users.findOne({});
  94. if (user !== undefined && user.profile !== undefined && (user.profile.rank === "admin" || user.profile.rank === "moderator")) {
  95. this.render("stations");
  96. } else {
  97. this.redirect("/");
  98. }
  99. }
  100. });
  101. Router.route("/admin/queues", {
  102. waitOn: function() {
  103. return [Meteor.subscribe("isModerator", Meteor.userId()), Meteor.subscribe("isAdmin", Meteor.userId())];
  104. },
  105. action: function() {
  106. var user = Meteor.users.findOne({});
  107. if (user !== undefined && user.profile !== undefined && (user.profile.rank === "admin" || user.profile.rank === "moderator")) {
  108. this.render("queues");
  109. } else {
  110. this.redirect("/");
  111. }
  112. }
  113. });
  114. Router.route("/admin/alerts", {
  115. waitOn: function() {
  116. return [Meteor.subscribe("isModerator", Meteor.userId()), Meteor.subscribe("isAdmin", Meteor.userId())];
  117. },
  118. action: function() {
  119. var user = Meteor.users.findOne({});
  120. if (user !== undefined && user.profile !== undefined && (user.profile.rank === "admin" || user.profile.rank === "moderator")) {
  121. this.render("alertsDashboard");
  122. } else {
  123. this.redirect("/");
  124. }
  125. }
  126. });
  127. Router.route("/u/:user", function() {
  128. this.render("profile");
  129. });
  130. Router.route("/:type", {
  131. waitOn: function() {
  132. return [Meteor.subscribe("isModerator", Meteor.userId()), Meteor.subscribe("isAdmin", Meteor.userId()), Meteor.subscribe("rooms")];
  133. },
  134. action: function() {
  135. var user = Meteor.users.findOne({});
  136. var room = Rooms.findOne({type: this.params.type});
  137. if ((room.private === true && user !== undefined && user.profile !== undefined && (user.profile.rank === "admin" || user.profile.rank === "moderator")) || room.private === false) {
  138. this.render("room");
  139. } else {
  140. this.redirect("/");
  141. }
  142. }
  143. });