application_controller.rb 1.5KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. class ApplicationController < ActionController::Base
  2. protect_from_forgery
  3. before_filter :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 upgrade_warning
  13. return unless current_user
  14. twitter_oauth_check
  15. basecamp_auth_check
  16. end
  17. private
  18. def twitter_oauth_check
  19. if ENV['TWITTER_OAUTH_KEY'].blank? || ENV['TWITTER_OAUTH_SECRET'].blank?
  20. if @twitter_agent = current_user.agents.where("type like 'Agents::Twitter%'").first
  21. @twitter_oauth_key = @twitter_agent.options['consumer_key'].presence || @twitter_agent.credential('twitter_consumer_key')
  22. @twitter_oauth_secret = @twitter_agent.options['consumer_secret'].presence || @twitter_agent.credential('twitter_consumer_secret')
  23. end
  24. end
  25. end
  26. def basecamp_auth_check
  27. if ENV['THIRTY_SEVEN_SIGNALS_OAUTH_KEY'].blank? || ENV['THIRTY_SEVEN_SIGNALS_OAUTH_SECRET'].blank?
  28. @basecamp_agent = current_user.agents.where(type: 'Agents::BasecampAgent').first
  29. end
  30. end
  31. end