routes.js 4.1 KB

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