Hi Eric --

> Seems like I'm authenticating with the login script just fine, but if
> I don't have a cookie set by thelogin script (i.e., I want to have the
> script redirect to the login script) and I request a script that is
> dependant on the login cookie, I fail init_session in that
> script...using the code on your home page:
> 
>  $self->param( 'session_dir' => '/dir/to/save/session/files' );
>       unless ( $self->init_session( 'name_of_cookie' ) )
>       {
>           $self->header_type('redirect');
>           $self->header_props( -location => 
> 'http://location/of/login.cgi' );
>           return;
>       }


You probably shouldn't be doing it like this, anyway.  Instead, you should
force the run-mode to one which performs the redirect.

My suggestion:  Instead of implementing a cgiapp_init() method, use the
mode_param() subref/callback hook to write a function which does this.  For
instance:

        sub setup {
                my $self = shift;

                $self->run_modes(
                        # Set up your normal run-modes here
                        'send_to_login' => 'send_to_login'
                );

                # Set up mode_param as a call-back instead of form parameter
                $self->mode_param(\&get_run_mode);
        }

        sub get_run_mode {
                my $self = shift;
                unless (user_is_logged_in()) {
                        return 'send_to_login';
                }

                # Do a normal check for run-mode
                my $q = $self->query();
                my $rm = $q->param('rm');
                $rm = 'start_mode' unless (defined($rm));
                return $rm;
        }

        sub send_to_login {
                my $self = shift;

                $self->header_type('redirect');
                my $redirect_url = 'http://location/of/login.pl';
                $self->header_props(url=>$redirect_url);
                return "<a href=\"$redirect_url\">$redirect_url</a>";
        }


This is a very clean solution.  When you set up redirect in your
cgiapp_init(), you STILL end up running the run-mode -- it just *may* get
redirected.  Very likely, this will result in a bug.

Mark's solution of hooking into the start_mode() is a good one.  The
solution I've outlined above takes that basic idea and goes to the next
logical step.

-Jesse-


----

  Jesse Erlbaum, CTO
  Vanguard Media
  212.242.5317 x115
  [EMAIL PROTECTED]



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to