You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
58 lines
1.3 KiB
58 lines
1.3 KiB
package LDV::User; |
|
|
|
use strict; |
|
use warnings; |
|
use utf8; |
|
|
|
use Mojo::Base 'Mojolicious::Controller'; |
|
|
|
use Net::LDAP; |
|
use Net::LDAP::Util qw(ldap_error_name); |
|
|
|
sub create { my ($self) = @_; $self->render(); } |
|
sub login { my ($self) = @_; $self->render(); } |
|
|
|
sub logout { |
|
my ($self) = @_; |
|
|
|
$self->session({useruid => undef}); |
|
$self->redirect_to('/user/login'); |
|
$self->rendered(); |
|
} |
|
|
|
sub update { |
|
my ($self) = @_; |
|
my ($data, $login); |
|
|
|
unless ($login = $self->session('useruid')) { |
|
$self->redirect_to('/user/login'); |
|
return; |
|
} |
|
|
|
eval { |
|
my ($ldap, $mesg); |
|
$ldap = Net::LDAP->new($self->app->config->{server}) |
|
or die("$@"); |
|
$mesg = $ldap->bind($self->app->config->{binddn}, |
|
password => $self->app->config->{bindpass}); |
|
if ($mesg->code) { |
|
$self->app->log->error($mesg->error); |
|
die("Can't connect to server\n"); |
|
} |
|
my $base = $self->app->config->{userbase}; |
|
my $attrs = [ @{$self->app->config->{defattrs}} ]; |
|
$mesg = $ldap->search(base => $base, scope => 'one', deref => 'never', |
|
filter => '(&(uid=$login)(class=InetOrgPerson))', |
|
attrs => $attrs); |
|
die("User not found\n") |
|
unless ($mesg->count); |
|
my $entry = $mesg->pop_entry(); |
|
1; |
|
} or do { |
|
}; |
|
|
|
$self->stash({user_data => $data}); |
|
$self->render(); |
|
} |
|
|
|
1;
|
|
|