From 5f80211580802e66329c4e6e824d22ecb9a6f3ca Mon Sep 17 00:00:00 2001 From: Ken Johnson Date: Thu, 16 May 2013 17:56:31 -0400 Subject: [PATCH] added an administrative method intended to be used as a before filter within the application controller as well as an is_admin? method --- app/controllers/application_controller.rb | 13 ++++++++++++- app/controllers/dashboard_controller.rb | 2 +- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index d998974..f831f46 100755 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -1,7 +1,7 @@ class ApplicationController < ActionController::Base before_filter :authenticated - helper_method :current_user + helper_method :current_user, :is_admin? # Our security guy keep talking about sea-surfing, cool story bro. # protect_from_forgery @@ -16,4 +16,15 @@ class ApplicationController < ActionController::Base redirect_to root_url and reset_session if not current_user end + def is_admin? + admin = current_user.admin if current_user + end + + def administrative + if not is_admin? + reset_session + redirect_to login_path + end + end + end diff --git a/app/controllers/dashboard_controller.rb b/app/controllers/dashboard_controller.rb index 8d5138f..854e375 100755 --- a/app/controllers/dashboard_controller.rb +++ b/app/controllers/dashboard_controller.rb @@ -1,5 +1,5 @@ class DashboardController < ApplicationController - + def home end