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

(-)a/C4/Auth.pm (-31 / +3 lines)
Lines 74-80 BEGIN { Link Here
74
74
75
    @EXPORT_OK = qw(
75
    @EXPORT_OK = qw(
76
        checkauth check_api_auth get_session check_cookie_auth checkpw checkpw_internal checkpw_hash
76
        checkauth check_api_auth get_session check_cookie_auth checkpw checkpw_internal checkpw_hash
77
        get_all_subpermissions get_cataloguing_page_permissions get_user_subpermissions track_login_daily in_iprange
77
        get_all_subpermissions get_cataloguing_page_permissions get_user_subpermissions in_iprange
78
        get_template_and_user haspermission create_basic_session
78
        get_template_and_user haspermission create_basic_session
79
    );
79
    );
80
80
Lines 1319-1325 sub checkauth { Link Here
1319
            ));
1319
            ));
1320
        }
1320
        }
1321
1321
1322
        track_login_daily( $userid, 'login' );
1322
        my $patron = Koha::Patrons->find({ userid => $userid });
1323
        $patron->update_lastseen('login');
1323
1324
1324
        # In case, that this request was a login attempt, we want to prevent that users can repost the opac login
1325
        # In case, that this request was a login attempt, we want to prevent that users can repost the opac login
1325
        # request. We therefore redirect the user to the requested page again without the login parameters.
1326
        # request. We therefore redirect the user to the requested page again without the login parameters.
Lines 2345-2379 sub getborrowernumber { Link Here
2345
    return 0;
2346
    return 0;
2346
}
2347
}
2347
2348
2348
=head2 track_login_daily
2349
2350
    track_login_daily( $userid );
2351
2352
Wraps the call to $patron->track_login, the method used to update borrowers.lastseen. We only call track_login once a day.
2353
2354
=cut
2355
2356
sub track_login_daily {
2357
    my $userid = shift;
2358
    my $activity = shift;
2359
    return if !$userid || !$activity || !C4::Context->preference('TrackLastPatronActivity');
2360
2361
    my $cache     = Koha::Caches->get_instance();
2362
    my $cache_key = "track_login_" . $userid;
2363
    my $cached    = $cache->get_from_cache($cache_key);
2364
    my $today = dt_from_string()->ymd;
2365
    return if $cached && $cached eq $today;
2366
2367
    my $patron = Koha::Patrons->find({ userid => $userid });
2368
    return unless $patron;
2369
2370
    my $tracked_activities = { map { (lc $_, 1); } split /\s*\,\s*/, C4::Context->preference('TrackLastPatronActivityTriggers') };
2371
    return unless $tracked_activities->{$activity};
2372
2373
    $patron->track_login;
2374
    $cache->set_in_cache( $cache_key, $today );
2375
}
2376
2377
END { }    # module clean-up code here (global destructor)
2349
END { }    # module clean-up code here (global destructor)
2378
1;
2350
1;
2379
__END__
2351
__END__
(-)a/C4/Circulation.pm (-3 / +3 lines)
Lines 1677-1683 sub AddIssue { Link Here
1677
                )->store;
1677
                )->store;
1678
            }
1678
            }
1679
            $issue->discard_changes;
1679
            $issue->discard_changes;
1680
            C4::Auth::track_login_daily( $patron->userid, 'check_out' );
1680
            $patron->update_lastseen('check_out');
1681
            if ( $item_object->location && $item_object->location eq 'CART'
1681
            if ( $item_object->location && $item_object->location eq 'CART'
1682
                && ( !$item_object->permanent_location || $item_object->permanent_location ne 'CART' ) ) {
1682
                && ( !$item_object->permanent_location || $item_object->permanent_location ne 'CART' ) ) {
1683
            ## Item was moved to cart via UpdateItemLocationOnCheckin, anything issued should be taken off the cart.
1683
            ## Item was moved to cart via UpdateItemLocationOnCheckin, anything issued should be taken off the cart.
Lines 2496-2502 sub AddReturn { Link Here
2496
            if C4::Context->preference("ReturnLog");
2496
            if C4::Context->preference("ReturnLog");
2497
2497
2498
        #Update borrowers.lastseen
2498
        #Update borrowers.lastseen
2499
        C4::Auth::track_login_daily( $patron->userid, 'check_in' );
2499
        $patron->update_lastseen('check_in');
2500
    }
2500
    }
2501
2501
2502
    # Check if this item belongs to a biblio record that is attached to an
2502
    # Check if this item belongs to a biblio record that is attached to an
Lines 3347-3353 sub AddRenewal { Link Here
3347
            }
3347
            }
3348
        );
3348
        );
3349
        #Update borrowers.lastseen
3349
        #Update borrowers.lastseen
3350
        C4::Auth::track_login_daily( $patron_unblessed->{userid}, 'renewal' );
3350
        $patron->update_lastseen('renewal');
3351
3351
3352
        #Log the renewal
3352
        #Log the renewal
3353
        logaction("CIRCULATION", "RENEWAL", $borrowernumber, $itemnumber) if C4::Context->preference("RenewalLog");
3353
        logaction("CIRCULATION", "RENEWAL", $borrowernumber, $itemnumber) if C4::Context->preference("RenewalLog");
