- my ($self, $form, $userspath) = @_;
-
- my $rc = -3;
-
- if ($self->{login}) {
-
- if ($self->{password}) {
- $form->{password} = crypt $form->{password}, substr($self->{login}, 0, 2);
- if ($self->{password} ne $form->{password}) {
- $main::lxdebug->leave_sub();
- return -1;
- }
- }
-
- unless (-e "$userspath/$self->{login}.conf") {
- $self->create_config("$userspath/$self->{login}.conf");
- }
-
- do "$userspath/$self->{login}.conf";
- $myconfig{dbpasswd} = unpack 'u', $myconfig{dbpasswd};
-
- # check if database is down
- my $dbh = DBI->connect($myconfig{dbconnect}, $myconfig{dbuser}, $myconfig{dbpasswd}) or $self->error(DBI::errstr);
-
- # we got a connection, check the version
- my $query = qq|SELECT version FROM defaults|;
- my $sth = $dbh->prepare($query);
- $sth->execute || $form->dberror($query);
-
- my ($dbversion) = $sth->fetchrow_array;
- $sth->finish;
-
- # add login to employee table if it does not exist
- # no error check for employee table, ignore if it does not exist
- $query = qq|SELECT e.id FROM employee e WHERE e.login = '$self->{login}'|;
- $sth = $dbh->prepare($query);
- $sth->execute;
-
- my ($login) = $sth->fetchrow_array;
- $sth->finish;
-
- if (!$login) {
- $query = qq|INSERT INTO employee (login, name, workphone, role)
- VALUES ('$self->{login}', '$myconfig{name}',
- '$myconfig{tel}', 'user')|;
- $dbh->do($query);
- }
- $dbh->disconnect;