Merge branch 'master' of git@lx-office.linet-services.de:lx-office-erp
[kivitendo-erp.git] / SL / Auth.pm
index a2e9832..3b14def 100644 (file)
@@ -13,6 +13,7 @@ use SL::Auth::DB;
 use SL::Auth::LDAP;
 
 use SL::User;
+use SL::DBConnect;
 use SL::DBUpgrade2;
 use SL::DBUtils;
 
@@ -35,10 +36,19 @@ sub new {
   return $self;
 }
 
+sub reset {
+  my ($self, %params) = @_;
+
+  $self->{SESSION}          = { };
+  $self->{FULL_RIGHTS}      = { };
+  $self->{RIGHTS}           = { };
+  $self->{unique_counter}   = 0;
+}
+
 sub get_user_dbh {
   my ($self, $login) = @_;
   my %user = $self->read_user($login);
-  my $dbh  = DBI->connect(
+  my $dbh  = SL::DBConnect->connect(
     $user{dbconnect},
     $user{dbuser},
     $user{dbpasswd},
@@ -136,11 +146,11 @@ sub authenticate_root {
 sub authenticate {
   $main::lxdebug->enter_sub();
 
-  my $self = shift;
+  my ($self, $login, $password) = @_;
 
   $main::lxdebug->leave_sub();
 
-  my $result = $self->{authenticator}->authenticate(@_);
+  my $result = $login ? $self->{authenticator}->authenticate($login, $password) : ERR_USER;
   return OK if $result eq OK;
   sleep 5;
   return $result;
@@ -166,7 +176,7 @@ sub dbconnect {
 
   $main::lxdebug->message(LXDebug->DEBUG1, "Auth::dbconnect DSN: $dsn");
 
-  $self->{dbh} = DBI->connect($dsn, $cfg->{user}, $cfg->{password}, { pg_enable_utf8 => $::locale->is_utf8, AutoCommit => 1 });
+  $self->{dbh} = SL::DBConnect->connect($dsn, $cfg->{user}, $cfg->{password}, { pg_enable_utf8 => $::locale->is_utf8, AutoCommit => 1 });
 
   if (!$may_fail && !$self->{dbh}) {
     $main::form->error($main::locale->text('The connection to the authentication database failed:') . "\n" . $DBI::errstr);
@@ -246,7 +256,7 @@ sub create_database {
   my $encoding   = $Common::charset_to_db_encoding{$charset};
   $encoding    ||= 'UNICODE';
 
-  my $dbh        = DBI->connect($dsn, $params{superuser}, $params{superuser_password}, { pg_enable_utf8 => $charset =~ m/^utf-?8$/i });
+  my $dbh        = SL::DBConnect->connect($dsn, $params{superuser}, $params{superuser_password}, { pg_enable_utf8 => $charset =~ m/^utf-?8$/i });
 
   if (!$dbh) {
     $main::form->error($main::locale->text('The connection to the template database failed:') . "\n" . $DBI::errstr);
@@ -970,7 +980,7 @@ sub delete_group {
   my $self = shift;
   my $id   = shift;
 
-  my $form = $main::from;
+  my $form = $main::form;
 
   my $dbh  = $self->dbconnect();
   $dbh->begin_work;