<commit_before>class PagesController < ApplicationController
  skip_before_filter :verify_authenticity_token

  AUTH_CTX = ADAL::AuthenticationContext.new(
    'login.windows.net', ENV['TENANT'])
  CLIENT_CRED = ADAL::ClientCredential.new(ENV['CLIENT_ID'], ENV['CLIENT_SECRET'])
  GRAPH_RESOURCE = 'https://graph.microsoft.com'
  
  def login
    redirect_to "/auth/azureactivedirectory"
  end
  
  def authd
    # Authentication redirects here
    code = params[:code]
    
    # Used in the template
    @name = auth_hash.info.name
    @email = auth_hash.info.email
    
    # Request an access token
    result = acquire_auth_token(code, ENV['REPLY_URL'])
    
    # Associate this token to our user's session
    session[:access_token] = result.access_token
    # name -> session
    session[:name] = @name
    # email -> session
    session[:email] = @email
    
    # Debug logging
    puts "Code: #{code}"
    puts "Name: #{@name}"
    puts "Email: #{@email}"
    puts "[authd] - Access token: #{session[:access_token]}"
  end
  
  def send_mail
    puts "[send_mail] - Access token: #{session[:access_token]}"
    
    # Used in the template
    @name = session[:name]
    @email = params[:specified_email]
    @recipient = params[:specified_email]
    
    # TODO send the email...
    # check the status code and if in the success range AKA (200-299) we're good
    # otherwise report an error...
    
    render "authd"
  end

  def auth_hash
    request.env['omniauth.auth']
  end
  
  def acquire_auth_token(auth_code, reply_url)
    AUTH_CTX.acquire_token_with_authorization_code(
                  auth_code,
                  reply_url,
                  CLIENT_CRED,
                  GRAPH_RESOURCE)
  end
  
  def disconnect
    reset_session
    #TODO: Use interpolate instead of +?
    redirect = "#{ENV['LOGOUT_ENDPOINT']}?post_logout_redirect_uri=http://localhost:9292"
    puts "REDIRECT: " + redirect
    redirect_to redirect<commit_msg>Added proper url encoding to post_logout_redirect_uri query string parameter and dynamically getting the root url<commit_after>class PagesController < ApplicationController
  skip_before_filter :verify_authenticity_token

  AUTH_CTX = ADAL::AuthenticationContext.new(
    'login.windows.net', ENV['TENANT'])
  CLIENT_CRED = ADAL::ClientCredential.new(ENV['CLIENT_ID'], ENV['CLIENT_SECRET'])
  GRAPH_RESOURCE = 'https://graph.microsoft.com'
  
  def login
    redirect_to "/auth/azureactivedirectory"
  end
  
  def authd
    # Authentication redirects here
    code = params[:code]
    
    # Used in the template
    @name = auth_hash.info.name
    @email = auth_hash.info.email
    
    # Request an access token
    result = acquire_auth_token(code, ENV['REPLY_URL'])
    
    # Associate this token to our user's session
    session[:access_token] = result.access_token
    # name -> session
    session[:name] = @name
    # email -> session
    session[:email] = @email
    
    # Debug logging
    puts "Code: #{code}"
    puts "Name: #{@name}"
    puts "Email: #{@email}"
    puts "[authd] - Access token: #{session[:access_token]}"
  end
  
  def send_mail
    puts "[send_mail] - Access token: #{session[:access_token]}"
    
    # Used in the template
    @name = session[:name]
    @email = params[:specified_email]
    @recipient = params[:specified_email]
    
    # TODO send the email...
    # check the status code and if in the success range AKA (200-299) we're good
    # otherwise report an error...
    
    render "authd"
  end

  def auth_hash
    request.env['omniauth.auth']
  end
  
  def acquire_auth_token(auth_code, reply_url)
    AUTH_CTX.acquire_token_with_authorization_code(
                  auth_code,
                  reply_url,
                  CLIENT_CRED,
                  GRAPH_RESOURCE)
  end
  
  def disconnect
    reset_session
    redirect = "#{ENV['LOGOUT_ENDPOINT']}?post_logout_redirect_uri=#{ERB::Util.url_encode(root_url)}"
    puts "REDIRECT: " + redirect
    redirect_to redirect
{'fraction_non_alphanumeric': 0.10413016270337923, 'fraction_numerical': 0.004005006257822278, 'mean_word_length': 2.9330708661417324, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, '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': '2745479', 'n_tokens_mistral': 1297, 'n_tokens_neox': 1256, 'n_words': 298}