On Tue, Nov 22, 2005 at 08:48:15PM -0500, Rick Delaney wrote:
> 
> If you want to do the whole branch now, I'm done.

I just want to point out that the changes look like a lot more than they
are.  Much of it is just refactored code.  After my .sig is a diff that
ignores whitespace between the mainline Framework.pm and the one in my
branch so you can better see the real changes.

-- 
Rick Delaney
[EMAIL PROTECTED]


--- main/lib/CGI/Application/Framework.pm       2005-11-03 20:27:19.000000000 
-0500
+++ dev/caf-auth/lib/CGI/Application/Framework.pm       2005-11-22 
20:15:00.000000000 -0500
@@ -2037,6 +2037,7 @@
     }
 
 
+    my $start_rm = $config->{'start_rm'} || $config->{'post_login_rm'};
     $tmplvars{'webapp'} = $self;
     $tmplvars{'run_mode_tags'} = {
         COMEFROMRUNMODE
@@ -2044,7 +2045,7 @@
             CURRENTRUNMODE
             => [ CURRENT  => $self->get_current_runmode ],
             SUBMITTORUNMODE
-            => [ SUBMITTO => $config->{'post_login_rm'} ],
+            => [ SUBMITTO => $start_rm ],
     };
     # ======== end population of tmpl_vars =============================
 
@@ -2227,6 +2228,14 @@
 
     $self->param( REQUIRE_LOGIN => $require_login);
 
+    if ($require_login) {
+        $self->start_mode('login');
+    } else {
+        my $start_rm = $config->{'start_rm'} 
+            or die "config variable 'start_rm' is not set";
+        $self->start_mode($start_rm);
+    }
+
     # build the template options (for system templates)
     my $template_options = $config->{'SystemTemplateOptions'};
 
@@ -2671,6 +2680,7 @@
                       . $self->start_mode()
                       );
 
+
     if ( $self->get_current_runmode() eq $self->start_mode() ) {
 
         # ---------------------------------------------------------------
@@ -2687,19 +2697,34 @@
                           . "\n"
                           . ' --> per start_mode() = '
                           . $self->start_mode());
+        $self->_make_session($self->get_session_id) unless $self->session;
         return;
     }
 
     $self->log->debug("I made it past the login run mode check");
 
