<commit_before>class APIController < ApplicationController
  AUTHENTICATION_TOKEN_DESCRIPTION = <<-EOS
    L'authentification de l'API se fait via un header HTTP :

    ```
      Authorization: Bearer &lt;Token administrateur&gt;
    ```
  EOS

  # deny request with an empty token as we do not want it
  # to match the first admin with an empty token
  # it should not happen as an empty token is serialized by ''
  # and a administrateur without token has admin.api_token == nil
  before_action :ensure_token_is_present
  before_action :authenticate_user
  before_action :default_format_json

  def authenticate_user
    if !valid_token?
      request_http_token_authentication
    end
  end

  protected

  def valid_token?
    administrateur.present?
  end

  def administrateur
    @administrateur ||= (authenticate_with_bearer_token || authenticate_with_param_token)
  end

  def authenticate_with_bearer_token
    authenticate_with_http_token do |token, options|
      Administrateur.find_by(api_token: token)
    end
  end

  def authenticate_with_param_token
    Administrateur.find_by(api_token: params[:token])
  end

  def default_format_json
    request.format = "json" if !request.params[:format]
  end

  def ensure_token_is_present
    if params[:token].blank? && header_token.blank?
      render json: {}, status: 401
    end
  end

  def header_token
    received_token = nil
    authenticate_with_http_token do |token, _options|
      received_token = token
    end
    received_token
  end
end<commit_msg>ApiController: remove old authenticate logic<commit_after>class APIController < ApplicationController
  AUTHENTICATION_TOKEN_DESCRIPTION = <<-EOS
    L'authentification de l'API se fait via un header HTTP :

    ```
      Authorization: Bearer &lt;Token administrateur&gt;
    ```
  EOS

  # deny request with an empty token as we do not want it
  # to match the first admin with an empty token
  # it should not happen as an empty token is serialized by ''
  # and a administrateur without token has admin.api_token == nil
  before_action :ensure_token_is_present
  before_action :default_format_json

  protected

  def default_format_json
    request.format = "json" if !request.params[:format]
  end

  def ensure_token_is_present
    if params[:token].blank? && header_token.blank?
      render json: {}, status: 401
    end
  end

  def header_token
    received_token = nil
    authenticate_with_http_token do |token, _options|
      received_token = token
    end
    received_token
  end
end
{'fraction_non_alphanumeric': 0.0598019801980198, 'fraction_numerical': 0.002376237623762376, 'mean_word_length': 3.7392120075046904, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3931000', 'n_tokens_mistral': 770, 'n_tokens_neox': 753, 'n_words': 229}