Commit 7b26a69a authored by Benjamin Rokseth's avatar Benjamin Rokseth
Browse files

koha: use session->get instead of older ->param

parent a3c31df3
......@@ -63,36 +63,37 @@ sub Auth {
} else {
warn "NO AUTH SESSION - TRYING TO CREATE ONE";
# Run all auth methods
my $auth = $self->checkAuthMethods();
$auth = $self->checkAuthMethods();
$auth or Deichman::Exception::Auth::InvalidSession->throw();
$session->put(auth => $auth);
}
# decorate session with library, etc.
if ( my $userid = $session->param("userid") // $session->param("id") ) { # 'id' will be set for admin user as well
my $branchcode = $req->param("branch") || $auth->{branchcode};
if ( my $userid = $req->param("userid") // $auth->{user}->{userid} ) { # 'id' will be set for admin user as well
my $branchcode = $req->param("branch") || $auth->{user}->{branchcode};
try {
my $lib = Deichman::Library->new()->Get($branchcode)->{library};
$session->param(branch => $lib->{branchcode});
$session->param(branchname => $lib->{branchname});
$session->put(branch => $lib->{branchcode});
$session->put(branchname => $lib->{branchname});
} catch {
warn $_->description;
$session->param(branch => "NO_LIBRARY_SET");
$session->param(branchname => "NO_LIBRARY_SET");
$session->put(branch => "NO_LIBRARY_SET");
$session->put(branchname => "NO_LIBRARY_SET");
};
# Set C4::Context user env
C4::Context->set_userenv(
$session->param("number"),
$session->get("number"),
$userid,
map { $session->param($_); } qw/
map { $session->get($_); } qw/
cardnumber firstname surname branch branchname
flags emailaddress branchprinter shibbolet/,
);
# No idea what this is? Virtualshelves?
C4::Context::set_shelves_userenv( "bar", $session->param("barshelves") );
C4::Context::set_shelves_userenv( "pub", $session->param("pubshelves") );
C4::Context::set_shelves_userenv( "tot", $session->param("totshelves") );
C4::Context::set_shelves_userenv( "bar", $session->get("barshelves") );
C4::Context::set_shelves_userenv( "pub", $session->get("pubshelves") );
C4::Context::set_shelves_userenv( "tot", $session->get("totshelves") );
}
warn Dumper($session);
# Should Auth return something?
return;
}
......@@ -165,8 +166,8 @@ sub templateAndPermissions {
# Use new auth object
my $auth = $self->{session}->get("auth");
my $branch = $self->{session}->param("branchname") || $auth->{user}->{branchcode}; # session param overrides stored branch
my $userid = $self->{session}->param("userid") || $auth->{user}->{userid}; # session param overrides stored userid
my $branch = $self->{session}->get("branchname") || $auth->{user}->{branchcode}; # session param overrides stored branch
my $userid = $self->{session}->get("userid") || $auth->{user}->{userid}; # session param overrides stored userid
my $flags = $in->{flagsrequired};
#use Data::Dumper; warn Dumper($auth);
......@@ -200,8 +201,8 @@ sub setTemplatePermissions {
my ($self, $template, $auth, $branch) = @_;
$template->param( LoginBranchname => $branch );
my $id = $self->{session}->param("id");
if ($self->{session}->param("admin")) {
my $id = $self->{session}->get("id");
if ($self->{session}->get("admin")) {
# Admin user login should be removed!
warn "TEMPLATE CALLED WITH ADMINUSER - BETTER REMOVE THIS";
$auth->{permissions} = { superlibrarian => 1 };
......
......@@ -8,6 +8,7 @@ use Deichman::Exception;
use Try::Tiny;
use Data::Dumper;
use Core::DB;
use Koha::AuthUtils qw(hash_password);
use Digest::MD5 qw(md5_base64);
use Encode qw( encode is_utf8);
......@@ -47,18 +48,18 @@ sub DoAuth {
};
# TO BE REMOVED: this is contextual stuff
if ($user->{userid} eq "admin") {
$session->param(admin => 1 );
$session->param(number => 0 );
$session->param($_ => C4::Context->config("user") ) for (qw/id cardnumber firstname surname/);
$session->param(flags => 1 );
$session->param(emailaddress => C4::Context->preference("KohaAdminEmailAddress") );
$session->param(lasttime => time() );
$session->get(admin => 1 );
$session->get(number => 0 );
$session->get($_ => C4::Context->config("user") ) for (qw/id cardnumber firstname surname/);
$session->get(flags => 1 );
$session->get(emailaddress => C4::Context->preference("KohaAdminEmailAddress") );
$session->get(lasttime => time() );
} else {
# $patron->track_login;
$session->param($_ => $user->{$_}) for (qw/userid borrowernumber cardnumber firstname surname flags email/);
$session->get($_ => $user->{$_}) for (qw/userid borrowernumber cardnumber firstname surname flags email/);
# extra session params that don't map directly
$session->param(id => $user->{userid});
$session->param(emailaddress => $user->{email});
$session->get(id => $user->{userid});
$session->get(emailaddress => $user->{email});
}
warn "Authenticated (SIMPLE AUTH)";
$self->{auth}->{user} = $user;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment