<commit_before>class Backend::BackendController < ApplicationController
  respond_to :html
  layout "backend"
  helper_method :clubnames_for_current_user

  before_filter :verify_cas, :verify_club

  def verify_cas
    puts :test
    if session[:cas].blank? #&& !Rails.env.development?
      redirect_to cas_auth_path(:redirect => request.fullpath)
    end
  end

  def verify_club
    @club = Club.with_internal_name(clubname_for_current_user).first
    unless @club
      render '/backend/denied', :status => 403
    end
  end

  # return which club this ugent_login is allowed to manage
  # Provides a default club for backwards compatibility
  def clubname_for_current_user
    if session[:club].blank?
      session[:club] = clubnames_for_current_user.first
    end
    session[:club]
  end

  def clubnames_for_current_user
    if session['clubnames'].blank?
      session['clubnames'] = request_clubnames
    end
    session['clubnames']
  end

  private
  def request_clubnames
    # Development backdoor
    #return Club.pluck(:internal_name) if Rails.env.development?

    ugent_login = session[:cas]['user']

    def digest(*args)
      Digest::SHA256.hexdigest args.join('-')
    end

    # using httparty because it is much easier to read than net/http code
    resp = HTTParty.get("#{ Rails.application.secrets.fk_auth_url }/#{ ugent_login }/FKEnrolment",
                        headers: {
                            'X-Authorization': Rails.application.secrets.fk_auth_key,
                            Accept: 'application/json'
                        })

    # this will only return the club names if control-hash matches
    if resp.success?
      hash = JSON[resp.body]<commit_msg>Oeps, these weren't mean to be committed<commit_after>class Backend::BackendController < ApplicationController
  respond_to :html
  layout "backend"
  helper_method :clubnames_for_current_user

  before_filter :verify_cas, :verify_club

  def verify_cas
    if session[:cas].blank? && !Rails.env.development?
      redirect_to cas_auth_path(:redirect => request.fullpath)
    end
  end

  def verify_club
    @club = Club.with_internal_name(clubname_for_current_user).first
    unless @club
      render '/backend/denied', :status => 403
    end
  end

  # return which club this ugent_login is allowed to manage
  # Provides a default club for backwards compatibility
  def clubname_for_current_user
    if session[:club].blank?
      session[:club] = clubnames_for_current_user.first
    end
    session[:club]
  end

  def clubnames_for_current_user
    if session['clubnames'].blank?
      session['clubnames'] = request_clubnames
    end
    session['clubnames']
  end

  private
  def request_clubnames
    # Development backdoor
    return Club.pluck(:internal_name) if Rails.env.development?

    ugent_login = session[:cas]['user']

    def digest(*args)
      Digest::SHA256.hexdigest args.join('-')
    end

    # using httparty because it is much easier to read than net/http code
    resp = HTTParty.get("#{ Rails.application.secrets.fk_auth_url }/#{ ugent_login }/FKEnrolment",
                        headers: {
                            'X-Authorization': Rails.application.secrets.fk_auth_key,
                            Accept: 'application/json'
                        })

    # this will only return the club names if control-hash matches
    if resp.success?
      hash = JSON[resp.body]
{'fraction_non_alphanumeric': 0.08699472759226713, 'fraction_numerical': 0.0035149384885764497, 'mean_word_length': 2.902857142857143, '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': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '815635', 'n_tokens_mistral': 1033, 'n_tokens_neox': 984, 'n_words': 247}