application_controller.rb 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. class ApplicationController < ActionController::Base
  2. protect_from_forgery
  3. before_action :authenticate_user!
  4. before_action :configure_permitted_parameters, if: :devise_controller?
  5. helper :all
  6. def redirect_back(fallback_path, *args)
  7. redirect_to :back, *args
  8. rescue ActionController::RedirectBackError
  9. redirect_to fallback_path, *args
  10. end
  11. protected
  12. def configure_permitted_parameters
  13. devise_parameter_sanitizer.for(:sign_up) { |u| u.permit(:username, :email, :password, :password_confirmation, :remember_me, :invitation_code) }
  14. devise_parameter_sanitizer.for(:sign_in) { |u| u.permit(:login, :username, :email, :password, :remember_me) }
  15. devise_parameter_sanitizer.for(:account_update) { |u| u.permit(:username, :email, :password, :password_confirmation, :current_password) }
  16. end
  17. def authenticate_admin!
  18. redirect_to(root_path, alert: 'Admin access required to view that page.') unless current_user && current_user.admin?
  19. end
  20. def upgrade_warning
  21. return unless current_user
  22. twitter_oauth_check
  23. basecamp_auth_check
  24. end
  25. private
  26. def twitter_oauth_check
  27. unless Devise.omniauth_providers.include?(:twitter)
  28. if @twitter_agent = current_user.agents.where("type like 'Agents::Twitter%'").first
  29. @twitter_oauth_key = @twitter_agent.options['consumer_key'].presence || @twitter_agent.credential('twitter_consumer_key')
  30. @twitter_oauth_secret = @twitter_agent.options['consumer_secret'].presence || @twitter_agent.credential('twitter_consumer_secret')
  31. end
  32. end
  33. end
  34. def basecamp_auth_check
  35. unless Devise.omniauth_providers.include?(:'37signals')
  36. @basecamp_agent = current_user.agents.where(type: 'Agents::BasecampAgent').first
  37. end
  38. end
  39. end