require 'csv'
class ApplicationController < ActionController::Base
  # Prevent CSRF attacks by raising an exception.
  # For APIs, you may want to use :null_session instead.
  protect_from_forgery with: :exception

  before_action :configure_permitted_parameters, if: :devise_controller?
  before_action :set_raven_context

  private
  def after_sign_in_path_for(resource)
    if resource.is_a?(User) && resource.is_enabled?
      if resource.client.present?
        "/customer"
      else
        "/admin"
      end
    else
      "/user_not_enabled"
    end
  end

  def configure_permitted_parameters
    devise_parameter_sanitizer.permit(:sign_up, keys: [:true_name, :username, :email])
  end

  def set_raven_context
    if Rails.env.production?
      Raven.user_context(id: current_user&.id) # or anything else in session
      Raven.extra_context(params: params.to_unsafe_h, url: request.url)
    end
  end

end
