Class: Users::SessionsController

Inherits:
Devise::SessionsController
  • Object
show all
Defined in:
app/controllers/users/sessions_controller.rb

Overview

app/controllers/users/sessions_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'app/controllers/users/sessions_controller.rb', line 3

def create
  self.resource = warden.authenticate(auth_options)

  if resource
    Rails.logger.info("Authentication: Found local user, signing in")
    (resource)
  else
    Rails.logger.info("Authentication: Not found a local user, trying LDAP")
    user = Ldap::Authenticator.new(
      email: params[:user][:email],
      password: params[:user][:password],
    ).authenticate

    if user
      (user)
    else
      set_flash_message!(:alert, :invalid, authentication_keys: resource_class.authentication_keys.join(", "))

      self.resource = resource_class.new()
      clean_up_passwords(resource)
      respond_with_navigational(resource) { render :new, status: :unauthorized }
    end
  end
end