]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/examples/remoteauth.cgi
Merge branch 'browser'
[Evergreen.git] / Open-ILS / examples / remoteauth.cgi
1 #!/usr/bin/perl
2 #use strict;
3 use warnings;
4
5 use CGI;
6 use Digest::MD5 qw(md5_hex);
7
8 use OpenSRF::EX qw(:try);
9 use OpenSRF::System;
10
11
12 my $bootstrap = '/openils/conf/opensrf_core.xml';
13 my $cgi = new CGI;
14 my $u = $cgi->param('user');
15 my $p = $cgi->param('passwd');
16
17 print $cgi->header(-type=>'text/html', -expires=>'-1d');
18
19 OpenSRF::System->bootstrap_client( config_file => $bootstrap );
20
21 if (!$u || !$p) {
22         print "+INCOMPLETE";
23 } else {
24         my $nametype = 'username';
25         $nametype = 'barcode' if ($u =~ /^\d+$/o);
26         my $seed = OpenSRF::AppSession
27                 ->create("open-ils.auth")
28                 ->request( 'open-ils.auth.authenticate.init', $u )
29                 ->gather(1);
30         if ($seed) {
31                 my $response = OpenSRF::AppSession
32                         ->create("open-ils.auth")
33                         ->request( 'open-ils.auth.authenticate.complete', { $nametype => $u, password => md5_hex($seed . md5_hex($p)), type => 'temp' })
34                         ->gather(1);
35                 if ($response->{payload}->{authtoken}) {
36                         my $user = OpenSRF::AppSession
37                                 ->create("open-ils.auth")
38                                 ->request( "open-ils.auth.session.retrieve", $response->{payload}->{authtoken} )
39                                 ->gather(1);
40                         if (ref($user) eq 'HASH' && $user->{ilsevent} == 1001) {
41                                 print "+NO";
42                         } else {
43                                 print "+VALID";
44                         }
45                 } else {
46                         print "+NO";
47                 }
48         } else {
49                 print "+BACKEND_ERROR";
50         }
51
52 }
53
54 1;