[Koha-bugs] [Bug 31050] Standardize session setup
bugzilla-daemon at bugs.koha-community.org
bugzilla-daemon at bugs.koha-community.org
Mon Jun 27 08:34:06 CEST 2022
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=31050
--- Comment #2 from David Cook <dcook at prosentient.com.au> ---
As an aside, this would make it easier to write authentication extensions.
Here is an example where the user is logged in with a new user session by
supplying their cardnumber.
use Modern::Perl;
use CGI qw ( -utf8 );
use C4::Context;
my $query = CGI->new;
my $cardnumber = $query->param('cardnumber');
my $user = Koha::Patrons->find({ cardnumber => $cardnumber });
if ($user){
my $session = C4::Auth::get_session();
my $branch = $user->library;
C4::Context->setup_session({
session => $session,
data => {
'number', $user->borrowernumber,
'id', $user->userid,
'cardnumber', $user->cardnumber,
'firstname', $user->firstname,
'surname', $user->surname,
'branch', $branch->branchcode,
'branchname', $branch->branchname,
'flags', $user->flags,
'emailaddress', $user->email,
'interface', 'opac',
},
});
my $cookie = $query->cookie(
-name => 'CGISESSID',
-value => $session->id,
-HttpOnly => 1,
-secure => ( C4::Context->https_enabled() ? 1 : 0 ),
-sameSite => 'Lax'
);
print $query->redirect(
-uri => '/cgi-bin/koha/opac-main.pl',
-cookie => $cookie,
);
}
--
You are receiving this mail because:
You are watching all bug changes.
More information about the Koha-bugs
mailing list