View | Details | Raw Unified | Return to bug 20489
Collapse All | Expand All

(-)a/C4/Auth.pm (-46 / +1 lines)
Lines 1048-1057 sub checkauth { Link Here
1048
                }
1048
                }
1049
            }
1049
            }
1050
1050
1051
            # $return: 1 = valid user, 2 = superlibrarian
1051
            # $return: 1 = valid user
1052
            if ($return) {
1052
            if ($return) {
1053
                # If DB user is logged in
1054
                $userid ||= $q_userid if $return == 2;
1055
1053
1056
                #_session_log(sprintf "%20s from %16s logged in  at %30s.\n", $userid,$ENV{'REMOTE_ADDR'},(strftime '%c', localtime));
1054
                #_session_log(sprintf "%20s from %16s logged in  at %30s.\n", $userid,$ENV{'REMOTE_ADDR'},(strftime '%c', localtime));
1057
                if ( $flags = haspermission( $userid, $flagsrequired ) ) {
1055
                if ( $flags = haspermission( $userid, $flagsrequired ) ) {
Lines 1151-1172 sub checkauth { Link Here
1151
                    $session->param( 'shibboleth',   $shibSuccess );
1149
                    $session->param( 'shibboleth',   $shibSuccess );
1152
                    $debug and printf STDERR "AUTH_4: (%s)\t%s %s - %s\n", map { $session->param($_) } qw(cardnumber firstname surname branch);
1150
                    $debug and printf STDERR "AUTH_4: (%s)\t%s %s - %s\n", map { $session->param($_) } qw(cardnumber firstname surname branch);
1153
                }
1151
                }
1154
                elsif ( $return == 2 ) {
1155
1156
                    #We suppose the user is the superlibrarian
1157
                    $borrowernumber = 0;
1158
                    $session->param( 'number',       0 );
1159
                    $session->param( 'id',           C4::Context->config('user') );
1160
                    $session->param( 'cardnumber',   C4::Context->config('user') );
1161
                    $session->param( 'firstname',    C4::Context->config('user') );
1162
                    $session->param( 'surname',      C4::Context->config('user') );
1163
                    $session->param( 'branch',       'NO_LIBRARY_SET' );
1164
                    $session->param( 'branchname',   'NO_LIBRARY_SET' );
1165
                    $session->param( 'flags',        1 );
1166
                    $session->param( 'emailaddress', C4::Context->preference('KohaAdminEmailAddress') );
1167
                    $session->param( 'ip',           $session->remote_addr() );
1168
                    $session->param( 'lasttime',     time() );
1169
                }
1170
                $session->param('cas_ticket', $cas_ticket) if $cas_ticket;
1152
                $session->param('cas_ticket', $cas_ticket) if $cas_ticket;
1171
                C4::Context->set_userenv(
1153
                C4::Context->set_userenv(
1172
                    $session->param('number'),       $session->param('id'),
1154
                    $session->param('number'),       $session->param('id'),
Lines 1598-1617 sub check_api_auth { Link Here
1598
                $session->param( 'emailaddress', $emailaddress );
1580
                $session->param( 'emailaddress', $emailaddress );
1599
                $session->param( 'ip',           $session->remote_addr() );
1581
                $session->param( 'ip',           $session->remote_addr() );
1600
                $session->param( 'lasttime',     time() );
1582
                $session->param( 'lasttime',     time() );
1601
            } elsif ( $return == 2 ) {
1602
1603
                #We suppose the user is the superlibrarian
1604
                $session->param( 'number',       0 );
1605
                $session->param( 'id',           C4::Context->config('user') );
1606
                $session->param( 'cardnumber',   C4::Context->config('user') );
1607
                $session->param( 'firstname',    C4::Context->config('user') );
1608
                $session->param( 'surname',      C4::Context->config('user') );
1609
                $session->param( 'branch',       'NO_LIBRARY_SET' );
1610
                $session->param( 'branchname',   'NO_LIBRARY_SET' );
1611
                $session->param( 'flags',        1 );
1612
                $session->param( 'emailaddress', C4::Context->preference('KohaAdminEmailAddress') );
1613
                $session->param( 'ip',           $session->remote_addr() );
1614
                $session->param( 'lasttime',     time() );
1615
            }
1583
            }
1616
            $session->param( 'cas_ticket', $cas_ticket);
1584
            $session->param( 'cas_ticket', $cas_ticket);
1617
            C4::Context->set_userenv(
1585
            C4::Context->set_userenv(
Lines 1805-1811 sub checkpw { Link Here
1805
    # 1 if auth is ok
1773
    # 1 if auth is ok
1806
    # 0 if auth is nok
1774
    # 0 if auth is nok
1807
    # -1 if user bind failed (LDAP only)
1775
    # -1 if user bind failed (LDAP only)
1808
    # 2 if DB user is used (internal only)
1809
1776
1810
    if ( $patron and $patron->account_locked ) {
1777
    if ( $patron and $patron->account_locked ) {
1811
        # Nothing to check, account is locked
1778
        # Nothing to check, account is locked
Lines 1878-1895 sub checkpw_internal { Link Here
1878
    $password = Encode::encode( 'UTF-8', $password )
1845
    $password = Encode::encode( 'UTF-8', $password )
1879
      if Encode::is_utf8($password);
1846
      if Encode::is_utf8($password);
1880
1847
1881
    if ( $userid && $userid eq C4::Context->config('user') ) {
1882
        if ( $password && $password eq C4::Context->config('pass') ) {
1883
1884
            # Koha superuser account
1885
            #     C4::Context->set_userenv(0,0,C4::Context->config('user'),C4::Context->config('user'),C4::Context->config('user'),"",1);
1886
            return 2;
1887
        }
1888
        else {
1889
            return 0;
1890
        }
1891
    }
1892
1893
    my $sth =
1848
    my $sth =
1894
      $dbh->prepare(
1849
      $dbh->prepare(
1895
        "select password,cardnumber,borrowernumber,userid,firstname,surname,borrowers.branchcode,branches.branchname,flags from borrowers join branches on borrowers.branchcode=branches.branchcode where userid=?"
1850
        "select password,cardnumber,borrowernumber,userid,firstname,surname,borrowers.branchcode,branches.branchname,flags from borrowers join branches on borrowers.branchcode=branches.branchcode where userid=?"
(-)a/acqui/neworderempty.pl (+3 lines)
Lines 203-208 else { #modify order Link Here
203
        my $order_patron = Koha::Patrons->find( $order_user_id );
203
        my $order_patron = Koha::Patrons->find( $order_user_id );
204
        push @order_users, $order_patron if $order_patron;
204
        push @order_users, $order_patron if $order_patron;
205
    }
205
    }
206
    if ( $data->{subscriptionid} ) {
207
        $template->param( subscriptionid => $data->{subscriptionid} );
208
    }
206
}
209
}
207
210
208
my $suggestion;
211
my $suggestion;
(-)a/members/member-flags.pl (-5 / +2 lines)
Lines 44-54 my ($template, $loggedinuser, $cookie) = get_template_and_user({ Link Here
44
        debug           => 1,
44
        debug           => 1,
45
});
45
});
46
46
47
my $userenv = C4::Context->userenv;
47
my $logged_in_user = Koha::Patrons->find( $loggedinuser ) or die "Not logged in";
48
if ( $userenv and $userenv->{number} ) { # Allow DB user to create a superlibrarian patron
48
output_and_exit_if_error( $input, $cookie, $template, { module => 'members', logged_in_user => $logged_in_user, current_patron => $patron } );
49
    my $logged_in_user = Koha::Patrons->find( $loggedinuser ) or die "Not logged in";
50
    output_and_exit_if_error( $input, $cookie, $template, { module => 'members', logged_in_user => $logged_in_user, current_patron => $patron } );
51
}
52
49
53
my %member2;
50
my %member2;
54
$member2{'borrowernumber'}=$member;
51
$member2{'borrowernumber'}=$member;
(-)a/members/memberentry.pl (-4 / +2 lines)
Lines 152-161 $template->param( "quickadd" => 1 ) if ( $quickadd ); Link Here
152
$template->param( "duplicate" => 1 ) if ( $op eq 'duplicate' );
152
$template->param( "duplicate" => 1 ) if ( $op eq 'duplicate' );
153
$template->param( "checked" => 1 ) if ( defined($nodouble) && $nodouble eq 1 );
153
$template->param( "checked" => 1 ) if ( defined($nodouble) && $nodouble eq 1 );
154
if ( $op eq 'modify' or $op eq 'save' or $op eq 'duplicate' ) {
154
if ( $op eq 'modify' or $op eq 'save' or $op eq 'duplicate' ) {
155
    if ( $patron and $userenv and $userenv->{number} ) { # Allow DB user to create a superlibrarian patron
155
    my $logged_in_user = Koha::Patrons->find( $loggedinuser ) or die "Not logged in";
156
        my $logged_in_user = Koha::Patrons->find( $loggedinuser ) or die "Not logged in";
156
    output_and_exit_if_error( $input, $cookie, $template, { module => 'members', logged_in_user => $logged_in_user, current_patron => $patron } );
157
        output_and_exit_if_error( $input, $cookie, $template, { module => 'members', logged_in_user => $logged_in_user, current_patron => $patron } );
158
    }
159
157
160
    $borrower_data = $patron->unblessed;
158
    $borrower_data = $patron->unblessed;
161
    $borrower_data->{category_type} = $patron->category->category_type;
159
    $borrower_data->{category_type} = $patron->category->category_type;
(-)a/members/moremember.pl (-5 / +3 lines)
Lines 122-132 my $error = $input->param('error'); Link Here
122
$template->param( error => $error ) if ( $error );
122
$template->param( error => $error ) if ( $error );
123
123
124
my $patron         = Koha::Patrons->find( $borrowernumber );
124
my $patron         = Koha::Patrons->find( $borrowernumber );
125
my $userenv = C4::Context->userenv;
125
my $logged_in_user = Koha::Patrons->find( $loggedinuser ) or die "Not logged in";
126
if ( $userenv and $userenv->{number} ) { # Allow DB user to create a superlibrarian patron
126
output_and_exit_if_error( $input, $cookie, $template, { module => 'members', logged_in_user => $logged_in_user, current_patron => $patron } );
127
    my $logged_in_user = Koha::Patrons->find( $loggedinuser ) or die "Not logged in";
128
    output_and_exit_if_error( $input, $cookie, $template, { module => 'members', logged_in_user => $logged_in_user, current_patron => $patron } );
129
}
130
127
131
my $issues        = $patron->checkouts;
128
my $issues        = $patron->checkouts;
132
my $balance       = $patron->account->balance;
129
my $balance       = $patron->account->balance;
Lines 206-211 if ( C4::Context->preference("IndependentBranches") ) { Link Here
206
        $samebranch = 1;
203
        $samebranch = 1;
207
    }
204
    }
208
    else {
205
    else {
206
        my $userenv = C4::Context->userenv;
209
        $samebranch = ( $data->{'branchcode'} eq $userenv->{branch} );
207
        $samebranch = ( $data->{'branchcode'} eq $userenv->{branch} );
210
    }
208
    }
211
}
209
}
(-)a/t/db_dependent/Auth.t (-2 / +1 lines)
Lines 62-68 subtest 'checkauth() tests' => sub { Link Here
62
            else { return; }
62
            else { return; }
63
        });
63
        });
64
    ( $userid, $cookie, $sessionID, $flags ) = C4::Auth::checkauth( $cgi, $authnotrequired );
64
    ( $userid, $cookie, $sessionID, $flags ) = C4::Auth::checkauth( $cgi, $authnotrequired );
65
    is ( $userid, $db_user_id, 'If DB user is logging in, it should be considered as logged in, i.e. checkauth return the relevant userid' );
65
    is ( $userid, undef, 'If DB user is used, it should not be logged in' );
66
    C4::Context->_new_userenv; # For next tests
66
    C4::Context->_new_userenv; # For next tests
67
67
68
};
68
};
69
- 

Return to bug 20489