(-)a/C4/ILSDI/Services.pm (-2 / +2 lines)
Lines 396-405 sub AuthenticatePatron { Link Here
396
    my $password = $cgi->param('password');
396
    my $password = $cgi->param('password');
397
    my ($status, $cardnumber, $userid) = C4::Auth::checkpw( $username, $password );
397
    my ($status, $cardnumber, $userid) = C4::Auth::checkpw( $username, $password );
398
    if ( $status == 1 ) {
398
    if ( $status == 1 ) {
399
        # Track the login
400
        C4::Auth::track_login_daily( $userid, 'connection' );
401
        # Get the borrower
399
        # Get the borrower
402
        my $patron = Koha::Patrons->find( { userid => $userid } );
400
        my $patron = Koha::Patrons->find( { userid => $userid } );
401
        # Track the login
402
        $patron->update_lastseen('connection');
403
        return { id => $patron->borrowernumber };
403
        return { id => $patron->borrowernumber };
404
    }
404
    }
405
    elsif ( $status == -2 ){
405
    elsif ( $status == -2 ){
(-)a/C4/SIP/Sip/MsgType.pm (-1 / +5 lines)
Lines 16-21 use C4::SIP::Sip::Checksum qw(verify_cksum); Link Here
16
16
17
use Data::Dumper;
17
use Data::Dumper;
18
use CGI qw ( -utf8 );
18
use CGI qw ( -utf8 );
19
use C4::Context;
19
use C4::Auth qw(&check_api_auth);
20
use C4::Auth qw(&check_api_auth);
20
use C4::Items qw(ModDateLastSeen);
21
use C4::Items qw(ModDateLastSeen);
21
22
Lines 995-1001 sub handle_patron_info { Link Here
995
996
996
    $resp = (PATRON_INFO_RESP);
997
    $resp = (PATRON_INFO_RESP);
997
    if ($patron) {
998
    if ($patron) {
998
        C4::Auth::track_login_daily( $patron->userid, 'connection' );
999
        if ( C4::Context->preference('TrackLastPatronActivity') ) {
1000
            my $koha_patron = Koha::Patrons->find($patron->userid);
1001
            $koha_patron->update_lastseen('connection');
1002
        }
999
        $resp .= patron_status_string( $patron, $server );
1003
        $resp .= patron_status_string( $patron, $server );
1000
        $resp .= ( defined($lang) and length($lang) == 3 ) ? $lang : $patron->language;
1004
        $resp .= ( defined($lang) and length($lang) == 3 ) ? $lang : $patron->language;
1001
        $resp .= timestamp();
1005
        $resp .= timestamp();
(-)a/Koha/Patron.pm (-14 / +24 lines)
Lines 33-38 use C4::Log qw( logaction ); Link Here
33
use Koha::Account;
33
use Koha::Account;
34
use Koha::ArticleRequests;
34
use Koha::ArticleRequests;
35
use Koha::AuthUtils;
35
use Koha::AuthUtils;
36
use Koha::Caches;
36
use Koha::Checkouts;
37
use Koha::Checkouts;
37
use Koha::CirculationRules;
38
use Koha::CirculationRules;
38
use Koha::Club::Enrollments;
39
use Koha::Club::Enrollments;
Lines 1165-1188 sub _get_overdue_debarred_delay { Link Here
1165
    }
1166
    }
1166
}
1167
}
1167
1168
1169
=head3 update_lastseen
1168
1170
1169
=head3 track_login
1171
  $patron->update_lastseen('activity');
1170
1172
1171
    $patron->track_login;
1173
Tracks a (successful) login attempt when the TrackLastPatronActivity preference is enabled
1172
    $patron->track_login({ force => 1 });
1174
and the activity passed is in the TrackLastPatronActivityTriggers list.
1173
1174
    Tracks a (successful) login attempt.
1175
    The preference TrackLastPatronActivity must be enabled. Or you
1176
    should pass the force parameter.
1177
1175
1178
=cut
1176
=cut
1179
1177
1180
sub track_login {
1178
sub update_lastseen {
1181
    my ( $self, $params ) = @_;
1179
    my ( $self, $activity ) = @_;
1182
    return if
1180
    return $self if !C4::Context->preference('TrackLastPatronActivity');
1183
        !$params->{force} &&
1181
1184
        !C4::Context->preference('TrackLastPatronActivity');
1182
    my $tracked_activities = {
1185
    $self->lastseen( dt_from_string() )->store;
1183
        map { ( lc $_, 1 ); } split /\s*\,\s*/,
1184
        C4::Context->preference('TrackLastPatronActivityTriggers')
1185
    };
1186
    return $self unless $tracked_activities->{$activity};
1187
1188
    my $cache     = Koha::Caches->get_instance();
1189
    my $cache_key = "track_login_" . $self->userid;
1190
    my $cached    = $cache->get_from_cache($cache_key);
1191
    my $now       = dt_from_string();
1192
    return if $cached && $cached eq $now->ymd;
1193
1194
    $self->lastseen($now)->store;
1195
    $cache->set_in_cache( $cache_key, $now->ymd );
1196
    return $self;
1186
}
1197
}
1187
1198
1188
=head3 move_to_deleted
1199
=head3 move_to_deleted
1189
- 

Return to bug 15504