class ZuoraConnect::ApplicationController
def ldap_login
def ldap_login 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