use Koha;
use Koha::Caches;
use Koha::AuthUtils qw(get_script_name hash_password);
+use Koha::DateUtils qw(dt_from_string);
use Koha::Library::Groups;
use Koha::Libraries;
use Koha::Patrons;
@ISA = qw(Exporter);
@EXPORT = qw(&checkauth &get_template_and_user &haspermission &get_user_subpermissions);
@EXPORT_OK = qw(&check_api_auth &get_session &check_cookie_auth &checkpw &checkpw_internal &checkpw_hash
- &get_all_subpermissions &get_user_subpermissions
+ &get_all_subpermissions &get_user_subpermissions track_login_daily
);
%EXPORT_TAGS = ( EditPermissions => [qw(get_all_subpermissions get_user_subpermissions)] );
$ldap = C4::Context->config('useldapserver') || 0;
);
}
- if ( $in->{type} eq 'opac' ) {
+ if ( $in->{type} eq 'opac' && $user ) {
my $kick_out;
if (
# If the user logged in is the SCO user and they try to go out of the SCO module,
# log the user out removing the CGISESSID cookie
$in->{template_name} !~ m|sco/|
- && $user
&& C4::Context->preference('AutoSelfCheckID')
&& $user eq C4::Context->preference('AutoSelfCheckID')
)
# kick them out unless it is SCO with a valid permission
# or they are a superlibrarian
$in->{template_name} !~ m|sci/|
- && $user
&& haspermission( $user, { self_check => 'self_checkin_module' } )
&& !(
$in->{template_name} =~ m|sco/| && haspermission(
$template->param( CAN_user_plugins => 1 );
$template->param( CAN_user_coursereserves => 1 );
$template->param( CAN_user_clubs => 1 );
+ $template->param( CAN_user_ill => 1 );
foreach my $module ( keys %$all_perms ) {
foreach my $subperm ( keys %{ $all_perms->{$module} } ) {
my $casparam = $query->param('cas');
my $q_userid = $query->param('userid') // '';
+ my $session;
+
# Basic authentication is incompatible with the use of Shibboleth,
# as Shibboleth may return REMOTE_USER as a Shibboleth attribute,
# and it may not be the attribute we want to use to match the koha login.
}
elsif ( $sessionID = $query->cookie("CGISESSID") )
{ # assignment, not comparison
- my $session = get_session($sessionID);
+ $session = get_session($sessionID);
C4::Context->_new_userenv($sessionID);
my ( $ip, $lasttime, $sessiontype );
my $s_userid = '';
}
}
- # $return: 1 = valid user, 2 = superlibrarian
+ # $return: 1 = valid user
if ($return) {
- # If DB user is logged in
- $userid ||= $q_userid if $return == 2;
#_session_log(sprintf "%20s from %16s logged in at %30s.\n", $userid,$ENV{'REMOTE_ADDR'},(strftime '%c', localtime));
if ( $flags = haspermission( $userid, $flagsrequired ) ) {
$session->param( 'shibboleth', $shibSuccess );
$debug and printf STDERR "AUTH_4: (%s)\t%s %s - %s\n", map { $session->param($_) } qw(cardnumber firstname surname branch);
}
- elsif ( $return == 2 ) {
-
- #We suppose the user is the superlibrarian
- $borrowernumber = 0;
- $session->param( 'number', 0 );
- $session->param( 'id', C4::Context->config('user') );
- $session->param( 'cardnumber', C4::Context->config('user') );
- $session->param( 'firstname', C4::Context->config('user') );
- $session->param( 'surname', C4::Context->config('user') );
- $session->param( 'branch', 'NO_LIBRARY_SET' );
- $session->param( 'branchname', 'NO_LIBRARY_SET' );
- $session->param( 'flags', 1 );
- $session->param( 'emailaddress', C4::Context->preference('KohaAdminEmailAddress') );
- $session->param( 'ip', $session->remote_addr() );
- $session->param( 'lasttime', time() );
- }
$session->param('cas_ticket', $cas_ticket) if $cas_ticket;
C4::Context->set_userenv(
$session->param('number'), $session->param('id'),
);
}
- if ( $userid ) {
- # track_login also depends on pref TrackLastPatronActivity
- my $patron = Koha::Patrons->find({ userid => $userid });
- $patron->track_login if $patron;
- }
+ track_login_daily( $userid );
return ( $userid, $cookie, $sessionID, $flags );
}
$session->param( 'emailaddress', $emailaddress );
$session->param( 'ip', $session->remote_addr() );
$session->param( 'lasttime', time() );
- } elsif ( $return == 2 ) {
-
- #We suppose the user is the superlibrarian
- $session->param( 'number', 0 );
- $session->param( 'id', C4::Context->config('user') );
- $session->param( 'cardnumber', C4::Context->config('user') );
- $session->param( 'firstname', C4::Context->config('user') );
- $session->param( 'surname', C4::Context->config('user') );
- $session->param( 'branch', 'NO_LIBRARY_SET' );
- $session->param( 'branchname', 'NO_LIBRARY_SET' );
- $session->param( 'flags', 1 );
- $session->param( 'emailaddress', C4::Context->preference('KohaAdminEmailAddress') );
- $session->param( 'ip', $session->remote_addr() );
- $session->param( 'lasttime', time() );
}
$session->param( 'cas_ticket', $cas_ticket);
C4::Context->set_userenv(
# 1 if auth is ok
# 0 if auth is nok
# -1 if user bind failed (LDAP only)
- # 2 if DB user is used (internal only)
if ( $patron and $patron->account_locked ) {
# Nothing to check, account is locked
$password = Encode::encode( 'UTF-8', $password )
if Encode::is_utf8($password);
- if ( $userid && $userid eq C4::Context->config('user') ) {
- if ( $password && $password eq C4::Context->config('pass') ) {
-
- # Koha superuser account
- # C4::Context->set_userenv(0,0,C4::Context->config('user'),C4::Context->config('user'),C4::Context->config('user'),"",1);
- return 2;
- }
- else {
- return 0;
- }
- }
-
my $sth =
$dbh->prepare(
"select password,cardnumber,borrowernumber,userid,firstname,surname,borrowers.branchcode,branches.branchname,flags from borrowers join branches on borrowers.branchcode=branches.branchcode where userid=?"
$sth->execute($userid);
my $row = $sth->fetchrow();
my $flags = getuserflags( $row, $userid );
- if ( $userid eq C4::Context->config('user') ) {
-
- # Super User Account from /etc/koha.conf
- $flags->{'superlibrarian'} = 1;
- }
return $flags if $flags->{superlibrarian};
return 0;
}
+=head2 track_login_daily
+
+ track_login_daily( $userid );
+
+Wraps the call to $patron->track_login, the method used to update borrowers.lastseen. We only call track_login once a day.
+
+=cut
+
+sub track_login_daily {
+ my $userid = shift;
+ return if !$userid || !C4::Context->preference('TrackLastPatronActivity');
+
+ my $cache = Koha::Caches->get_instance();
+ my $cache_key = "track_login_" . $userid;
+ my $cached = $cache->get_from_cache($cache_key);
+ my $today = dt_from_string()->ymd;
+ return if $cached && $cached eq $today;
+
+ my $patron = Koha::Patrons->find({ userid => $userid });
+ return unless $patron;
+ $patron->track_login;
+ $cache->set_in_cache( $cache_key, $today );
+}
+
END { } # module clean-up code here (global destructor)
1;
__END__