use DateTime;
use DateTime::Format::ISO8601;
use OpenSRF::Utils qw/:datetime/;
+use OpenSRF::Utils::Logger qw/$logger/;
use OpenSRF::System;
use OpenSRF::AppSession;
my $bootstrap = '/openils/conf/opensrf_core.xml';
my $cgi = new CGI;
my $u = $cgi->param('user');
-my $usrname = $cgi->param('usrname');
-my $barcode = $cgi->param('barcode');
+my $usrname = $cgi->param('usrname') || '';
+my $barcode = $cgi->param('barcode') || '';
my $agent = $cgi->param('agent'); # optional, but preferred
my $p = $cgi->param('passwd');
$user = $e->search_actor_user({usrname => $u})->[0];
}
- if ($user
- and $user->deleted eq 'f'
- and $user->active eq 't'
- and $user->passwd eq md5_hex($p)) {
+ my $logtag = $barcode ? "barcode=$barcode" : "username=$usrname";
- my $expire =
- DateTime::Format::ISO8601->new->parse_datetime(
- cleanse_ISO8601($user->expire_date));
+ if (!$user) {
+ $logger->warn("remoteauth: no such user $logtag");
+ print '+NO';
+ exit 0;
+ }
- if ($expire < DateTime->now) {
- print '+NO';
+ $logtag .= " id=".$user->id." profile=".$user->profile;
+
+ if ($user->deleted eq 't') {
+ $logger->warn("remoteauth: user is deleted $logtag");
+ print '+NO';
+ exit 0;
+ }
- } else {
+ if ($user->active eq 'f') {
+ $logger->warn("remoteauth: user is not active $logtag");
+ print '+NO';
+ exit 0;
+ }
- $e->requestor($user);
- if ($e->allowed('ACCESS_EBOOKS_AND_DATABASES', $user->home_ou)) {
+ if ($user->passwd ne md5_hex($p)) {
+ $logger->warn("remoteauth: bad password for $logtag");
+ print '+NO';
+ exit 0;
+ }
- OpenILS::Application::AppUtils
- ->log_user_activity($user->id, $agent, 'verify');
+ my $expire =
+ DateTime::Format::ISO8601->new->parse_datetime(
+ cleanse_ISO8601($user->expire_date));
- print '+VALID';
+ if ($expire < DateTime->now) {
+ $logger->warn("remoteauth: patron account is expired $logtag");
+ print '+NO';
+ exit 0;
+ }
- } else {
- print '+NO';
- }
- }
- } else {
+ $e->requestor($user);
+ if (!$e->allowed('ACCESS_EBOOKS_AND_DATABASES', $user->home_ou)) {
+ $logger->warn("remoteauth: patron does not have permission $logtag");
print '+NO';
+ exit 0;
}
+
+ $logger->info("remoteauth: successful authentication for $logtag");
+
+ OpenILS::Application::AppUtils
+ ->log_user_activity($user->id, $agent, 'verify');
+
+ print '+VALID';
}
1;