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
my $borrower;
$borrowernumber = getborrowernumber($user) if defined($user);
if ( !defined($borrowernumber) && defined($user) ) {
- $borrower = C4::Members::GetMember( borrowernumber => $user );
+ $borrower = Koha::Patrons->find( $user );
if ($borrower) {
+ $borrower = $borrower->unblessed;
$borrowernumber = $user;
# A bit of a hack, but I don't know there's a nicer way
$user = $borrower->{firstname} . ' ' . $borrower->{surname};
}
} else {
- $borrower = C4::Members::GetMember( borrowernumber => $borrowernumber );
+ $borrower = Koha::Patrons->find( $borrowernumber );
+ $borrower->unblessed if $borrower; # FIXME Otherwise, what to do?
}
# user info
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 );
}
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(
# 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;
}
# 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;
}
# $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 ) ) {
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 ),
);
$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 {