2013-01-07 09:04:09 +01:00
|
|
|
class ApplicationController < ActionController::Base
|
|
|
|
|
include ApplicationHelper
|
|
|
|
|
protect_from_forgery
|
2013-06-27 16:58:20 +02:00
|
|
|
before_filter :get_conferences
|
2013-08-25 13:40:44 +03:00
|
|
|
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)
|
2014-05-23 17:05:19 +02:00
|
|
|
if organizer_or_admin? &&
|
|
|
|
|
(!session[:return_to] ||
|
|
|
|
|
session[:return_to] &&
|
|
|
|
|
session[:return_to] == root_path)
|
|
|
|
|
admin_conference_index_path
|
2014-03-24 12:45:04 +01:00
|
|
|
else
|
2014-05-23 17:05:19 +02:00
|
|
|
if session[:return_to] &&
|
|
|
|
|
!session[:return_to].start_with?(user_registration_path)
|
|
|
|
|
logger.debug "Returning to #{session[:return_to]}"
|
|
|
|
|
session[:return_to]
|
|
|
|
|
else
|
|
|
|
|
logger.debug "Not returning to #{session[:return_to]} because it would loop"
|
|
|
|
|
super
|
|
|
|
|
end
|
2014-03-24 12:45:04 +01:00
|
|
|
end
|
2013-08-25 13:40:44 +03:00
|
|
|
end
|
2013-06-27 16:58:20 +02:00
|
|
|
|
|
|
|
|
def get_conferences
|
|
|
|
|
@conferences =Conference.all
|
|
|
|
|
end
|
2013-01-07 09:04:09 +01:00
|
|
|
|
|
|
|
|
def verify_user
|
|
|
|
|
:authenticate_user!
|
|
|
|
|
|
|
|
|
|
if (current_user.nil?)
|
2013-01-20 13:06:01 +01:00
|
|
|
redirect_to new_user_session_path
|
2013-01-11 15:00:54 +01:00
|
|
|
return false
|
2013-01-07 09:04:09 +01:00
|
|
|
end
|
|
|
|
|
|
2014-04-27 16:27:29 +02:00
|
|
|
@conference = Conference.find_by(short_title: params[:conference_id])
|
2013-01-15 14:08:22 +01:00
|
|
|
true
|
2013-01-07 09:04:09 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def organizer_or_admin?
|
|
|
|
|
has_role?(current_user, 'admin') || has_role?(current_user, 'organizer')
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def verify_organizer
|
2013-01-11 15:00:54 +01:00
|
|
|
if !verify_user
|
|
|
|
|
return
|
|
|
|
|
end
|
2013-01-07 09:04:09 +01:00
|
|
|
|
|
|
|
|
## Todo simplify this
|
2013-01-20 13:06:01 +01:00
|
|
|
redirect_to root_path unless has_role?(current_user, 'admin') || has_role?(current_user, 'organizer')
|
2013-01-07 09:04:09 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def verify_admin
|
2013-01-11 15:00:54 +01:00
|
|
|
if !verify_user
|
|
|
|
|
return
|
|
|
|
|
end
|
2013-01-07 09:04:09 +01:00
|
|
|
|
2013-01-20 13:06:01 +01:00
|
|
|
redirect_to root_path unless has_role?(current_user, 'admin')
|
2013-01-07 09:04:09 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def current_ability
|
|
|
|
|
@current_ability ||= AdminAbility.new(current_user)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
rescue_from CanCan::AccessDenied do |exception|
|
|
|
|
|
Rails.logger.debug("Access denied!")
|
2013-01-20 13:06:01 +01:00
|
|
|
redirect_to root_path, :alert => exception.message
|
2013-01-07 09:04:09 +01:00
|
|
|
end
|
2013-07-28 13:03:22 +03:00
|
|
|
helper_method :organizer_or_admin?
|
2013-01-07 09:04:09 +01:00
|
|
|
end
|