routes.js 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  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. document.title = 'Musare';
  13. next();
  14. }
  15. });
  16. } else {
  17. this.next();
  18. }
  19. });
  20. Router.route("/", {
  21. template: "home"
  22. });
  23. Router.route("/login", {
  24. action: function() {
  25. var user = Meteor.user();
  26. if (user === undefined || user === null) {
  27. this.render("login");
  28. } else {
  29. this.redirect("/");
  30. }
  31. }
  32. });
  33. Router.route("/register", {
  34. action: function() {
  35. var user = Meteor.user();
  36. if (user === undefined || user === null) {
  37. this.render("register");
  38. } else {
  39. this.redirect("/");
  40. }
  41. }
  42. });
  43. Router.route("/settings", {
  44. action: function() {
  45. if (!Meteor.userId()) {
  46. this.redirect("/");
  47. } else {
  48. this.render("settings");
  49. }
  50. }
  51. });
  52. Router.route("/add", {
  53. template: "addSong"
  54. });
  55. Router.route("/terms", {
  56. template: "terms"
  57. });
  58. Router.route("/contact", {
  59. template: "contact"
  60. });
  61. Router.route("/faq", {
  62. template: "faq"
  63. });
  64. Router.route("/privacy", {
  65. template: "privacy"
  66. });
  67. Router.route("/feedback", {
  68. template: "feedback"
  69. })
  70. Router.route("/team", {
  71. template: "team"
  72. })
  73. Router.route("/news", {
  74. template: "news"
  75. })
  76. Router.route("/welcome", {
  77. template: "landing"
  78. })
  79. Router.route("/project", {
  80. template: "project"
  81. })
  82. Router.route("/admin", {
  83. waitOn: function() {
  84. return [Meteor.subscribe("isModerator", Meteor.userId()), Meteor.subscribe("isAdmin", Meteor.userId())];
  85. },
  86. action: function() {
  87. var user = Meteor.users.findOne({});
  88. if (user !== undefined && user.profile !== undefined && (user.profile.rank === "admin" || user.profile.rank === "moderator")) {
  89. this.render("admin");
  90. } else {
  91. this.redirect("/");
  92. }
  93. }
  94. });
  95. Router.route("/admin/songs", {
  96. waitOn: function() {
  97. return [Meteor.subscribe("isModerator", Meteor.userId()), Meteor.subscribe("isAdmin", Meteor.userId())];
  98. },
  99. action: function() {
  100. var user = Meteor.users.findOne({});
  101. if (user !== undefined && user.profile !== undefined && (user.profile.rank === "admin" || user.profile.rank === "moderator")) {
  102. this.render("manageSongs");
  103. } else {
  104. this.redirect("/");
  105. }
  106. }
  107. });
  108. Router.route("/admin/queues", {
  109. waitOn: function() {
  110. return [Meteor.subscribe("isModerator", Meteor.userId()), Meteor.subscribe("isAdmin", Meteor.userId())];
  111. },
  112. action: function() {
  113. var user = Meteor.users.findOne({});
  114. if (user !== undefined && user.profile !== undefined && (user.profile.rank === "admin" || user.profile.rank === "moderator")) {
  115. this.render("queues");
  116. } else {
  117. this.redirect("/");
  118. }
  119. }
  120. });
  121. Router.route("/admin/alerts", {
  122. waitOn: function() {
  123. return [Meteor.subscribe("isModerator", Meteor.userId()), Meteor.subscribe("isAdmin", Meteor.userId())];
  124. },
  125. action: function() {
  126. var user = Meteor.users.findOne({});
  127. if (user !== undefined && user.profile !== undefined && (user.profile.rank === "admin" || user.profile.rank === "moderator")) {
  128. this.render("alertsDashboard");
  129. } else {
  130. this.redirect("/");
  131. }
  132. }
  133. });
  134. Router.route("/u/:user", function() {
  135. this.render("profile");
  136. });
  137. Router.route("/:type", {
  138. waitOn: function() {
  139. return [Meteor.subscribe("isModerator", Meteor.userId()), Meteor.subscribe("isAdmin", Meteor.userId()), Meteor.subscribe("rooms")];
  140. },
  141. action: function() {
  142. var user = Meteor.users.findOne({});
  143. var room = Rooms.findOne({type: this.params.type});
  144. if ((room.private === true && user !== undefined && user.profile !== undefined && (user.profile.rank === "admin" || user.profile.rank === "moderator")) || room.private === false) {
  145. this.render("room");
  146. } else {
  147. this.redirect("/");
  148. }
  149. }
  150. });
  151. Router.route("/:type/manage", {
  152. waitOn: function() {
  153. return [Meteor.subscribe("isModerator", Meteor.userId()), Meteor.subscribe("isAdmin", Meteor.userId())];
  154. },
  155. action: function() {
  156. var user = Meteor.users.findOne({});
  157. var room = Rooms.findOne({type: this.params.type});
  158. if (room !== undefined && user !== undefined && user.profile !== undefined && (user.profile.rank === "admin" || user.profile.rank === "moderator")) {
  159. this.render("manageStation");
  160. } else {
  161. this.redirect("/");
  162. }
  163. }
  164. });