<commit_before>module CurrentUser

  def self.lookup_from_env(env)
    request = Rack::Request.new(env)
    lookup_from_auth_token(request.cookies["_t"])
  end

  def self.lookup_from_auth_token(auth_token)
    if auth_token && auth_token.length == 32
      User.where(auth_token: auth_token).first 
    end
  end

  def log_on_user(user)
    session[:current_user_id] = user.id
    unless user.auth_token
      user.auth_token = SecureRandom.hex(16)
      user.save!
    end
    cookies.permanent[:_t] = { :value => user.auth_token, :httponly => true }
  end

  def current_user
    return @current_user if @current_user || @not_logged_in

    if session[:current_user_id].blank?
      # maybe we have a cookie? 
      @current_user = CurrentUser.lookup_from_auth_token(cookies["_t"])
      session[:current_user_id] = @current_user.id if @current_user
    else
      @current_user ||= User.where(id: session[:current_user_id]).first
    end
<commit_msg>cookie recovery cause we have been messing with it.<commit_after>module CurrentUser

  def self.lookup_from_env(env)
    request = Rack::Request.new(env)
    lookup_from_auth_token(request.cookies["_t"])
  end

  def self.lookup_from_auth_token(auth_token)
    if auth_token && auth_token.length == 32
      User.where(auth_token: auth_token).first 
    end
  end

  def log_on_user(user)
    session[:current_user_id] = user.id
    unless user.auth_token
      user.auth_token = SecureRandom.hex(16)
      user.save!
    end
    set_permanent_cookie!(user)
  end

  def set_permanent_cookie!(user)
    cookies.permanent["_t"] = { :value => user.auth_token, :httponly => true }
  end

  def current_user
    return @current_user if @current_user || @not_logged_in

    if session[:current_user_id].blank?
      # maybe we have a cookie? 
      @current_user = CurrentUser.lookup_from_auth_token(cookies["_t"])
      session[:current_user_id] = @current_user.id if @current_user
    else
      @current_user ||= User.where(id: session[:current_user_id]).first
      
      # cookie recovery from session, we have been messing with it, fix it up
      if @current_user && cookies["_t"] != @current_user.auth_token
        set_permanent_cookie!(@current_user)
      end

    end

{'fraction_non_alphanumeric': 0.10309278350515463, 'fraction_numerical': 0.003585835948005379, 'mean_word_length': 3.5737704918032787, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '5244211', 'n_tokens_mistral': 769, 'n_tokens_neox': 744, 'n_words': 149}