<commit_before>require 'digest/md5'
  
# This controller handles the login/logout function of the site.
class SessionsController < ApplicationController
    
  after_filter :update_last_user_activity
  
  layout 'main'
  
  #find out from the SARs shibboleth service what the magic
  #url is
  def pre_shibboleth_login
    url = URI.parse("http://academic.sar-data.ccsr.ac.uk/nesstar/?" + SHIB_LOGIN_URL + "/session/shibboleth")
    res = Net::HTTP.get url
    doc = Nokogiri::HTML(res)
    links = doc.css('a').map { |link| link['href'] }
    shib_links =  links.reject{|entry| entry.rindex('shibboleth') == nil}
    shib_link = shib_links[0]
    redirect_to shib_link
  end
  
  def shibboleth
    date = DateTime.now
    year = date.year
    month = date.month
    mday = date.mday
    check_date = year.to_s + '-' + sprintf("%02d", month) + '-' + sprintf("%02d",mday)
    ip = request.env["HTTP_X_FORWARDED_FOR"] || request.env["HTTP_FORWARDED_FOR"] || request.env["REMOTE_ADDR"]
    full_ip = IPAddress ip
    short_ip = full_ip[0].to_s + '.' + full_ip[1].to_s + '.' + full_ip[2].to_s
    user = params[:username]
    user.gsub!("+"," ")
    pre_hash =  check_date + SARS_SHARED_SECRET + short_ip + user
    digest = Digest::MD5.hexdigest(pre_hash)
    sars_checksum = params[:sars_checksum]
    calculated_hash = digest
    respond_to do |format|
      if params[:sars_checksum] == digest
        user=User.find_by_shibboleth_user_id(params[:username])
        if user && user.person
          self.current_user = user
          format.html {redirect_to person_url(current_user)}
        else<commit_msg>added a description for the shib login<commit_after>require 'digest/md5'
  
# This controller handles the login/logout function of the site.
class SessionsController < ApplicationController
    
  after_filter :update_last_user_activity
  
  layout 'main'
  
  #find out from the SARs shibboleth service what the magic
  #url is
  def pre_shibboleth_login
    url = URI.parse("http://academic.sar-data.ccsr.ac.uk/nesstar/?" + SHIB_LOGIN_URL + "/session/shibboleth")
    res = Net::HTTP.get url
    doc = Nokogiri::HTML(res)
    links = doc.css('a').map { |link| link['href'] }
    shib_links =  links.reject{|entry| entry.rindex('shibboleth') == nil}
    shib_link = shib_links[0]
    redirect_to shib_link
  end
  
  #the return action for the shibboleth login round trip
  #figure out what the user id is by parsing the response
  def shibboleth
    date = DateTime.now
    year = date.year
    month = date.month
    mday = date.mday
    check_date = year.to_s + '-' + sprintf("%02d", month) + '-' + sprintf("%02d",mday)
    ip = request.env["HTTP_X_FORWARDED_FOR"] || request.env["HTTP_FORWARDED_FOR"] || request.env["REMOTE_ADDR"]
    full_ip = IPAddress ip
    short_ip = full_ip[0].to_s + '.' + full_ip[1].to_s + '.' + full_ip[2].to_s
    user = params[:username]
    user.gsub!("+"," ")
    pre_hash =  check_date + SARS_SHARED_SECRET + short_ip + user
    digest = Digest::MD5.hexdigest(pre_hash)
    sars_checksum = params[:sars_checksum]
    calculated_hash = digest
    respond_to do |format|
      if params[:sars_checksum] == digest
        user=User.find_by_shibboleth_user_id(params[:username])
        if user && user.person
          self.current_user = user
          format.html {redirect_to person_url(current_user)}
        else
{'fraction_non_alphanumeric': 0.12202380952380952, 'fraction_numerical': 0.005952380952380952, 'mean_word_length': 3.3820078226857886, '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': '1198050', 'n_tokens_mistral': 1213, 'n_tokens_neox': 1195, 'n_words': 245}