Files
osem/app/controllers/application_controller.rb
2013-08-25 13:40:44 +03:00

62 lines
1.4 KiB
Ruby

class ApplicationController < ActionController::Base
include ApplicationHelper
protect_from_forgery
before_filter :get_conferences
before_filter :store_location
def store_location
session[:return_to] = request.fullpath if request.get? and controller_name != "user_sessions" and controller_name != "sessions"
end
def after_sign_in_path_for(resource)
session[:return_to]
end
def get_conferences
@conferences =Conference.all
end
def verify_user
:authenticate_user!
if (current_user.nil?)
redirect_to new_user_session_path
return false
end
@conference = Conference.find_all_by_short_title(params[:conference_id]).first
true
end
def organizer_or_admin?
has_role?(current_user, 'admin') || has_role?(current_user, 'organizer')
end
def verify_organizer
if !verify_user
return
end
## Todo simplify this
redirect_to root_path unless has_role?(current_user, 'admin') || has_role?(current_user, 'organizer')
end
def verify_admin
if !verify_user
return
end
redirect_to root_path unless has_role?(current_user, 'admin')
end
def current_ability
@current_ability ||= AdminAbility.new(current_user)
end
rescue_from CanCan::AccessDenied do |exception|
Rails.logger.debug("Access denied!")
redirect_to root_path, :alert => exception.message
end
helper_method :organizer_or_admin?
end