<commit_before>class MicroAuthController < ApplicationController
  def request

  end

  def success

  end

  def token

  end
end<commit_msg>flesh out microauth methods<commit_after>class MicroAuthController < ApplicationController
  before_action :authenticate_user!, :except => [:token]

  def request
  end

  def authorize
    token = ApiToken.new(:user => current_user, :api_key => params[:api_key], :code => generate_code(7), :token => generate_code(64), :expiry => 10.minutes.from_now)
    if !token.save
      flash[:alert] = "Can't create a write token right now - ask an admin to look at the server logs."
    end
  end

  def reject
  end

  def token
    code = params[:code]
    api_key = params[:api_key]
    token = ApiToken.where(:code => code, :api_key => api_key)
    if token.any? && !token.first.expiry.past?
      render :json => { :token => token.first.token }
    else
      render :json => { :error_name => 'token not found', :error_code => 404, :error_message => 'There was no token found matching the key and code.' }
    end
  end

  private
    def generate_code(len)
      hash = Digest::SHA256.hexdigest("#{rand(0..9e9)}#{Time.now}")
      return hash[0..(len - 1)]
    end
end
{'fraction_non_alphanumeric': 0.12158808933002481, 'fraction_numerical': 0.013234077750206782, 'mean_word_length': 3.352517985611511, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 17, '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': '2875738', 'n_tokens_mistral': 406, 'n_tokens_neox': 381, 'n_words': 112}