PageRenderTime 81ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 1ms

/app/controllers/application_controller.rb

https://bitbucket.org/instedd/taskmeup
Ruby | 49 lines | 41 code | 8 blank | 0 comment | 3 complexity | 7f2699e801231ea0fd63fdada8329085 MD5 | raw file
  1. class ApplicationController < ActionController::Base
  2. protect_from_forgery
  3. before_filter :mailer_set_url_options
  4. before_filter :set_footer_html_url
  5. unless Rails.application.config.consider_all_requests_local
  6. rescue_from Exceptions::InvalidAction do
  7. render :file => "public/400.html", :status => :badrequest, :layout => nil
  8. end
  9. end
  10. def mailer_set_url_options
  11. ActionMailer::Base.default_url_options[:host] = request.host_with_port
  12. end
  13. def set_footer_html_url
  14. @footer_html_url = "http://bitbucket.org/ataraciuk/instedd-tools-footer/raw/tip/footer.js"
  15. end
  16. def check_login
  17. if current_user.nil?
  18. session[:return_to] = request.fullpath
  19. flash[:alert] = 'You need to sign in to see this page.'
  20. redirect_to new_user_session_path
  21. return false
  22. else
  23. true
  24. end
  25. end
  26. def check_permission(task_hub)
  27. return false unless check_login
  28. if !current_user.authorized_to(task_hub)
  29. session[:return_to] = request.fullpath
  30. flash[:alert] = 'You don\' t have permission to see this page. Ask the hub admin for it.'
  31. redirect_to request_permission_task_hub_path(task_hub)
  32. return false
  33. else
  34. true
  35. end
  36. end
  37. private
  38. def after_sign_in_path_for(resource_or_scope)
  39. (session[:return_to] || root_url).to_s
  40. end
  41. end