Class: ZuoraConnect::ApplicationController

Inherits:
ActionController::Base
  • Object
show all
Defined in:
app/controllers/zuora_connect/application_controller.rb

Direct Known Subclasses

StaticController

Instance Method Summary collapse

Instance Method Details

#ldap_loginObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'app/controllers/zuora_connect/application_controller.rb', line 8

def 
  if !ZuoraConnect::AppInstance::INTERNAL_HOSTS.include?(request.headers.fetch("HOST", nil)) 
    render 'zuora_connect/application/ldap_login', locals: {
        title: 'Internal Auth Failure',
        message: 'Internal Auth Failure'
      }, :layout => false
  end

  require 'net-ldap'

  username = request.parameters['ldap_username']
  password = request.parameters['ldap_password']

  begin
    if ZuoraConnect::LDAP::Adapter.valid_credentials?(username, password)
      id = ZuoraConnect::AppInstance.first.id
      session["appInstance"] = ZuoraConnect::AppInstance.first.id
      session["#{id}::admin"] = true
      respond_to do |format|
        format.html { redirect_to '/admin/app_instances' }
      end
    else
      render 'zuora_connect/application/ldap_login', locals: {
        title: 'LDAP Authentication Failed',
        message: 'Invalid username or password'
      }, :layout => false
    end
  rescue Net::LDAP::Error
    render 'zuora_connect/application/ldap_login', locals: {
      title: 'LDAP Authentication Net Error',
      message: 'Failed to connect to server while authenticating the LDAP credentials. Please retry later.'
    }, :layout => false
  end
end