Aesthetic code changes

This commit is contained in:
Luc Didry 2017-07-14 12:11:50 +02:00
parent 14cc832552
commit e65ee8dc9a
1 changed files with 8 additions and 8 deletions

View File

@ -11,7 +11,7 @@ $ENV{MOJO_MAX_WEBSOCKET_SIZE} = 100485760; # 10 * 1024 * 1024 = 10MiB
# This method will run once at server start # This method will run once at server start
sub startup { sub startup {
my $self = shift; my $self = shift;
my $entry = undef; my $entry;
my $config = $self->plugin('Config' => { my $config = $self->plugin('Config' => {
default => { default => {
@ -84,14 +84,14 @@ sub startup {
my $mesg = $ldap->bind($c->config->{ldap}->{bind_user}.$c->config->{ldap}->{bind_dn}, my $mesg = $ldap->bind($c->config->{ldap}->{bind_user}.$c->config->{ldap}->{bind_dn},
password => $c->config->{ldap}->{bind_pwd} password => $c->config->{ldap}->{bind_pwd}
); );
$mesg->code && die $mesg->error; $mesg->code && die $mesg->error;
$mesg = $ldap->search( $mesg = $ldap->search(
base => $c->config->{ldap}->{user_tree}, base => $c->config->{ldap}->{user_tree},
filter => "(&(uid=$username)".$c->config->{ldap}->{user_filter}.")" filter => "(&(uid=$username)".$c->config->{ldap}->{user_filter}.")"
); );
if ($mesg->code) { if ($mesg->code) {
$c->app->log->error($mesg->error); $c->app->log->error($mesg->error);
return undef; return undef;
@ -103,18 +103,18 @@ sub startup {
$c->app->log->info("[LDAP authentication failed] - User $username filtered out, IP: ".$c->ip); $c->app->log->info("[LDAP authentication failed] - User $username filtered out, IP: ".$c->ip);
return undef; return undef;
} }
# Now we know that the user exists, and that he is authorized by the filter # Now we know that the user exists, and that he is authorized by the filter
$mesg = $ldap->bind('uid='.$username.$c->config->{ldap}->{bind_dn}, $mesg = $ldap->bind('uid='.$username.$c->config->{ldap}->{bind_dn},
password => $password password => $password
); );
if ($mesg->code) { if ($mesg->code) {
$c->app->log->info("[LDAP authentication failed] login: $username, IP: ".$c->ip); $c->app->log->info("[LDAP authentication failed] login: $username, IP: ".$c->ip);
$c->app->log->error("[LDAP authentication failed] ".$mesg->error); $c->app->log->error("[LDAP authentication failed] ".$mesg->error);
return undef; return undef;
} }
$c->app->log->info("[LDAP authentication successful] login: $username, IP: ".$c->ip); $c->app->log->info("[LDAP authentication successful] login: $username, IP: ".$c->ip);
} elsif (defined($c->config('htpasswd'))) { } elsif (defined($c->config('htpasswd'))) {
my $htpasswd = new Apache::Htpasswd({passwdFile => $c->config->{htpasswd}, my $htpasswd = new Apache::Htpasswd({passwdFile => $c->config->{htpasswd},
@ -285,7 +285,7 @@ sub startup {
if($c->authenticate($login, $pwd)) { if($c->authenticate($login, $pwd)) {
$c->redirect_to('index'); $c->redirect_to('index');
} elsif (defined $entry) { } elsif (defined $entry) {
$c->stash(msg => $c->l('Please, check your credentials: unable to authenticate.')); $c->stash(msg => $c->l('Please, check your credentials: unable to authenticate.'));
$c->render(template => 'login'); $c->render(template => 'login');
} else { } else {