Line 0
Link Here
|
|
|
1 |
package Koha::Auth::Shim; |
2 |
|
3 |
# Copyright 2021 Koha Development team |
4 |
# |
5 |
# This file is part of Koha |
6 |
# |
7 |
# Koha is free software; you can redistribute it and/or modify it |
8 |
# under the terms of the GNU General Public License as published by |
9 |
# the Free Software Foundation; either version 3 of the License, or |
10 |
# (at your option) any later version. |
11 |
# |
12 |
# Koha is distributed in the hope that it will be useful, but |
13 |
# WITHOUT ANY WARRANTY; without even the implied warranty of |
14 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 |
# GNU General Public License for more details. |
16 |
# |
17 |
# You should have received a copy of the GNU General Public License |
18 |
# along with Koha; if not, see <http://www.gnu.org/licenses>. |
19 |
|
20 |
|
21 |
use Modern::Perl; |
22 |
|
23 |
use C4::Auth; |
24 |
use C4::Context; |
25 |
use Koha::Patrons; |
26 |
|
27 |
=head1 API |
28 |
|
29 |
=head2 Class Methods |
30 |
|
31 |
=head3 cgi_is_authenticated |
32 |
|
33 |
This method checks if there is a CGISESSID and if the associated session |
34 |
exists and has a patron attached to it. |
35 |
|
36 |
=cut |
37 |
|
38 |
#NOTE: CGI |
39 |
sub cgi_is_authenticated { |
40 |
my ($class,$args) = @_; |
41 |
my $is_authenticated; |
42 |
my $cgi = $args->{cgi}; |
43 |
if ($cgi){ |
44 |
my $sessionID = $cgi->cookie('CGISESSID'); |
45 |
if ($sessionID){ |
46 |
my $session = C4::Auth::get_session($sessionID); |
47 |
if ($session){ |
48 |
my $id = $session->param('id'); |
49 |
if ($id){ |
50 |
my $patrons = Koha::Patrons->search({ userid => $id }); |
51 |
if ($patrons->count){ |
52 |
$is_authenticated = 1; |
53 |
} |
54 |
} |
55 |
} |
56 |
} |
57 |
} |
58 |
return $is_authenticated; |
59 |
} |
60 |
|
61 |
=head3 create_session |
62 |
|
63 |
This method creates a Koha session for a patron. |
64 |
|
65 |
=cut |
66 |
|
67 |
sub create_session { |
68 |
my ($class,$args) = @_; |
69 |
my $complete_session; |
70 |
my $patron = $args->{patron}; |
71 |
if ($patron){ |
72 |
my $session = C4::Auth::get_session(""); |
73 |
if ($session){ |
74 |
my $sessionID = $session->id; |
75 |
if ($sessionID){ |
76 |
C4::Context->_new_userenv($sessionID); |
77 |
$session->param( 'number', $patron->borrowernumber ); |
78 |
$session->param( 'id', $patron->userid ); |
79 |
$session->param( 'cardnumber', $patron->cardnumber ); |
80 |
$session->param( 'firstname', $patron->firstname ); |
81 |
$session->param( 'surname', $patron->surname ); |
82 |
$session->param( 'branch', $patron->library->branchcode ); |
83 |
$session->param( 'branchname', $patron->library->branchname ); |
84 |
$session->param( 'flags', $patron->flags ); |
85 |
$session->param( 'emailaddress', $patron->email ); |
86 |
$session->param( 'ip', $session->remote_addr() ); |
87 |
$session->param( 'lasttime', time() ); |
88 |
C4::Context->set_userenv( |
89 |
$session->param('number'), $session->param('id'), |
90 |
$session->param('cardnumber'), $session->param('firstname'), |
91 |
$session->param('surname'), $session->param('branch'), |
92 |
$session->param('branchname'), $session->param('flags'), |
93 |
$session->param('emailaddress'), $session->param('shibboleth'), |
94 |
$session->param('desk_id'), $session->param('desk_name'), |
95 |
$session->param('register_id'), $session->param('register_name') |
96 |
); |
97 |
#NOTE: Persist session immediately. Otherwise, scoping issues can bite you. |
98 |
$session->flush(); |
99 |
$complete_session = $session; |
100 |
} |
101 |
} |
102 |
} |
103 |
return $complete_session; |
104 |
} |
105 |
|
106 |
1; |