<commit_before># Using LDAP authentication and authorizion
class AdminAuthController < ApplicationController
  skip_before_action :authenticate_admin
  skip_before_action :verify_authenticity_token

  layout 'login'

  def new
  end

  def create
    reset_session_keys

    # TODO: remove comment when LDAP in place
    return stub_auth # if APP_CONFIG['stub_auth']

    @ldap = LdapAuth.new

    unless @ldap.authenticate(params[:username], params[:password])
      @error_message = 'Fel användarnamn eller lösenord. Vänligen försök igen'
      render 'new' && return
    end

    unless @ldap.belongs_to_group?
      @error_message = 'Du saknar behörighet till systemet'
      render 'new' && return
    end

    admin = @ldap.update_user_profile(username, role)
    if admin
      session[:admin_id] = admin.id
      update_session
      redirect_after_login && return
    end

    @error_message = 'Kunde inte spara användarinformationen'
    render 'new'
  end

  def destroy
    reset_session_keys
    redirect_to root_path, notice: 'Du är utloggad'
  end

  # Stubbed auth for local dev env
  # A user with the role admin has to exist first
  def stub_auth
    # TODO: remove comment when LDAP in place
    # unless Rails.application.config.consider_all_requests_local
    #   redirect_to root_path, warning: 'Stubbed authentication only available in local environment'
    # end

    admin = Admin.where(username: params[:username].strip.downcase).first
    if admin.save
      session[:admin_id] = admin.id
      update_session
      redirect_after_login
    else

      @error_message = "Användaren #{params[:username]} finns inte"
      render 'new'
    end
  end
end<commit_msg>Enabled LDAP<commit_after># Using LDAP authentication and authorizion
class AdminAuthController < ApplicationController
  skip_before_action :authenticate_admin
  skip_before_action :verify_authenticity_token

  layout 'login'

  def new
  end

  def create
    reset_session_keys

    return stub_auth if APP_CONFIG['stub_auth']

    @ldap = LdapAuth.new

    unless @ldap.authenticate(params[:username], params[:password])
      @error_message = 'Fel användarnamn eller lösenord. Vänligen försök igen'
      render 'new' && return
    end

    unless @ldap.belongs_to_group?
      @error_message = 'Du saknar behörighet till systemet'
      render 'new' && return
    end

    admin = @ldap.update_user_profile(username, role)
    if admin
      session[:admin_id] = admin.id
      update_session
      redirect_after_login && return
    end

    @error_message = 'Kunde inte spara användarinformationen'
    render 'new'
  end

  def destroy
    reset_session_keys
    redirect_to root_path, notice: 'Du är utloggad'
  end

  # Stubbed auth for local dev env
  # A user with the role admin has to exist first
  def stub_auth
    unless Rails.application.config.consider_all_requests_local
      redirect_to root_path, warning: 'Stubbed authentication only available in local environment'
    end

    admin = Admin.where(username: params[:username].strip.downcase).first
    if admin.save
      session[:admin_id] = admin.id
      update_session
      redirect_after_login
    else

      @error_message = "Användaren #{params[:username]} finns inte"
      render 'new'
    end
  end
end
{'fraction_non_alphanumeric': 0.06827186833282536, 'fraction_numerical': 0.0, 'mean_word_length': 3.376, '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': '7045540', 'n_tokens_mistral': 1024, 'n_tokens_neox': 991, 'n_words': 282}