mirror of
https://github.com/snipe/snipe-it.git
synced 2024-12-25 05:34:06 -08:00
LDAP test login
This commit is contained in:
parent
ba7b9d8168
commit
f1a6926ad9
|
@ -99,4 +99,35 @@ class SettingsController extends Controller
|
|||
|
||||
}
|
||||
|
||||
public function ldaptestlogin(Request $request)
|
||||
{
|
||||
|
||||
\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);
|
||||
try {
|
||||
$ldap_user = Ldap::findAndBindUserLdap($request->input('ldaptest_user'), $request->input('ldaptest_password'));
|
||||
return response()->json(['message' => 'It worked! '. $request->input('username').' successfully binded to LDAP.'], 200);
|
||||
} catch (\Exception $e) {
|
||||
\Log::debug('LDAP login failed');
|
||||
return response()->json(['message' => $e->getMessage()], 400);
|
||||
}
|
||||
|
||||
} catch (\Exception $e) {
|
||||
\Log::debug('Bind failed');
|
||||
return response()->json(['message' => $e->getMessage()], 400);
|
||||
//return response()->json(['message' => $e->getMessage()], 500);
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
\Log::debug('Connection failed');
|
||||
return response()->json(['message' => $e->getMessage()], 600);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -328,24 +328,52 @@
|
|||
</div>
|
||||
|
||||
|
||||
@if ($setting->ldap_enabled)
|
||||
<!-- LDAP test -->
|
||||
<div class="form-group {{ $errors->has('ldap_email') ? 'error' : '' }}">
|
||||
<div class="col-md-3">
|
||||
Test LDAP Connection
|
||||
Test LDAP Sync
|
||||
</div>
|
||||
<div class="col-md-9">
|
||||
<div id="ldaptestrow">
|
||||
<div class="col-md-9" id="ldaptestrow">
|
||||
<a class="btn btn-default btn-sm pull-left" id="ldaptest" style="margin-right: 10px;"> Test LDAP</a>
|
||||
<span id="ldaptesticon"></span>
|
||||
<span id="ldaptestresult"></span>
|
||||
<span id="ldapteststatus"></span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-9 col-md-offset-3">
|
||||
<p class="help-block">This only tests that LDAP can sync correctly. If your LDAP Authentication query is not correct, users may still not be able to login.</p>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
<!-- LDAP Login test -->
|
||||
<div class="form-group {{ $errors->has('ldap_email') ? 'error' : '' }}">
|
||||
<div class="col-md-3">
|
||||
Test LDAP Login
|
||||
</div>
|
||||
<div class="col-md-9" id="ldaptestloginrow">
|
||||
<div class="row">
|
||||
<div class="col-md-4">
|
||||
<input type="text" name="ldaptest_user" class="form-control" placeholder="LDAP username">
|
||||
</div>
|
||||
<div class="col-md-4">
|
||||
<input type="password" name="ldaptest_password" class="form-control" placeholder="LDAP password">
|
||||
</div>
|
||||
<div class="col-md-3">
|
||||
<a class="btn btn-default btn-sm" id="ldaptestlogin" style="margin-right: 10px;">Test LDAP</a>
|
||||
</div>
|
||||
<span id="ldaptestloginicon"></span>
|
||||
<span id="ldaptestloginresult"></span>
|
||||
<span id="ldaptestloginstatus"></span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-9 col-md-offset-3">
|
||||
<p class="help-block">Enter a valid LDAP username and password to test whether your LDAP login is configured correctly.</p>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
@endif
|
||||
|
||||
</div>
|
||||
|
||||
</div> <!--/.box-body-->
|
||||
<div class="box-footer">
|
||||
<div class="text-left col-md-6">
|
||||
|
@ -404,6 +432,39 @@
|
|||
});
|
||||
});
|
||||
|
||||
$("#ldaptestlogin").click(function(){
|
||||
$("#ldaptestloginrow").removeClass('success');
|
||||
$("#ldaptestloginrow").removeClass('danger');
|
||||
$("#ldaptestloginstatus").html('');
|
||||
$("#ldaptestloginicon").html('<i class="fa fa-spinner spin"></i>');
|
||||
$.ajax({
|
||||
url: '{{ route('api.settings.ldaptestlogin') }}',
|
||||
type: 'POST',
|
||||
headers: {
|
||||
"X-Requested-With": 'XMLHttpRequest',
|
||||
"X-CSRF-TOKEN": $('meta[name="csrf-token"]').attr('content')
|
||||
},
|
||||
data: {},
|
||||
dataType: 'json',
|
||||
|
||||
success: function (data) {
|
||||
$("#ldaptestloginicon").html('');
|
||||
$("#ldaptestloginrow").addClass('success');
|
||||
$("#ldaptestloginstatus").html('<i class="fa fa-check text-success"></i> It worked!');
|
||||
},
|
||||
|
||||
error: function (data) {
|
||||
//console.dir(data);
|
||||
$("#ldaptestloginicon").html('');
|
||||
$("#ldaptestloginrow").addClass('danger');
|
||||
$("#ldaptestloginicon").html('<i class="fa fa-exclamation-triangle text-danger"></i>');
|
||||
$('#ldaptestloginstatus').text(data.responseText.message);
|
||||
}
|
||||
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
|
||||
</script>
|
||||
|
|
|
@ -423,6 +423,11 @@ Route::group(['prefix' => 'v1','namespace' => 'Api'], function () {
|
|||
'as' => 'api.settings.ldaptest',
|
||||
'uses' => 'SettingsController@ldaptest'
|
||||
]);
|
||||
|
||||
Route::post('settings/ldaptestlogin', [
|
||||
'as' => 'api.settings.ldaptestlogin',
|
||||
'uses' => 'SettingsController@ldaptestlogin'
|
||||
]);
|
||||
|
||||
Route::resource('settings', 'SettingsController',
|
||||
[
|
||||
|
|
Loading…
Reference in a new issue