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

(-)a/C4/Auth.pm (-3 / +6 lines)
Lines 1149-1155 sub checkauth { Link Here
1149
            }
1149
            }
1150
1150
1151
            # $return: 1 = valid user
1151
            # $return: 1 = valid user
1152
            if ($return) {
1152
            if ($return > 0) {
1153
1153
1154
                if ( $flags = haspermission( $userid, $flagsrequired ) ) {
1154
                if ( $flags = haspermission( $userid, $flagsrequired ) ) {
1155
                    $auth_state = "logged_in";
1155
                    $auth_state = "logged_in";
Lines 1909-1916 sub checkpw { Link Here
1909
    # 0 if auth is nok
1909
    # 0 if auth is nok
1910
    # -1 if user bind failed (LDAP only)
1910
    # -1 if user bind failed (LDAP only)
1911
1911
1912
    if ( $patron and ( $patron->account_locked || $patron->password_expired )  ) {
1912
    if ( $patron and ( $patron->account_locked )  ) {
1913
        # Nothing to check, account is locked or password expired
1913
        # Nothing to check, account is locked
1914
    } elsif ($ldap && defined($password)) {
1914
    } elsif ($ldap && defined($password)) {
1915
        my ( $retval, $retcard, $retuserid ) = checkpw_ldap(@_);    # EXTERNAL AUTH
1915
        my ( $retval, $retcard, $retuserid ) = checkpw_ldap(@_);    # EXTERNAL AUTH
1916
        if ( $retval == 1 ) {
1916
        if ( $retval == 1 ) {
Lines 1963-1968 sub checkpw { Link Here
1963
    if( $patron ) {
1963
    if( $patron ) {
1964
        if ( $passwd_ok ) {
1964
        if ( $passwd_ok ) {
1965
            $patron->update({ login_attempts => 0 });
1965
            $patron->update({ login_attempts => 0 });
1966
            if( $patron->password_expired ){
1967
                @return = (-2);
1968
            }
1966
        } elsif( !$patron->account_locked ) {
1969
        } elsif( !$patron->account_locked ) {
1967
            $patron->update({ login_attempts => $patron->login_attempts + 1 });
1970
            $patron->update({ login_attempts => $patron->login_attempts + 1 });
1968
        }
1971
        }
(-)a/C4/ILSDI/Services.pm (-1 / +4 lines)
Lines 398-410 sub AuthenticatePatron { Link Here
398
    my $username = $cgi->param('username');
398
    my $username = $cgi->param('username');
399
    my $password = $cgi->param('password');
399
    my $password = $cgi->param('password');
400
    my ($status, $cardnumber, $userid) = C4::Auth::checkpw( C4::Context->dbh, $username, $password );
400
    my ($status, $cardnumber, $userid) = C4::Auth::checkpw( C4::Context->dbh, $username, $password );
401
    if ( $status ) {
401
    if ( $status == 1 ) {
402
        # Track the login
402
        # Track the login
403
        C4::Auth::track_login_daily( $userid );
403
        C4::Auth::track_login_daily( $userid );
404
        # Get the borrower
404
        # Get the borrower
405
        my $patron = Koha::Patrons->find( { userid => $userid } );
405
        my $patron = Koha::Patrons->find( { userid => $userid } );
406
        return { id => $patron->borrowernumber };
406
        return { id => $patron->borrowernumber };
407
    }
407
    }
408
    elsif ( $status == -2 ){
409
        return { code => 'PasswordExpired' };
410
    }
408
    else {
411
    else {
409
        return { code => 'PatronNotFound' };
412
        return { code => 'PatronNotFound' };
410
    }
413
    }
(-)a/t/db_dependent/Auth.t (-1 / +17 lines)
Lines 10-16 use CGI qw ( -utf8 ); Link Here
10
use Test::MockObject;
10
use Test::MockObject;
11
use Test::MockModule;
11
use Test::MockModule;
12
use List::MoreUtils qw/all any none/;
12
use List::MoreUtils qw/all any none/;
13
use Test::More tests => 15;
13
use Test::More tests => 16;
14
use Test::Warn;
14
use Test::Warn;
15
use t::lib::Mocks;
15
use t::lib::Mocks;
16
use t::lib::TestBuilder;
16
use t::lib::TestBuilder;
Lines 506-511 subtest 'Check value of login_attempts in checkpw' => sub { Link Here
506
    is( $patron->account_locked, 1, 'Check administrative lockout without pref' );
506
    is( $patron->account_locked, 1, 'Check administrative lockout without pref' );
507
};
507
};
508
508
509
subtest 'Check value of login_attempts in checkpw' => sub {
510
    plan tests => 2;
511
512
    t::lib::Mocks::mock_preference('FailedLoginAttempts', 3);
513
    my $patron = $builder->build_object({ class => 'Koha::Patrons' });
514
    $patron->set_password({ password => '123', skip_validation => 1 });
515
516
    my @test = checkpw( $dbh, $patron->userid, '123', undef, 'opac', 1 );
517
    is( $test[0], 1, 'Patron authenticated correctly' );
518
519
    $patron->password_expiration_date('2020-01-01')->store;
520
    @test = checkpw( $dbh, $patron->userid, '123', undef, 'opac', 1 );
521
    is( $test[0], -2, 'Patron returned as expired correctly' );
522
523
};
524
509
subtest '_timeout_syspref' => sub {
525
subtest '_timeout_syspref' => sub {
510
    plan tests => 5;
526
    plan tests => 5;
511
527
(-)a/t/db_dependent/ILSDI_Services.t (-2 / +8 lines)
Lines 42-48 my $builder = t::lib::TestBuilder->new; Link Here
42
42
43
subtest 'AuthenticatePatron test' => sub {
43
subtest 'AuthenticatePatron test' => sub {
44
44
45
    plan tests => 16;
45
    plan tests => 18;
46
46
47
    $schema->storage->txn_begin;
47
    $schema->storage->txn_begin;
48
48
Lines 111-116 subtest 'AuthenticatePatron test' => sub { Link Here
111
    is( $reply->{code}, 'PatronNotFound', "non-existing cardnumer/userid - PatronNotFound" );
111
    is( $reply->{code}, 'PatronNotFound', "non-existing cardnumer/userid - PatronNotFound" );
112
    is( $reply->{id}, undef, "id undef");
112
    is( $reply->{id}, undef, "id undef");
113
113
114
    $query->param( 'username', $borrower->{userid} );
115
    $query->param( 'password', $plain_password );
116
    $seen_patron->password_expiration_date('2020-01-01')->store;
117
    $reply = C4::ILSDI::Services::AuthenticatePatron($query);
118
    is( $reply->{code}, 'PasswordExpired', "correct credentials, expired password not authenticated" );
119
    is( $reply->{id}, undef, "id undef");
120
114
    $schema->storage->txn_rollback;
121
    $schema->storage->txn_rollback;
115
};
122
};
116
123
117
- 

Return to bug 29924