https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=31050

--- Comment #2 from David Cook <[email protected]> ---
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.
_______________________________________________
Koha-bugs mailing list
[email protected]
https://lists.koha-community.org/cgi-bin/mailman/listinfo/koha-bugs
website : http://www.koha-community.org/
git : http://git.koha-community.org/
bugs : http://bugs.koha-community.org/

Reply via email to