-    if ( $self->query->param($self->param('come_from_rm'))
-        and $self->query->param($self->param('come_from_rm')) eq 'login' ) {
+    my $from_rm = $self->query->param('come_from_rm');
+    if ($from_rm) {
+        $self->log->debug("Come from run mode = $from_rm");
 
-        #
+        if ($from_rm eq 'login') {
         # This is a "first time" login attempt, so...
-        #
         $self->log->debug("About to validate a first time login");
 
+            return $self->_framework_prerun_first;
+        }
+    } else {
+        $self->log->debug("Come from run mode not specified");
+    }
+    return $self->_framework_prerun_next;
+}
+
+
+sub _framework_prerun_first {
+    my $self = shift;
+
+    my $config = $self->conf($self->config_name)->context;
+
         # ---------------------------------------------------------
         # First, make sure that the form submission is at least
         # barely within specification (i.e. provides a user id and
@@ -2734,7 +2759,7 @@
         # A numeric user id and a password were provided... now,
         # make sure that they match...
         # ---------------------------------------------------------
-        my ($is_login_authenticated, $user) = $self->_login_authenticate();
+    my ($is_login_authenticated, $user) = $self->_authenticate();
         if ( $is_login_authenticated ) {
 
             # ---------------------------------------------------
@@ -2748,17 +2773,12 @@
             $self->log->debug("Login authenticate:  current runmode = "
                               . $self->get_current_runmode);
 
-            tie(my %session,
-                'Apache::SessionX',
-                undef,
-                $config->{'SessionParams'});
-            $self->param( session => \%session);
-            $self->header_props( -cookie =>
-                                 $self->query->cookie
-                                 (
+        my $session = $self->_make_session;
+        $self->header_props( 
+            -cookie => $self->query->cookie(
                                   -name  => 'session_id',
-                                  -value => $session{_session_id},
-                                  )
+                -value => $session->{_session_id},
+            ),
                                  );
 
             # ---------------------------------------------------
@@ -2781,9 +2801,6 @@
             # hidden input "rm" tag in the login form.
             # ---------------------------------------------------
             $self->param( _login_loop => 0 );
-            return;
-            # ---------------------------------------------------
-
         } else {
 
 
@@ -2802,20 +2819,14 @@
 
             $self->param( _errs => $errs );
             $self->prerun_mode('login');
-            return;
-            # -----------------------------------------------------
         }
+    return 1;
+}
 
-    } else {
-
-        if ($self->query->param('come_from_rm')) {
-            $self->log->debug("Come from run mode = "
-                              . $self->query->param('come_from_rm'));
-        }
-        else {
-            $self->log->debug("Come from run mode not specified");
-        }
+sub _framework_prerun_next {
+    my $self = shift;
 
+    my $config = $self->conf($self->config_name)->context;
         # --------------------------------------------------------------------
         # Try what we can to get a session ID, and set various parameters
         # corresponding to what we came across in the attempt.  If we can't
@@ -2851,12 +2862,7 @@
         # can't find a session with this session ID, kick out to a prerun
         # mode to display an error page to the user.
         # --------------------------------------------------------------------
-        my %session = ();
-
-        eval { tie(%session,
-                   'Apache::SessionX',
-                   $session_id,
-                   $config->{'SessionParams'}); };
+    my $session = eval { $self->_make_session($session_id) };
 
         if ( $@ ) { # there was an error in the creation of the session
 
@@ -2881,12 +2887,6 @@
         }
         # --------------------------------------------------------------------
 
-        # --------------------------------------------------------------------
-        # We have a %session, so stick it inside of our $self so that we can
-        # carry it around the application.
-        # --------------------------------------------------------------------
-        $self->param( session => \%session );
-        # --------------------------------------------------------------------
 
         # ------------------------------------------------------------------
         # This seems like a good place to put in a check to make sure that
@@ -3045,11 +3045,26 @@
 
             } # end of if $self->_relogin_test
         }
-    }
-
-    return; # guess that's about it...
 }
 
+sub _authenticate {
+    my $self = shift;
+    my ($is_login_authenticated, $user) = $self->param('REQUIRE_LOGIN')
+                                        ? $self->_login_authenticate()
+                                        : (1, $self->_default_user);
+}
+
+sub _default_user {
+    my $self = shift;
+    # RPD - Just want a default object that can satisfy the example
+    # apps.  They require the attributes below.
+    require Hash::AsObject;
+    my $user = Hash::AsObject->new({
+        uid         => -1,
+        username    => 'default',
+        fullname    => 'Default User',
+    });
+}
 
 # ------------------------------------------------------------------
 # These methods are new and unique to CGI::Application::Framework
@@ -3362,6 +3377,21 @@
     return $self->param('session') || undef;
 }
 
+sub _make_session {
+    my $self = shift;
+    my ($session_id) = @_;
+
+    my $config = $self->conf($self->config_name)->context;
+    my %session;
+    tie(%session, 'Apache::SessionX', $session_id, $config->{'SessionParams'});
+    # --------------------------------------------------------------------
+    # We have a %session, so stick it inside of our $self so that we can
+    # carry it around the application.
+    # --------------------------------------------------------------------
+    $self->param(session => \%session );
+
+    return \%session;
+}
 
 # -------------------------------------------------------------------
 # _framework_template_pre_process is called right before a template is
_______________________________________________
caf mailing list
caf@lpi.org
http://list.lpi.org/cgi-bin/mailman/listinfo/caf

Reply via email to