Sha256: 647150c86bc2e997e6209a90326c580a41abcdbd435cda11e94f2e7db9902cce

Contents?: true

Size: 933 Bytes

Versions: 2

Compression:

Stored size: 933 Bytes

Contents

require 'chaltron/ldap/user'

module Chaltron
  class OmniauthCallbacksController < Devise::OmniauthCallbacksController

  default_log_category :login

    def ldap
#      puts '##########################################'
#      puts oauth.inspect
#      puts '##########################################'
      # We only find ourselves here
      # if the authentication to LDAP was successful.
      user = Chaltron::LDAP::User.find_or_create(oauth, Chaltron.ldap_allow_all)
      if user.nil?
        redirect_to root_url, alert: I18n.t('chaltron.not_allowed_to_sign_in')
      else
        user.remember_me = true if user.persisted?
        flash[:notice] = I18n.t('devise.sessions.signed_in')

        info I18n.t('chaltron.logs.login_via', user: user.display_name, provider: 'ldap')
        sign_in_and_redirect(user)
      end
    end

    private

    def oauth
      @oauth ||= request.env['omniauth.auth']
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
chaltron-0.1.1 app/controllers/chaltron/omniauth_callbacks_controller.rb
chaltron-0.1.0 app/controllers/chaltron/omniauth_callbacks_controller.rb