<commit_before># app/controllers/sessions_controller.rb
class SessionsController < ApplicationController
  skip_before_action :require_login, only: [:new, :create, :failure]

  def new
    @link = Rails.env.production? ? '/auth/google_oauth2' : '/auth/developer'
  end

  def create
    start_page = '/problem_submissions'
    failure_page = '/auth/failure'

    unless session[:user_id].nil?
      redirect_to start_page
      return
    end

    auth = request.env['omniauth.auth']
    provider = auth['provider']

    logger.info "Trying to log in with the following information #{auth}".green

    if auth.nil? || provider.nil?
      redirect_to failure_page
      return
    end

    if provider.eql?('google_oauth2')
      logger.info "Using google OAuth2".green

      credentials = auth['credentials']
      logger.info "Tokens are #{credentials}".green

      @info = credentials['extra']['info']
      logger.info "User info is are #{@info}".green

      # TODO: Link the token to the user name
      Token.create(
        access_token: credentials['token'],
        refresh_token: credentials['refresh_token'],
        expires_at: Time.at(credentials['expires_at']).to_datetime)
    elsif provider.eql?('developer')
      logger.info "Using google oauth".green

      @info = auth['info']
    else
      redirect_to failure_page
      return
    end

    user = User.find_by_email(@info['email'])<commit_msg>Remove extra<commit_after># app/controllers/sessions_controller.rb
class SessionsController < ApplicationController
  skip_before_action :require_login, only: [:new, :create, :failure]

  def new
    @link = Rails.env.production? ? '/auth/google_oauth2' : '/auth/developer'
  end

  def create
    start_page = '/problem_submissions'
    failure_page = '/auth/failure'

    unless session[:user_id].nil?
      redirect_to start_page
      return
    end

    auth = request.env['omniauth.auth']
    provider = auth['provider']

    logger.info "Trying to log in with the following information #{auth}".green

    if auth.nil? || provider.nil?
      redirect_to failure_page
      return
    end

    if provider.eql?('google_oauth2')
      logger.info "Using google OAuth2".green

      credentials = auth['credentials']
      logger.info "Tokens are #{credentials}".green

      @info = credentials['info']
      logger.info "User info is are #{@info}".green

      # TODO: Link the token to the user name
      Token.create(
        access_token: credentials['token'],
        refresh_token: credentials['refresh_token'],
        expires_at: Time.at(credentials['expires_at']).to_datetime)
    elsif provider.eql?('developer')
      logger.info "Using google oauth".green

      @info = auth['info']
    else
      redirect_to failure_page
      return
    end

    user = User.find_by_email(@info['email'])
{'fraction_non_alphanumeric': 0.11386138613861387, 'fraction_numerical': 0.0021216407355021216, 'mean_word_length': 3.1359649122807016, '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': '656597', 'n_tokens_mistral': 862, 'n_tokens_neox': 827, 'n_words': 202}