<commit_before>class AuthToken < ActiveRecord::Base

  belongs_to :user

  # Auth token encryption settings
  attr_encrypted :auth_token,
    key: Doubtfire::Application.secrets.secret_key_attr,
    encode: true,
    attribute: 'authentication_token'

  def self.generate(user, remember, expiry_time = Time.zone.now + 2.hours)
    # Loop until new unique auth token is found
    token = loop do
      token = Devise.friendly_token
      break token unless AuthToken.find_by_auth_token(token)
    end

    # Create a new AuthToken with this value
    result = AuthToken.new(user_id: user.id)
    result.auth_token = token
    result.extend_token(remember, expiry_time, false)
    result.save!
    result
  end
<commit_msg>ENHANCE: Ensure that auth tokens are unique<commit_after>class AuthToken < ActiveRecord::Base

  belongs_to :user

  validates :authentication_token, presence: true, uniqueness: true

  # Auth token encryption settings
  attr_encrypted :auth_token,
    key: Doubtfire::Application.secrets.secret_key_attr,
    encode: true,
    attribute: 'authentication_token'

  def self.generate(user, remember, expiry_time = Time.zone.now + 2.hours)
    # Loop until new unique auth token is found
    token = loop do
      token = Devise.friendly_token
      break token unless AuthToken.find_by_auth_token(token)
    end

    # Create a new AuthToken with this value
    result = AuthToken.new(user_id: user.id)
    result.auth_token = token
    result.extend_token(remember, expiry_time, false)
    result.save!
    result
  end

{'fraction_non_alphanumeric': 0.07397793640493186, 'fraction_numerical': 0.0012978585334198572, 'mean_word_length': 3.701219512195122, 'pattern_counts': {'":': 0, '<': 5, '<?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': '737515', 'n_tokens_mistral': 485, 'n_tokens_neox': 463, 'n_words': 130}