Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 722fee3c

Von Moritz Bunkus vor mehr als 11 Jahren hinzugefügt

  • ID 722fee3c7224fa0b1222b9f5134e2c19dc021c64
  • Vorgänger 1c7afd9e
  • Nachfolger 0afeb736

Userlogin mit Mandanten gefixt (erster Schritt)

Unterschiede anzeigen:

SL/Auth.pm
65 65

  
66 66
  $self->client(undef);
67 67

  
68
  return undef unless $id_or_name;
69

  
68 70
  my $column = $id_or_name =~ m/^\d+$/ ? 'id' : 'name';
69 71
  my $dbh    = $self->dbconnect;
70 72

  
......
75 77
  return $self->client;
76 78
}
77 79

  
78
sub get_user_dbh {
79
  my ($self, $login, %params) = @_;
80
  my $may_fail = delete $params{may_fail};
81

  
82
  my %user = $self->read_user(login => $login);
83
  my $dbh  = SL::DBConnect->connect(
84
    $user{dbconnect},
85
    $user{dbuser},
86
    $user{dbpasswd},
87
    {
88
      pg_enable_utf8 => $::locale->is_utf8,
89
      AutoCommit     => 0
90
    }
91
  );
92

  
93
  if (!$may_fail && !$dbh) {
94
    $::form->error($::locale->text('The connection to the authentication database failed:') . "\n" . $DBI::errstr);
95
  }
96

  
97
  if ($user{dboptions} && $dbh) {
98
    $dbh->do($user{dboptions}) or $::form->dberror($user{dboptions});
99
  }
100

  
101
  return $dbh;
102
}
103

  
104 80
sub DESTROY {
105 81
  my $self = shift;
106 82

  
......
166 142
  $main::lxdebug->leave_sub();
167 143
}
168 144

  
145
sub has_access_to_client {
146
  my ($self, $login) = @_;
147

  
148
  return 0 if !$self->client || !$self->client->{id};
149

  
150
  my $sql = <<SQL;
151
    SELECT cu.client_id
152
    FROM auth.clients_users cu
153
    LEFT JOIN auth."user" u ON (cu.user_id = u.id)
154
    WHERE (u.login      = ?)
155
      AND (cu.client_id = ?)
156
SQL
157

  
158
  my ($has_access) = $self->dbconnect->selectrow_array($sql, undef, $login, $self->client->{id});
159
  return $has_access;
160
}
161

  
169 162
sub authenticate_root {
170 163
  $main::lxdebug->enter_sub();
171 164

  
......
197 190

  
198 191
  my ($self, $login, $password) = @_;
199 192

  
193
  if (!$self->client || !$self->has_access_to_client($login)) {
194
    $::lxdebug->leave_sub;
195
    return ERR_PASSWORD;
196
  }
197

  
200 198
  my $session_auth = $self->get_session_value(SESSION_KEY_USER_AUTH());
201 199
  if (defined $session_auth && $session_auth == OK) {
202 200
    $::lxdebug->leave_sub;
......
209 207
  }
210 208

  
211 209
  my $result = $login ? $self->{authenticator}->authenticate($login, $password) : ERR_USER;
212
  $self->set_session_value(SESSION_KEY_USER_AUTH() => $result, login => $login);
210
  $self->set_session_value(SESSION_KEY_USER_AUTH() => $result, login => $login, client_id => $self->client->{id});
213 211

  
214 212
  $::lxdebug->leave_sub;
215 213
  return $result;
......
550 548

  
551 549
  my $dbh   = $self->dbconnect;
552 550
  my $id    = $self->get_user_id($login);
553
  my $user_db_exists;
554 551

  
555 552
  $dbh->rollback and return $::lxdebug->leave_sub if (!$id);
556 553

  
557
  my $u_dbh = $self->get_user_dbh($login, may_fail => 1);
558
  $user_db_exists = $self->check_tables($u_dbh) if $u_dbh;
559

  
560
  $u_dbh->begin_work if $u_dbh && $user_db_exists;
561

  
562 554
  $dbh->begin_work;
563 555

  
564 556
  do_query($::form, $dbh, qq|DELETE FROM auth.user_group WHERE user_id = ?|, $id);
565 557
  do_query($::form, $dbh, qq|DELETE FROM auth.user_config WHERE user_id = ?|, $id);
566 558
  do_query($::form, $dbh, qq|DELETE FROM auth.user WHERE id = ?|, $id);
567
  do_query($::form, $u_dbh, qq|UPDATE employee SET deleted = 't' WHERE login = ?|, $login) if $u_dbh && $user_db_exists;
559

  
560
  # TODO: SL::Auth::delete_user
561
  # do_query($::form, $u_dbh, qq|UPDATE employee SET deleted = 't' WHERE login = ?|, $login) if $u_dbh && $user_db_exists;
568 562

  
569 563
  $dbh->commit;
570
  $u_dbh->commit if $u_dbh && $user_db_exists;
571 564

  
572 565
  $::lxdebug->leave_sub;
573 566
}

Auch abrufbar als: Unified diff