<commit_before>class ExercismApp < Sinatra::Base

  get '/logout' do
    logout
    redirect '/'
  end

  if ENV['RACK_ENV'] == 'development'
    get '/backdoor' do
      session[:github_id] = params[:id]

      if !current_user.admin? && current_user.submissions.count == 0
        redirect "/account"
      else
        redirect "/"
      end
    end
  end

  get '/login' do
    redirect "https://github.com/login/oauth/authorize?client_id=#{ENV.fetch('EXERCISM_GITHUB_CLIENT_ID')}"
  end

  # Callback from github. This will include a temp code from Github that
  # we use to authenticate other requests.
  # If we get a code, the user has said okay.
  get '/github/callback' do
    unless params[:code]
      halt 400, "Must provide parameter 'code'"
    end
    user = Authentication.perform(params[:code])
    login(user)

    if current_user.guest?
      flash[:error] = "We're having trouble with logins right now. Please come back later"
      redirect '/'
    elsif !current_user.admin? && current_user.submissions.count == 0
      redirect "/account"
    else
      redirect "/"
    end
  end

end
<commit_msg>Don't blow up on login issues<commit_after>class ExercismApp < Sinatra::Base

  get '/logout' do
    logout
    redirect '/'
  end

  if ENV['RACK_ENV'] == 'development'
    get '/backdoor' do
      session[:github_id] = params[:id]

      if !current_user.admin? && current_user.submissions.count == 0
        redirect "/account"
      else
        redirect "/"
      end
    end
  end

  get '/login' do
    redirect "https://github.com/login/oauth/authorize?client_id=#{ENV.fetch('EXERCISM_GITHUB_CLIENT_ID')}"
  end

  # Callback from github. This will include a temp code from Github that
  # we use to authenticate other requests.
  # If we get a code, the user has said okay.
  get '/github/callback' do
    unless params[:code]
      halt 400, "Must provide parameter 'code'"
    end
    begin
      user = Authentication.perform(params[:code])
      login(user)
    rescue => e
      flash[:error] = "We're having trouble with logins right now. Please come back later"
      redirect '/'
    end

    if current_user.guest?
      flash[:error] = "We're having trouble with logins right now. Please come back later"
      redirect '/'
    elsif !current_user.admin? && current_user.submissions.count == 0
      redirect "/account"
    else
      redirect "/"
    end
  end

end

{'fraction_non_alphanumeric': 0.1079734219269103, 'fraction_numerical': 0.004152823920265781, 'mean_word_length': 2.6722560975609757, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 4, 'https://': 2, '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': '179071', 'n_tokens_mistral': 778, 'n_tokens_neox': 742, 'n_words': 228}