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

(-)a/C4/Auth.pm (-31 / +3 lines)
Lines 73-79 BEGIN { Link Here
73
73
74
    @EXPORT_OK = qw(
74
    @EXPORT_OK = qw(
75
      checkauth check_api_auth get_session check_cookie_auth checkpw checkpw_internal checkpw_hash
75
      checkauth check_api_auth get_session check_cookie_auth checkpw checkpw_internal checkpw_hash
76
      get_all_subpermissions get_user_subpermissions track_login_daily in_iprange
76
      get_all_subpermissions get_user_subpermissions in_iprange
77
      get_template_and_user haspermission create_basic_session
77
      get_template_and_user haspermission create_basic_session
78
    );
78
    );
79
79
Lines 1306-1312 sub checkauth { Link Here
1306
            ));
1306
            ));
1307
        }
1307
        }
1308
1308
1309
        track_login_daily( $userid, 'login' );
1309
        my $patron = Koha::Patrons->find({ userid => $userid });
1310
        $patron->update_lastseen('login');
1310
1311
1311
        # In case, that this request was a login attempt, we want to prevent that users can repost the opac login
1312
        # In case, that this request was a login attempt, we want to prevent that users can repost the opac login
1312
        # request. We therefore redirect the user to the requested page again without the login parameters.
1313
        # request. We therefore redirect the user to the requested page again without the login parameters.
Lines 2297-2331 sub getborrowernumber { Link Here
2297
    return 0;
2298
    return 0;
2298
}
2299
}
2299
2300
2300
=head2 track_login_daily
2301
2302
    track_login_daily( $userid );
2303
2304
Wraps the call to $patron->track_login, the method used to update borrowers.lastseen. We only call track_login once a day.
2305
2306
=cut
2307
2308
sub track_login_daily {
2309
    my $userid = shift;
2310
    my $activity = shift;
2311
    return if !$userid || !$activity || !C4::Context->preference('TrackLastPatronActivity');
2312
2313
    my $cache     = Koha::Caches->get_instance();
2314
    my $cache_key = "track_login_" . $userid;
2315
    my $cached    = $cache->get_from_cache($cache_key);
2316
    my $today = dt_from_string()->ymd;
2317
    return if $cached && $cached eq $today;
2318
2319
    my $patron = Koha::Patrons->find({ userid => $userid });
2320
    return unless $patron;
2321
2322
    my $tracked_activities = { map { (lc $_, 1); } split /\s*\,\s*/, C4::Context->preference('TrackLastPatronActivityTriggers') };
2323
    return unless $tracked_activities->{$activity};
2324
2325
    $patron->track_login;
2326
    $cache->set_in_cache( $cache_key, $today );
2327
}
2328
2329
END { }    # module clean-up code here (global destructor)
2301
END { }    # module clean-up code here (global destructor)
2330
1;
2302
1;
2331
__END__
2303
__END__
(-)a/C4/Circulation.pm (-3 / +3 lines)
Lines 1676-1682 sub AddIssue { Link Here
1676
                )->store;
1676
                )->store;
1677
            }
1677
            }
1678
            $issue->discard_changes;
1678
            $issue->discard_changes;
1679
            C4::Auth::track_login_daily( $borrower->{userid}, 'check_out' );
1679
            $patron->update_lastseen('check_out');
1680
            if ( $item_object->location && $item_object->location eq 'CART'
1680
            if ( $item_object->location && $item_object->location eq 'CART'
1681
                && ( !$item_object->permanent_location || $item_object->permanent_location ne 'CART' ) ) {
1681
                && ( !$item_object->permanent_location || $item_object->permanent_location ne 'CART' ) ) {
1682
            ## Item was moved to cart via UpdateItemLocationOnCheckin, anything issued should be taken off the cart.
1682
            ## Item was moved to cart via UpdateItemLocationOnCheckin, anything issued should be taken off the cart.
Lines 2471-2477 sub AddReturn { Link Here
2471
            if C4::Context->preference("ReturnLog");
2471
            if C4::Context->preference("ReturnLog");
2472
2472
2473
        #Update borrowers.lastseen
2473
        #Update borrowers.lastseen
2474
        C4::Auth::track_login_daily( $patron->userid, 'check_in' );
2474
        $patron->update_lastseen('check_in');
2475
    }
2475
    }
2476
2476
2477
    # Check if this item belongs to a biblio record that is attached to an
2477
    # Check if this item belongs to a biblio record that is attached to an
Lines 3311-3317 sub AddRenewal { Link Here
3311
            }
3311
            }
