<commit_before>#!/usr/bin/env ruby
require "cgi"
require "uri"
require "pathname"

require "webrick"
include WEBrick

# load the openid library, first trying rubygems
begin
  require "openid"
  require "openid/store/filestore"
  require "openid/extensions/sreg"
rescue LoadError
  require "rubygems"
  require_gem "ruby-openid"
end

################ start config ##########################
# use your desired store implementation here.
store_dir = Pathname.new(Dir.tmpdir).join("openid-store")
store = OpenID::FilesystemStore.new(store_dir)

$host = "localhost"
$port = 2000
################ end config ############################

if $port.nil?
  $base_url = "http://#{$host}/"
else
  $base_url = "http://#{$host}:#{$port}/"
end

# NOTE: Please note that a Hash is not a valid session storage type, it is just
# used here to get something that works.  In a production environment this
# should be an object representing the CURRENT USER's session, NOT a global
# hash.  Every user visiting this running consumer.rb will write into this
# same hash.
$session = {}

$trust_root = $base_url
$consumer = OpenID::Consumer.new($session, store)

server = HTTPServer.new(:Port=>$port)
class SimpleServlet < HTTPServlet::AbstractServlet

  def do_GET(req, res)
    @req = req
    @res = res

    begin
      case req.path
      when "", "/", "/start"
        render
      when "/begin"
        do_begin
      when "/complete"
        do_complete
      when '/policy'
        do_policy
      else
        redirect(build_url)
      end
    ensure
      @req = nil
      @res = nil
    end
  end

  def do_POST(req, res)
    do_GET(req, res)
  end

  def policy_url
    build_url('policy')
  end

  def return_to
    build_url('complete')
  end

  def do_begin
    # First make sure the user entered something
    openid_url = @req.query.fetch("openid_url", "")

    if openid_url.empty?
      render("Enter an OpenID identifier to verify",
             css_class="error", form_contents=openid_url)
      return HTTPStatus::Success
    end

    # Then ask the openid library to begin the authorization
    begin
      checkid_request = $consumer.begin(openid_url)
    rescue OpenID::Yadis::DiscoveryFailure => why
      # If the URL was unusable (either because of network conditions,
      # a server error, or that the response returned was not an
      # OpenID identity page), the library will raise
      # OpenID::Yadis::DiscoveryFailure Let the user know that the URL
      # is unusable.
      render("Error performing discovery: #{why.message}", "error", openid_url)
      return HTTPStatus::Success
    end

    # check to see if we want to make an SREG request. Generally this will
    # not take the form of a checkbox, but will be part of your site policy.
    # For example, you may perform an sreg request if the user appears
    # to be new to the site.  The checkbox is here for convenience of<commit_msg>[project @ Buh. Actually make the code handle the form field being called openid_identifier]<commit_after>#!/usr/bin/env ruby
require "cgi"
require "uri"
require "pathname"

require "webrick"
include WEBrick

# load the openid library, first trying rubygems
begin
  require "openid"
  require "openid/store/filestore"
  require "openid/extensions/sreg"
rescue LoadError
  require "rubygems"
  require_gem "ruby-openid"
end

################ start config ##########################
# use your desired store implementation here.
store_dir = Pathname.new(Dir.tmpdir).join("openid-store")
store = OpenID::FilesystemStore.new(store_dir)

$host = "localhost"
$port = 2000
################ end config ############################

if $port.nil?
  $base_url = "http://#{$host}/"
else
  $base_url = "http://#{$host}:#{$port}/"
end

# NOTE: Please note that a Hash is not a valid session storage type, it is just
# used here to get something that works.  In a production environment this
# should be an object representing the CURRENT USER's session, NOT a global
# hash.  Every user visiting this running consumer.rb will write into this
# same hash.
$session = {}

$trust_root = $base_url
$consumer = OpenID::Consumer.new($session, store)

server = HTTPServer.new(:Port=>$port)
class SimpleServlet < HTTPServlet::AbstractServlet

  def do_GET(req, res)
    @req = req
    @res = res

    begin
      case req.path
      when "", "/", "/start"
        render
      when "/begin"
        do_begin
      when "/complete"
        do_complete
      when '/policy'
        do_policy
      else
        redirect(build_url)
      end
    ensure
      @req = nil
      @res = nil
    end
  end

  def do_POST(req, res)
    do_GET(req, res)
  end

  def policy_url
    build_url('policy')
  end

  def return_to
    build_url('complete')
  end

  def do_begin
    # First make sure the user entered something
    openid_identifier = @req.query.fetch("openid_identifier", "")

    if openid_identifier.empty?
      render("Enter an OpenID identifier to verify",
             css_class="error", form_contents=openid_identifier)
      return HTTPStatus::Success
    end

    # Then ask the openid library to begin the authorization
    begin
      checkid_request = $consumer.begin(openid_identifier)
    rescue OpenID::Yadis::DiscoveryFailure => why
      # If the URL was unusable (either because of network conditions,
      # a server error, or that the response returned was not an
      # OpenID identity page), the library will raise
      # OpenID::Yadis::DiscoveryFailure Let the user know that the URL
      # is unusable.
      render("Error performing discovery: #{why.message}",
             "error", openid_identifier)
      return HTTPStatus::Success
    end

    # check to see if we want to make an SREG request. Generally this will
    # not take the form of a checkbox, but will be part of your site policy.
    # For example, you may perform an sreg request if the user appears
    # to be new to the site.  The checkbox is here for convenience of
{'fraction_non_alphanumeric': 0.1148036253776435, 'fraction_numerical': 0.001342732460557234, 'mean_word_length': 3.2142857142857144, 'pattern_counts': {'":': 0, '<': 5, '<?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': '4471059', 'n_tokens_mistral': 1780, 'n_tokens_neox': 1724, 'n_words': 629}