use Koha;
use Koha::Caches;
use Koha::AuthUtils qw(get_script_name hash_password);
+use Koha::Library::Groups;
use Koha::Libraries;
-use Koha::LibraryCategories;
use Koha::Patrons;
use POSIX qw/strftime/;
use List::MoreUtils qw/ any /;
C4::Context->interface( $in->{type} );
- my $safe_chars = 'a-zA-Z0-9_\-\/';
- die "bad template path" unless $in->{'template_name'} =~ m/^[$safe_chars]+\.tt$/ig; #sanitize input
-
$in->{'authnotrequired'} ||= 0;
+
+ # the following call includes a bad template check; might croak
my $template = C4::Templates::gettemplate(
$in->{'template_name'},
$in->{'type'},
$in->{'query'},
- $in->{'is_plugin'}
);
if ( $in->{'template_name'} !~ m/maintenance/ ) {
}
- # If the user logged in is the SCO user and he tries to go out the SCO module, log the user out removing the CGISESSID cookie
+ # 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
if ( $in->{type} eq 'opac' and $in->{template_name} !~ m|sco/| ) {
- if ( C4::Context->preference('AutoSelfCheckID') && $user eq C4::Context->preference('AutoSelfCheckID') ) {
+ if ( $user && C4::Context->preference('AutoSelfCheckID') && $user eq C4::Context->preference('AutoSelfCheckID') ) {
$template = C4::Templates::gettemplate( 'opac-auth.tt', 'opac', $in->{query} );
my $cookie = $in->{query}->cookie(
-name => 'CGISESSID',
my $borrowernumber;
if ($user) {
- require C4::Members;
# It's possible for $user to be the borrowernumber if they don't have a
# userid defined (and are logging in through some other method, such
# as SSL certs against an email address)
- my $borrower;
+ my $patron;
$borrowernumber = getborrowernumber($user) if defined($user);
if ( !defined($borrowernumber) && defined($user) ) {
- $borrower = C4::Members::GetMember( borrowernumber => $user );
- if ($borrower) {
+ $patron = Koha::Patrons->find( $user );
+ if ($patron) {
$borrowernumber = $user;
# A bit of a hack, but I don't know there's a nicer way
# to do it.
- $user = $borrower->{firstname} . ' ' . $borrower->{surname};
+ $user = $patron->firstname . ' ' . $patron->surname;
}
} else {
- $borrower = C4::Members::GetMember( borrowernumber => $borrowernumber );
+ $patron = Koha::Patrons->find( $borrowernumber );
+ # FIXME What to do if $patron does not exist?
}
# user info
- $template->param( loggedinusername => $user );
- $template->param( loggedinusernumber => $borrowernumber );
+ $template->param( loggedinusername => $user ); # FIXME Should be replaced with something like patron-title.inc
+ $template->param( loggedinusernumber => $borrowernumber ); # FIXME Should be replaced with logged_in_user.borrowernumber
+ $template->param( logged_in_user => $patron );
$template->param( sessionID => $sessionID );
if ( $in->{'type'} eq 'opac' ) {
);
}
- $template->param( "USER_INFO" => $borrower );
+ $template->param( "USER_INFO" => $patron->unblessed ) if $borrowernumber != 0;
my $all_perms = get_all_subpermissions();
my @flagroots = qw(circulate catalogue parameters borrowers permissions reserveforothers borrow
- editcatalogue updatecharges management tools editauthorities serials reports acquisition);
+ editcatalogue updatecharges management tools editauthorities serials reports acquisition clubs);
# We are going to use the $flags returned by checkauth
# to create the template's parameters that will indicate
$template->param( CAN_user_staffaccess => 1 );
$template->param( CAN_user_plugins => 1 );
$template->param( CAN_user_coursereserves => 1 );
- foreach my $module ( keys %$all_perms ) {
+ $template->param( CAN_user_clubs => 1 );
+ foreach my $module ( keys %$all_perms ) {
foreach my $subperm ( keys %{ $all_perms->{$module} } ) {
$template->param( "CAN_user_${module}_${subperm}" => 1 );
}
# We show the link in opac
$template->param( EnableOpacSearchHistory => 1 );
}
+ if (C4::Context->preference('LoadSearchHistoryToTheFirstLoggedUser'))
+ {
+ # And if there are searches performed when the user was not logged in,
+ # we add them to the logged-in search history
+ my @recentSearches = C4::Search::History::get_from_session( { cgi => $in->{'query'} } );
+ if (@recentSearches) {
+ my $dbh = C4::Context->dbh;
+ my $query = q{
+ INSERT INTO search_history(userid, sessionid, query_desc, query_cgi, type, total, time )
+ VALUES (?, ?, ?, ?, ?, ?, ?)
+ };
+ my $sth = $dbh->prepare($query);
+ $sth->execute( $borrowernumber,
+ $in->{query}->cookie("CGISESSID"),
+ $_->{query_desc},
+ $_->{query_cgi},
+ $_->{type} || 'biblio',
+ $_->{total},
+ $_->{time},
+ ) foreach @recentSearches;
+
+ # clear out the search history from the session now that
+ # we've saved it to the database
+ }
+ }
+ C4::Search::History::set_to_session( { cgi => $in->{'query'}, search_history => [] } );
- # And if there are searches performed when the user was not logged in,
- # we add them to the logged-in search history
- my @recentSearches = C4::Search::History::get_from_session( { cgi => $in->{'query'} } );
- if (@recentSearches) {
- my $dbh = C4::Context->dbh;
- my $query = q{
- INSERT INTO search_history(userid, sessionid, query_desc, query_cgi, type, total, time )
- VALUES (?, ?, ?, ?, ?, ?, ?)
- };
-
- my $sth = $dbh->prepare($query);
- $sth->execute( $borrowernumber,
- $in->{query}->cookie("CGISESSID"),
- $_->{query_desc},
- $_->{query_cgi},
- $_->{type} || 'biblio',
- $_->{total},
- $_->{time},
- ) foreach @recentSearches;
-
- # clear out the search history from the session now that
- # we've saved it to the database
- C4::Search::History::set_to_session( { cgi => $in->{'query'}, search_history => [] } );
- }
} elsif ( $in->{type} eq 'intranet' and C4::Context->preference('EnableSearchHistory') ) {
$template->param( EnableSearchHistory => 1 );
}
my $https = $in->{query}->https();
my $using_https = ( defined $https and $https ne 'OFF' ) ? 1 : 0;
+ my $minPasswordLength = C4::Context->preference('minPasswordLength');
+ $minPasswordLength = 3 if not $minPasswordLength or $minPasswordLength < 3;
$template->param(
"BiblioDefaultView" . C4::Context->preference("BiblioDefaultView") => 1,
EnhancedMessagingPreferences => C4::Context->preference('EnhancedMessagingPreferences'),
noItemTypeImages => C4::Context->preference("noItemTypeImages"),
marcflavour => C4::Context->preference("marcflavour"),
OPACBaseURL => C4::Context->preference('OPACBaseURL'),
+ minPasswordLength => $minPasswordLength,
);
if ( $in->{'type'} eq "intranet" ) {
$template->param(
UseKohaPlugins => C4::Context->preference('UseKohaPlugins'),
UseCourseReserves => C4::Context->preference("UseCourseReserves"),
useDischarge => C4::Context->preference('useDischarge'),
+ KOHA_VERSION => C4::Context->preference('Version'),
);
}
else {
$opac_name = C4::Context->userenv->{'branch'};
}
- my $library_categories = Koha::LibraryCategories->search({categorytype => 'searchdomain', show_in_pulldown => 1}, { order_by => ['categorytype', 'categorycode']});
+ my @search_groups = Koha::Library::Groups->get_search_groups({ interface => 'opac' });
$template->param(
OpacAdditionalStylesheet => C4::Context->preference("OpacAdditionalStylesheet"),
AnonSuggestions => "" . C4::Context->preference("AnonSuggestions"),
- BranchCategoriesLoop => $library_categories,
+ LibrarySearchGroups => \@search_groups,
opac_name => $opac_name,
LibraryName => "" . C4::Context->preference("LibraryName"),
LibraryNameTitle => "" . $LibraryNameTitle,
OpacTopissue => C4::Context->preference("OpacTopissue"),
RequestOnOpac => C4::Context->preference("RequestOnOpac"),
'Version' => C4::Context->preference('Version'),
+ KOHA_VERSION => C4::Context->preference('Version'),
hidelostitems => C4::Context->preference("hidelostitems"),
mylibraryfirst => ( C4::Context->preference("SearchMyLibraryFirst") && C4::Context->userenv ) ? C4::Context->userenv->{'branch'} : '',
opaclayoutstylesheet => "" . C4::Context->preference("opaclayoutstylesheet"),
my $authnotrequired = shift;
my $flagsrequired = shift;
my $type = shift;
+ my $emailaddress = shift;
$type = 'opac' unless $type;
my $dbh = C4::Context->dbh;
);
$loggedin = 1;
}
+ elsif ( $emailaddress) {
+ # the Google OpenID Connect passes an email address
+ }
elsif ( $sessionID = $query->cookie("CGISESSID") )
{ # assignment, not comparison
my $session = get_session($sessionID);
-value => $session->id,
-HttpOnly => 1
);
- $userid = $q_userid;
my $pki_field = C4::Context->preference('AllowPKIAuth');
if ( !defined($pki_field) ) {
print STDERR "ERROR: Missing system preference AllowPKIAuth.\n";
$pki_field = 'None';
}
if ( ( $cas && $query->param('ticket') )
- || $userid
+ || $q_userid
|| ( $shib && $shib_login )
- || $pki_field ne 'None' )
+ || $pki_field ne 'None'
+ || $emailaddress )
{
my $password = $query->param('password');
my $shibSuccess = 0;
my $retuserid;
# Do not pass password here, else shib will not be checked in checkpw.
- ( $return, $cardnumber, $retuserid ) = checkpw( $dbh, $userid, undef, $query );
+ ( $return, $cardnumber, $retuserid ) = checkpw( $dbh, $q_userid, undef, $query );
$userid = $retuserid;
$shibSuccess = $return;
$info{'invalidShibLogin'} = 1 unless ($return);
$info{'invalidCasLogin'} = 1 unless ($return);
}
+ elsif ( $emailaddress ) {
+ my $value = $emailaddress;
+
+ # If we're looking up the email, there's a chance that the person
+ # doesn't have a userid. So if there is none, we pass along the
+ # borrower number, and the bits of code that need to know the user
+ # ID will have to be smart enough to handle that.
+ my $patrons = Koha::Patrons->search({ email => $value });
+ if ($patrons->count) {
+
+ # First the userid, then the borrowernum
+ my $patron = $patrons->next;
+ $value = $patron->userid || $patron->borrowernumber;
+ } else {
+ undef $value;
+ }
+ $return = $value ? 1 : 0;
+ $userid = $value;
+ }
+
elsif (
( $pki_field eq 'Common Name' && $ENV{'SSL_CLIENT_S_DN_CN'} )
|| ( $pki_field eq 'emailAddress'
# doesn't have a userid. So if there is none, we pass along the
# borrower number, and the bits of code that need to know the user
# ID will have to be smart enough to handle that.
- require C4::Members;
- my @users_info = C4::Members::GetBorrowersWithEmail($value);
- if (@users_info) {
+ my $patrons = Koha::Patrons->search({ email => $value });
+ if ($patrons->count) {
# First the userid, then the borrowernum
- $value = $users_info[0][1] || $users_info[0][0];
+ my $patron = $patrons->next;
+ $value = $patron->userid || $patron->borrowernumber;
} else {
undef $value;
}
else {
my $retuserid;
( $return, $cardnumber, $retuserid ) =
- checkpw( $dbh, $userid, $password, $query, $type );
+ checkpw( $dbh, $q_userid, $password, $query, $type );
$userid = $retuserid if ($retuserid);
$info{'invalid_username_or_password'} = 1 unless ($return);
}
# $return: 1 = valid user, 2 = superlibrarian
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( 'ip', $session->remote_addr() );
$session->param( 'sessiontype', 'anon' );
}
- } # END if ( $userid = $query->param('userid') )
+ } # END if ( $q_userid
elsif ( $type eq "opac" ) {
# if we are here this is an anonymous session; add public lists to it and a few other items...
push @inputs, { name => $name, value => $value };
}
+ my $patron = Koha::Patrons->find({ userid => $q_userid }); # Not necessary logged in!
+
my $LibraryNameTitle = C4::Context->preference("LibraryName");
$LibraryNameTitle =~ s/<(?:\/?)(?:br|p)\s*(?:\/?)>/ /sgi;
$LibraryNameTitle =~ s/<(?:[^<>'"]|'(?:[^']*)'|"(?:[^"]*)")*>//sg;
PatronSelfRegistration => C4::Context->preference("PatronSelfRegistration"),
PatronSelfRegistrationDefaultCategory => C4::Context->preference("PatronSelfRegistrationDefaultCategory"),
opac_css_override => $ENV{'OPAC_CSS_OVERRIDE'},
+ too_many_login_attempts => ( $patron and $patron->account_locked ),
+ KOHA_VERSION => C4::Context->preference('Version'),
);
$template->param( SCO_login => 1 ) if ( $query->param('sco_user_login') );
sub checkpw {
my ( $dbh, $userid, $password, $query, $type, $no_set_userenv ) = @_;
$type = 'opac' unless $type;
- if ($ldap) {
+
+ my @return;
+ my $patron = Koha::Patrons->find({ userid => $userid });
+ my $check_internal_as_fallback = 0;
+ my $passwd_ok = 0;
+ # Note: checkpw_* routines returns:
+ # 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
+ } elsif ($ldap) {
$debug and print STDERR "## checkpw - checking LDAP\n";
my ( $retval, $retcard, $retuserid ) = checkpw_ldap(@_); # EXTERNAL AUTH
- return 0 if $retval == -1; # Incorrect password for LDAP login attempt
- ($retval) and return ( $retval, $retcard, $retuserid );
- }
+ if ( $retval == 1 ) {
+ @return = ( $retval, $retcard, $retuserid );
+ $passwd_ok = 1;
+ }
+ $check_internal_as_fallback = 1 if $retval == 0;
- if ( $cas && $query && $query->param('ticket') ) {
+ } elsif ( $cas && $query && $query->param('ticket') ) {
$debug and print STDERR "## checkpw - checking CAS\n";
# In case of a CAS authentication, we use the ticket instead of the password
my $ticket = $query->param('ticket');
$query->delete('ticket'); # remove ticket to come back to original URL
my ( $retval, $retcard, $retuserid ) = checkpw_cas( $dbh, $ticket, $query, $type ); # EXTERNAL AUTH
- ($retval) and return ( $retval, $retcard, $retuserid );
- return 0;
+ if ( $retval ) {
+ @return = ( $retval, $retcard, $retuserid );
+ }
+ $passwd_ok = $retval;
}
# If we are in a shibboleth session (shibboleth is enabled, and a shibboleth match attribute is present)
# Check for password to asertain whether we want to be testing against shibboleth or another method this
# time around.
- if ( $shib && $shib_login && !$password ) {
+ elsif ( $shib && $shib_login && !$password ) {
$debug and print STDERR "## checkpw - checking Shibboleth\n";
# Then, we check if it matches a valid koha user
if ($shib_login) {
my ( $retval, $retcard, $retuserid ) = C4::Auth_with_shibboleth::checkpw_shib($shib_login); # EXTERNAL AUTH
- ($retval) and return ( $retval, $retcard, $retuserid );
- return 0;
+ if ( $retval ) {
+ @return = ( $retval, $retcard, $retuserid );
+ }
+ $passwd_ok = $retval;
}
+ } else {
+ $check_internal_as_fallback = 1;
}
# INTERNAL AUTH
- return checkpw_internal( $dbh, $userid, $password, $no_set_userenv);
+ if ( $check_internal_as_fallback ) {
+ @return = checkpw_internal( $dbh, $userid, $password, $no_set_userenv);
+ $passwd_ok = 1 if $return[0] > 0; # 1 or 2
+ }
+
+ if( $patron ) {
+ if ( $passwd_ok ) {
+ $patron->update({ login_attempts => 0 });
+ } else {
+ $patron->update({ login_attempts => $patron->login_attempts + 1 });
+ }
+ }
+ return @return;
}
sub checkpw_internal {
return 1, $cardnumber, $userid;
}
}
- if ( $userid && $userid eq 'demo'
- && "$password" eq 'demo'
- && C4::Context->config('demo') )
- {
-
- # DEMO => the demo user is allowed to do everything (if demo set to 1 in koha.conf
- # some features won't be effective : modify systempref, modify MARC structure,
- return 2;
- }
return 0;
}
# Super User Account from /etc/koha.conf
$flags->{'superlibrarian'} = 1;
}
- elsif ( $userid eq 'demo' && C4::Context->config('demo') ) {
-
- # Demo user that can do "anything" (demo=1 in /etc/koha.conf)
- $flags->{'superlibrarian'} = 1;
- }
return $flags if $flags->{superlibrarian};