Bug 18403: Send logged_in_user to template from C4::Auth
authorJonathan Druart <jonathan.druart@bugs.koha-community.org>
Tue, 4 Apr 2017 19:43:58 +0000 (16:43 -0300)
committerJonathan Druart <jonathan.druart@bugs.koha-community.org>
Mon, 12 Feb 2018 18:41:37 +0000 (15:41 -0300)
Technical note:
To ease future changes we are passing a logged_in_user variable to templates.
It contains the Koha::Patron object representing the logged in patron.
This will be very useful for this patch and even after (for instance we will be
able to replace easily loggedinusername and loggedinusernumber).

Signed-off-by: Signed-off-by: Jon McGowan <jon.mcgowan@ptfs-europe.com>
Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
C4/Auth.pm

index 7fac6df..7903099 100644 (file)
@@ -213,26 +213,26 @@ sub get_template_and_user {
         # It's possible for $user to be the borrowernumber if they don't have a
         # userid defined (and are logging in through some other method, such
         # as SSL certs against an email address)
-        my $borrower;
+        my $patron;
         $borrowernumber = getborrowernumber($user) if defined($user);
         if ( !defined($borrowernumber) && defined($user) ) {
-            $borrower = Koha::Patrons->find( $user );
-            if ($borrower) {
-                $borrower = $borrower->unblessed;
+            $patron = Koha::Patrons->find( $user );
+            if ($patron) {
                 $borrowernumber = $user;
 
                 # A bit of a hack, but I don't know there's a nicer way
                 # to do it.
-                $user = $borrower->{firstname} . ' ' . $borrower->{surname};
+                $user = $patron->firstname . ' ' . $patron->surname;
             }
         } else {
-            $borrower = Koha::Patrons->find( $borrowernumber );
-            $borrower->unblessed if $borrower; # FIXME Otherwise, what to do?
+            $patron = Koha::Patrons->find( $borrowernumber );
+            # FIXME What to do if $patron does not exist?
         }
 
         # user info
-        $template->param( loggedinusername   => $user );
-        $template->param( loggedinusernumber => $borrowernumber );
+        $template->param( loggedinusername   => $user ); # FIXME Should be replaced with something like patron-title.inc
+        $template->param( loggedinusernumber => $borrowernumber ); # FIXME Should be replaced with logged_in_user.borrowernumber
+        $template->param( logged_in_user     => $patron );
         $template->param( sessionID          => $sessionID );
 
         if ( $in->{'type'} eq 'opac' ) {
@@ -254,7 +254,7 @@ sub get_template_and_user {
             );
         }
 
-        $template->param( "USER_INFO" => $borrower );
+        $template->param( "USER_INFO" => $patron->unblessed );
 
         my $all_perms = get_all_subpermissions();