[Rt-commit] rt branch, 3.8-trunk, updated. rt-3.8.5-168-g5a5f584

jesse jesse at bestpractical.com
Tue Sep 29 16:06:19 EDT 2009


The branch, 3.8-trunk has been updated
       via  5a5f58450ea27a6258639517dae114a2106901a1 (commit)
      from  13c5c85839393fea772dc8c6822e3b8d86a4d8f0 (commit)

Summary of changes:
 lib/RT/Interface/Web.pm |   19 +++++++++++++++++++
 share/html/autohandler  |   29 ++++++++---------------------
 2 files changed, 27 insertions(+), 21 deletions(-)

- Log -----------------------------------------------------------------
commit 5a5f58450ea27a6258639517dae114a2106901a1
Author: Jesse Vincent <jesse at bestpractical.com>
Date:   Wed Sep 30 05:06:02 2009 +0900

    Extract Password authentication from the autohandler

diff --git a/lib/RT/Interface/Web.pm b/lib/RT/Interface/Web.pm
index bf538a0..8c7959e 100755
--- a/lib/RT/Interface/Web.pm
+++ b/lib/RT/Interface/Web.pm
@@ -338,6 +338,25 @@ sub AttemptExternalAuth {
     }
 }
 
+sub AttemptPasswordAuthentication {
+    my $ARGS     = shift;
+    my $user_obj = RT::CurrentUser->new();
+    $user_obj->Load( $ARGS->{user} );
+
+    my $m  = $HTML::Mason::Commands::m;
+
+    unless ( $user_obj->id && $user_obj->IsPassword( $ARGS->{pass} ) ) {
+        $RT::Logger->error("FAILED LOGIN for @{[$ARGS->{user}]} from $ENV{'REMOTE_ADDR'}");
+        $m->comp( '/Elements/Login', %$ARGS, Error => loc('Your username or password is incorrect'), );
+        $m->callback( %$ARGS, CallbackName => 'FailedLogin', CallbackPage => '/autohandler' );
+        $m->abort;
+    }
+
+    $RT::Logger->info("Successful login for @{[$ARGS->{user}]} from $ENV{'REMOTE_ADDR'}");
+    $HTML::Mason::Commands::session{'CurrentUser'} = $user_obj;
+    $m->callback( %$ARGS, CallbackName => 'SuccessfulLogin', CallbackPage => '/autohandler' );
+}
+
 =head2 Redirect URL
 
 This routine ells the current user's browser to redirect to URL.  
diff --git a/share/html/autohandler b/share/html/autohandler
index b5cb799..95950b9 100755
--- a/share/html/autohandler
+++ b/share/html/autohandler
@@ -70,9 +70,7 @@ RT::Interface::Web::PreprocessTimeUpdates(\%ARGS);
 $m->{'rt_base_time'} = [ Time::HiRes::gettimeofday() ];
 $m->comp( '/Elements/SetupSessionCookie', %ARGS );
 
-unless ( $session{'CurrentUser'} && $session{'CurrentUser'}->Id ) {
-    $session{'CurrentUser'} = RT::CurrentUser->new;
-}
+$session{'CurrentUser'} = RT::CurrentUser->new() unless ( $session{'CurrentUser'} && $session{'CurrentUser'}->Id );
 
 # Set the proper encoding for the current language handle
 $r->content_type("text/html; charset=utf-8");
@@ -89,28 +87,17 @@ $m->callback( %ARGS, CallbackName => 'Auth', CallbackPage => '/autohandler');
 
 delete $session{'CurrentUser'} unless $session{'CurrentUser'} && $session{'CurrentUser'}->Id;
 
-unless( $session{'CurrentUser'} ) {
+unless ( $session{'CurrentUser'} ) {
     # If the user is logging in, let's authenticate
-    if( defined $user && defined $pass ) {
-        my $user_obj = RT::CurrentUser->new;
-        $user_obj->Load( $user );
-
-        unless ( $user_obj->id && $user_obj->IsPassword( $pass ) ) {
-            $RT::Logger->error("FAILED LOGIN for $user from $ENV{'REMOTE_ADDR'}");
-            $m->comp( '/Elements/Login', %ARGS, Error => loc('Your username or password is incorrect'),);
-            $m->callback( %ARGS, CallbackName => 'FailedLogin', CallbackPage => '/autohandler');
+    if ( defined $user && defined $pass ) {
+        RT::Interface::Web::AttemptPasswordAuthentication( \%ARGS );
+
+        # if no credentials then show him login page
+        } else {
+            $m->comp( '/Elements/Login', %ARGS );
             $m->abort;
         }
-        $session{'CurrentUser'} = $user_obj;
-        $RT::Logger->info( "Successful login for $user from $ENV{'REMOTE_ADDR'}");
-        $m->callback( %ARGS, CallbackName => 'SuccessfulLogin', CallbackPage => '/autohandler' );
-    }
-    # if no credentials then show him login page
-    else {
-        $m->comp( '/Elements/Login', %ARGS );
-        $m->abort;
     }
-}
 
 # now it applies not only to home page, but any dashboard that can be used as a workspace
 $session{'home_refresh_interval'} = $ARGS{'HomeRefreshInterval'} if ( $ARGS{'HomeRefreshInterval'} ); 

-----------------------------------------------------------------------


More information about the Rt-commit mailing list