1
0

application_controller.rb 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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. protected
  7. def configure_permitted_parameters
  8. devise_parameter_sanitizer.for(:sign_up) { |u| u.permit(:username, :email, :password, :password_confirmation, :remember_me, :invitation_code) }
  9. devise_parameter_sanitizer.for(:sign_in) { |u| u.permit(:login, :username, :email, :password, :remember_me) }
  10. devise_parameter_sanitizer.for(:account_update) { |u| u.permit(:username, :email, :password, :password_confirmation, :current_password) }
  11. end
  12. def authenticate_admin!
  13. redirect_to(root_path, alert: 'Admin access required to view that page.') unless current_user && current_user.admin?
  14. end
  15. def upgrade_warning
  16. return unless current_user
  17. twitter_oauth_check
  18. basecamp_auth_check
  19. end
  20. private
  21. def twitter_oauth_check
  22. unless Devise.omniauth_providers.include?(:twitter)
  23. if @twitter_agent = current_user.agents.where("type like 'Agents::Twitter%'").first
  24. @twitter_oauth_key = @twitter_agent.options['consumer_key'].presence || @twitter_agent.credential('twitter_consumer_key')
  25. @twitter_oauth_secret = @twitter_agent.options['consumer_secret'].presence || @twitter_agent.credential('twitter_consumer_secret')
  26. end
  27. end
  28. end
  29. def basecamp_auth_check
  30. unless Devise.omniauth_providers.include?(:'37signals')
  31. @basecamp_agent = current_user.agents.where(type: 'Agents::BasecampAgent').first
  32. end
  33. end
  34. end