3312
        );
3312
        );
3313
        #Update borrowers.lastseen
3313
        #Update borrowers.lastseen
3314
        C4::Auth::track_login_daily( $patron_unblessed->{userid}, 'renewal' );
3314
        $patron->update_lastseen('renewal');
3315
3315
3316
        #Log the renewal
3316
        #Log the renewal
3317
        logaction("CIRCULATION", "RENEWAL", $borrowernumber, $itemnumber) if C4::Context->preference("RenewalLog");
3317
        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 993-999 sub handle_patron_info { Link Here
993
994
994
    $resp = (PATRON_INFO_RESP);
995
    $resp = (PATRON_INFO_RESP);
995
    if ($patron) {
996
    if ($patron) {
996
        C4::Auth::track_login_daily( $patron->userid, 'connection' );
997
        if ( C4::Context->preference('TrackLastPatronActivity') ) {
998
            my $koha_patron = Koha::Patrons->find($patron->userid);
999
            $koha_patron->update_lastseen('connection');
1000
        }
997
        $resp .= patron_status_string( $patron, $server );
1001
        $resp .= patron_status_string( $patron, $server );
998
        $resp .= ( defined($lang) and length($lang) == 3 ) ? $lang : $patron->language;
1002
        $resp .= ( defined($lang) and length($lang) == 3 ) ? $lang : $patron->language;
999
        $resp .= timestamp();
1003
        $resp .= timestamp();
(-)a/Koha/Patron.pm (-13 / +24 lines)
Lines 32-37 use Koha::Account; Link Here
32
use Koha::ArticleRequests;
32
use Koha::ArticleRequests;
33
use C4::Letters qw( GetPreparedLetter EnqueueLetter SendQueuedMessages );
33
use C4::Letters qw( GetPreparedLetter EnqueueLetter SendQueuedMessages );
34
use Koha::AuthUtils;
34
use Koha::AuthUtils;
35
use Koha::Caches;
35
use Koha::Checkouts;
36
use Koha::Checkouts;
36
use Koha::CirculationRules;
37
use Koha::CirculationRules;
37
use Koha::Club::Enrollments;
38
use Koha::Club::Enrollments;
Lines 998-1021 sub has_overdues { Link Here
998
    return $self->_result->issues->search({ date_due => { '<' => $dtf->format_datetime( dt_from_string() ) } })->count;
999
    return $self->_result->issues->search({ date_due => { '<' => $dtf->format_datetime( dt_from_string() ) } })->count;
999
}
1000
}
1000
1001
1001
=head3 track_login
1002
=head3 update_lastseen
1002
1003
1003
    $patron->track_login;
1004
  $patron->update_lastseen('activity');
1004
    $patron->track_login({ force => 1 });
1005
1005
1006
    Tracks a (successful) login attempt.
1006
Tracks a (successful) login attempt when the TrackLastPatronActivity preference is enabled
1007
    The preference TrackLastPatronActivity must be enabled. Or you
1007
and the activity passed is in the TrackLastPatronActivityTriggers list.
1008
    should pass the force parameter.
1009
1008
1010
=cut
1009
=cut
1011
1010
1012
sub track_login {
1011
sub update_lastseen {
1013
    my ( $self, $params ) = @_;
1012
    my ( $self, $activity ) = @_;
1014
    return if
1013
    return $self if !C4::Context->preference('TrackLastPatronActivity');
1015
        !$params->{force} &&
1014
1016
        !C4::Context->preference('TrackLastPatronActivity');
1015
    my $tracked_activities = {
1016
        map { ( lc $_, 1 ); } split /\s*\,\s*/,
1017
        C4::Context->preference('TrackLastPatronActivityTriggers')
1018
    };
1019
    return $self unless $tracked_activities->{$activity};
1020
1021
    my $cache     = Koha::Caches->get_instance();
1022
    my $cache_key = "track_login_" . $self->userid;
1023
    my $cached    = $cache->get_from_cache($cache_key);
1024
    my $now       = dt_from_string();
1025
    return if $cached && $cached eq $now->ymd;
1026
1017
    $self->make_column_dirty('updated_on');
1027
    $self->make_column_dirty('updated_on');
1018
    $self->lastseen( dt_from_string() )->store;
1028
    $self->lastseen($now)->store;
1029
    $cache->set_in_cache( $cache_key, $now->ymd );
1030
    return $self;
1019
}
1031
}
1020
1032
1021
=head3 move_to_deleted
1033
=head3 move_to_deleted
1022
- 

Return to bug 15504