Author: spadkins
Date: Tue May 16 08:25:21 2006
New Revision: 6300

Modified:
   p5ee/trunk/App-Context/lib/App/Context/Cmd.pm
   p5ee/trunk/App-Context/lib/App/Context/HTTP.pm
   p5ee/trunk/App-Context/lib/App/Context/Server.pm

Log:
tweak get_user()

Modified: p5ee/trunk/App-Context/lib/App/Context/Cmd.pm
==============================================================================
--- p5ee/trunk/App-Context/lib/App/Context/Cmd.pm       (original)
+++ p5ee/trunk/App-Context/lib/App/Context/Cmd.pm       Tue May 16 08:25:21 2006
@@ -178,7 +178,7 @@
 The user() method returns the username of the authenticated user.
 The special name, "guest", refers to the unauthenticated (anonymous) user.
 
-    * Signature: $username = $self->user();
+    * Signature: $username = $context->user();
     * Param:  void
     * Return: string
     * Throws: <none>
@@ -188,13 +188,14 @@
 
     $username = $context->user();
 
-Gets the currently logged in user id, or "guest" if it can't figure that out.
-
 =cut
 
 sub user {
+    &App::sub_entry if ($App::trace);
     my $self = shift;
-    return ($self->{user} || getlogin || (getpwuid($<))[0] || "guest");
+    my $user = $self->{user} || getlogin || (getpwuid($<))[0] || "guest";
+    &App::sub_exit($user) if ($App::trace);
+    $user;
 }
 
 1;

Modified: p5ee/trunk/App-Context/lib/App/Context/HTTP.pm
==============================================================================
--- p5ee/trunk/App-Context/lib/App/Context/HTTP.pm      (original)
+++ p5ee/trunk/App-Context/lib/App/Context/HTTP.pm      Tue May 16 08:25:21 2006
@@ -505,6 +505,7 @@
     &App::sub_entry if ($App::trace);
     my $self = shift;
     my $user = $self->request()->user();
+    $self->{user} = $user;
     my $switchable_users = $self->get_option("switchable_users");
     if ($switchable_users && $switchable_users =~ /\b$user\b/) {
         # check more carefully ...
@@ -512,9 +513,10 @@
             $switchable_users =~ /:$user:/ ||
             $switchable_users =~ /^$user:/ ||
             $switchable_users =~ /:$user$/) {
-            my $newuser = $self->so_get("default","u");
-            if ($newuser) {
-                $user = $newuser;
+            my $effective_user = $self->so_get("default","u");
+            if ($effective_user) {
+                $user = $effective_user;
+                $self->{effective_user} = $effective_user;
             }
         }
     }

Modified: p5ee/trunk/App-Context/lib/App/Context/Server.pm
==============================================================================
--- p5ee/trunk/App-Context/lib/App/Context/Server.pm    (original)
+++ p5ee/trunk/App-Context/lib/App/Context/Server.pm    Tue May 16 08:25:21 2006
@@ -839,5 +839,34 @@
     &App::sub_exit() if ($App::trace);
 }
 
+#############################################################################
+# user()
+#############################################################################
+
+=head2 user()
+
+The user() method returns the username of the authenticated user.
+The special name, "guest", refers to the unauthenticated (anonymous) user.
+
+    * Signature: $username = $context->user();
+    * Param:  void
+    * Return: string
+    * Throws: <none>
+    * Since:  0.01
+
+    Sample Usage: 
+
+    $username = $context->user();
+
+=cut
+
+sub user {
+    &App::sub_entry if ($App::trace);
+    my $self = shift;
+    my $user = $self->{user} || getlogin || (getpwuid($<))[0] || "guest";
+    &App::sub_exit($user) if ($App::trace);
+    $user;
+}
+
 1;
 

Reply via email to