Commit 00975393 authored by frankiejol's avatar frankiejol
Browse files

refactor(auth): show error when no LDAP connected

parent e7b35fff
......@@ -492,6 +492,7 @@
$scope.ldap_entries = 0;
$scope.ldap_verified = 0;
$http.get('/list_ldap_attributes/'+$scope.cn).then(function(response) {
$scope.ldap_error = response.data.error;
$scope.ldap_attributes = response.data.attributes;
});
};
......
......@@ -124,6 +124,7 @@ our $SESSION_TIMEOUT_ADMIN2 = ($CONFIG_FRONT->{session_timeout_admin2} or 60 * 6
my $WS = Ravada::WebSocket->new(ravada => $RAVADA);
my %ALLOWED_ANONYMOUS_WS = map { $_ => 1 } qw(list_bases_anonymous list_alerts);
my %LDAP_ATTRIBUTES;
init();
############################################################################3
......@@ -912,15 +913,27 @@ get '/list_ldap_attributes/(#cn)' => sub {
return _access_denied($c) if !$USER->is_admin;
my $cn = $c->stash('cn');
return $c->render(json => $LDAP_ATTRIBUTES{$cn}) if exists $LDAP_ATTRIBUTES{$cn};
my $user;
eval {
($user) = Ravada::Auth::LDAP::search_user($cn);
};
return $c->render(json => { error => $@ }) if $@;
return $c->render(json => []) if !$user;
my $return;
if ( $@ ) {
my $error = $@;
$error =~ s/(.*) at lib\/Ravada.*/$1/;
$return = { error => $error };
} elsif (!$user) {
$return = { error => "User not found" };
} else {
$return = {attributes => [sort $user->attributes]};
}
$c->session(ldap_attributes_cn => $cn) if $user;
return $c->render(json => {attributes => [sort $user->attributes]});
$LDAP_ATTRIBUTES{$cn} = $return;
return $c->render( json => $return );
};
get '/count_ldap_entries/(#attribute)/(#value)' => sub {
......
......@@ -3,8 +3,13 @@
<%=l 'Type a typical LDAP user name to fetch the attribute list' %>
<input type="text" ng-model="cn" ng-change="list_ldap_attributes()"
ng-init="cn='<%= $ldap_attributes_cn %>'">
<div class="alert alert-danger d-inline-flex p-2" role="alert" ng-hide="ldap_attributes || !cn">
<div class="alert alert-danger" role="alert" ng-hide="ldap_attributes || !cn">
<div>
<%=l 'User name' %>&nbsp;<b>{{cn}}</b>&nbsp;<%=l 'not found in LDAP server' %>
</div>
<div>
{{ldap_error}}
</div>
</div>
</div>
<div class="card">
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment