Browse Source

Commit 7-3: Denied access to new posts page when not logged in.

Frederic G. MARAND 9 years ago
parent
commit
3634d57c1d
2 changed files with 20 additions and 0 deletions
  1. 6 0
      client/templates/includes/access_denied.html
  2. 14 0
      lib/router.js

+ 6 - 0
client/templates/includes/access_denied.html

@@ -0,0 +1,6 @@
+<template name="accessDenied">
+  <div class="access-denied page jumbotron">
+    <h2>Access denied</h2>
+    <p>You can't get here! Please log in.</p>
+  </div>
+</template>

+ 14 - 0
lib/router.js

@@ -38,3 +38,17 @@ Router.route('/submit', {
 Router.onBeforeAction('dataNotFound', {
   only: 'postPage'
 });
+
+var requireLogin = function () {
+  if (!Meteor.user()) {
+    this.render('accessDenied');
+  }
+  else {
+    this.next();
+  }
+};
+
+// Appliquer le contrôle d'accès à la route postSubmit.
+Router.onBeforeAction(requireLogin, {
+  only: 'postSubmit'
+});