diff --git a/app/Http/Controllers/Api/SettingsController.php b/app/Http/Controllers/Api/SettingsController.php index 2edae03199..15b4d9eb8a 100644 --- a/app/Http/Controllers/Api/SettingsController.php +++ b/app/Http/Controllers/Api/SettingsController.php @@ -5,6 +5,8 @@ namespace App\Http\Controllers\Api; use Illuminate\Http\Request; use App\Http\Controllers\Controller; use App\Models\Ldap; +use Validator; +use App\Models\Setting; class SettingsController extends Controller { @@ -78,6 +80,11 @@ class SettingsController extends Controller public function ldaptest() { + if (Setting::getSettings()->ldap_enabled!='1') { + \Log::debug('LDAP is not enabled cannot test.'); + return response()->json(['message' => 'LDAP is not enabled, cannot test.'], 400); + } + \Log::debug('Preparing to test LDAP connection'); try { @@ -102,20 +109,37 @@ class SettingsController extends Controller public function ldaptestlogin(Request $request) { - \Log::debug('Preparing to test LDAP login'); + if (Setting::getSettings()->ldap_enabled!='1') { + \Log::debug('LDAP is not enabled. Cannot test.'); + return response()->json(['message' => 'LDAP is not enabled, cannot test.'], 400); + } + + $rules = array( + 'ldaptest_user' => 'required', + 'ldaptest_password' => 'required' + ); + + $validator = Validator::make($request->all(), $rules); + if ($validator->fails()) { + \Log::debug('LDAP Validation test failed.'); + return response()->json(['message' => $validator->errors()->all()], 400); + } + + + \Log::debug('Preparing to test LDAP login'); try { $connection = Ldap::connectToLdap(); try { - \Log::debug('Attempting to bind to LDAP for LDAP test'); Ldap::bindAdminToLdap($connection); + \Log::debug('Attempting to bind to LDAP for LDAP test'); try { $ldap_user = Ldap::findAndBindUserLdap($request->input('ldaptest_user'), $request->input('ldaptest_password')); if ($ldap_user) { \Log::debug('It worked! '. $request->input('ldaptest_user').' successfully binded to LDAP.'); return response()->json(['message' => 'It worked! '. $request->input('ldaptest_user').' successfully binded to LDAP.'], 200); } - return response()->json(['message' => 'Login Failed. '. $request->input('ldaptest_user').' successfully binded to LDAP.'], 400); + return response()->json(['message' => 'Login Failed. '. $request->input('ldaptest_user').' did not successfully bind to LDAP.'], 400); } catch (\Exception $e) { \Log::debug('LDAP login failed'); diff --git a/resources/views/settings/ldap.blade.php b/resources/views/settings/ldap.blade.php index 82496a8c7f..1232f89c8a 100644 --- a/resources/views/settings/ldap.blade.php +++ b/resources/views/settings/ldap.blade.php @@ -353,10 +353,10 @@