<commit_before>class Auth0Controller < ApplicationController
  def callback
    if github_org_authorized?
      user = User.find_or_create_by(uid: request.env['omniauth.auth']['uid'])
      user.image = request.env['omniauth.auth']['info']['image']
      user.name  = request.env['omniauth.auth']['info']['name']
      user.email = request.env['omniauth.auth']['info']['email']
      user.save
      if github_mentor?
        user.roles << Role.find_by(name: "mentor")
      end

      session[:uid] = user.uid
      if user.is_mentor?
        redirect_to mentor_index_url
      else
        redirect_to root_url
      end
    else
      render plain: "You are not a member of the Devbootcamp Org on GitHub", status: 403
    end
  end

  def failure
    @error_msg = request.params['message']
    render plain: @error_msg.to_s
  end

  def github_org_authorized?
    conn = Faraday.new(:url => 'https://api.github.com') do |faraday|
      faraday.adapter  Faraday.default_adapter
    end

    token = "#{request.env['omniauth.auth']['extra']['raw_info']['identities'][0]['access_token']}"
    response = conn.get do |req|
      req.url "/orgs/devbootcamp/members/#{request.env['omniauth.auth']['info']['nickname']}"
      req.headers['Authorization'] = "token #{token}"
    end

    if response[:status] == "204 No Content"
      return true
    end
    false
  end

  def github_mentor?
    conn = Faraday.new(:url => 'https://api.github.com') do |faraday|
      faraday.adapter  Faraday.default_adapter
    end

    token = "#{request.env['omniauth.auth']['extra']['raw_info']['identities'][0]['access_token']}"
    response = conn.get do |req|
      req.url "/teams/1889928/memberships/#{request.env['omniauth.auth']['info']['nickname']}"
      req.headers['Authorization'] = "token #{token}"
    end

    response[:status] == "200 OK"
  end
end
<commit_msg>Remove dbc org check for dev branch<commit_after>class Auth0Controller < ApplicationController
  def callback
    if github_org_authorized?
      user = User.find_or_create_by(uid: request.env['omniauth.auth']['uid'])
      user.image = request.env['omniauth.auth']['info']['image']
      user.name  = request.env['omniauth.auth']['info']['name']
      user.email = request.env['omniauth.auth']['info']['email']
      user.save
      if github_mentor?
        user.roles << Role.find_by(name: "mentor")
      end

      session[:uid] = user.uid
      if user.is_mentor?
        redirect_to mentor_index_url
      else
        redirect_to root_url
      end
    else
      render plain: "You are not a member of the Devbootcamp Org on GitHub", status: 403
    end
  end

  def failure
    @error_msg = request.params['message']
    render plain: @error_msg.to_s
  end

  def github_org_authorized?
    conn = Faraday.new(:url => 'https://api.github.com') do |faraday|
      faraday.adapter  Faraday.default_adapter
    end

    token = "#{request.env['omniauth.auth']['extra']['raw_info']['identities'][0]['access_token']}"
    response = conn.get do |req|
      req.url "/orgs/devbootcamp/members/#{request.env['omniauth.auth']['info']['nickname']}"
      req.headers['Authorization'] = "token #{token}"
    end

    if response[:status] == "204 No Content"
      return true
    end
    # false
    # force return true to make dev-branch hosted at mentor-me-dev.herokuapp.com
    # accessible to any user with a GitHub profile
    true
  end

  def github_mentor?
    conn = Faraday.new(:url => 'https://api.github.com') do |faraday|
      faraday.adapter  Faraday.default_adapter
    end

    token = "#{request.env['omniauth.auth']['extra']['raw_info']['identities'][0]['access_token']}"
    response = conn.get do |req|
      req.url "/teams/1889928/memberships/#{request.env['omniauth.auth']['info']['nickname']}"
      req.headers['Authorization'] = "token #{token}"
    end

    response[:status] == "200 OK"
  end
end

{'fraction_non_alphanumeric': 0.1517880113197839, 'fraction_numerical': 0.009776177000257269, 'mean_word_length': 3.258488499452355, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 7, 'https://': 4, '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': '1062140', 'n_tokens_mistral': 1295, 'n_tokens_neox': 1216, 'n_words': 260}