/app/controllers/application_controller.rb
Ruby | 49 lines | 41 code | 8 blank | 0 comment | 3 complexity | 7f2699e801231ea0fd63fdada8329085 MD5 | raw file
- class ApplicationController < ActionController::Base
- protect_from_forgery
- before_filter :mailer_set_url_options
- before_filter :set_footer_html_url
-
- unless Rails.application.config.consider_all_requests_local
- rescue_from Exceptions::InvalidAction do
- render :file => "public/400.html", :status => :badrequest, :layout => nil
- end
- end
- def mailer_set_url_options
- ActionMailer::Base.default_url_options[:host] = request.host_with_port
- end
- def set_footer_html_url
- @footer_html_url = "http://bitbucket.org/ataraciuk/instedd-tools-footer/raw/tip/footer.js"
- end
-
- def check_login
- if current_user.nil?
- session[:return_to] = request.fullpath
- flash[:alert] = 'You need to sign in to see this page.'
- redirect_to new_user_session_path
- return false
- else
- true
- end
- end
-
- def check_permission(task_hub)
- return false unless check_login
-
- if !current_user.authorized_to(task_hub)
- session[:return_to] = request.fullpath
- flash[:alert] = 'You don\' t have permission to see this page. Ask the hub admin for it.'
- redirect_to request_permission_task_hub_path(task_hub)
- return false
- else
- true
- end
- end
-
- private
-
- def after_sign_in_path_for(resource_or_scope)
- (session[:return_to] || root_url).to_s
- end
- end