Skip to content

Instantly share code, notes, and snippets.

@zipkid
Created January 4, 2011 08:45
Show Gist options
  • Save zipkid/764547 to your computer and use it in GitHub Desktop.
Save zipkid/764547 to your computer and use it in GitHub Desktop.
Mojolicious - redirect_to - flash issue...
Where does the flash disapear to!!!???
# Routes
my $r = $self->routes;
$r->namespace("Ds::Controllers");
# Normal route to controller
$r->route('/')->to('index#welcome' )->name('index');
$r->route('/login')->to('auth#index' )->name('login');
$r->route('/logout')->to('auth#logout' )->name('logout');
my $auth = $r->bridge->to('Auth#protected');
$self->plugin('resourceful_routes');
$self->resources('customers', -routes => $auth );
sub protected {
my $c = shift;
$c->app->log->debug( "= = =Ds::Auth::protected" );
return 1 if defined $c->session('user');
$c->app->log->debug( defined $c->session('user') ? "user defined" : "user not defined" );
$c->flash( login_redirect_path => $c->req->url->path );
warn $c->flash->{'login_redirect_path'};
$c->session( login_redirect_path => $c->req->url->path );
return $c->redirect_to( 'login' );
}
sub index {
my $c = shift;
$c->stash( menu => [] ) if ! defined $c->stash->{'menu'} ;
$c->app->log->debug( " = = Ds::Auth::index Not logged in" );
warn $c->flash->{'login_redirect_path'};
my $user = $c->param('user') || '';
my $pass = $c->param('pass') || '';
return $c->render unless $USERS->{$user} && $USERS->{$user} eq $pass;
$c->session( user => $user );
#warn $c->flash->{'login_redirect_path'};
#$c->redirect_to( $c->flash->{'login_redirect_path'} );
my $login_redirect_path = $c->session->{'login_redirect_path'};
delete $c->session->{'login_redirect_path'};
$c->redirect_to( $login_redirect_path );
}
piccolo:ds zipkid$ script/ds daemon --reload
Tue Jan 4 09:42:01 2011 info Mojo::Server::Daemon:320 [13533]: Server listening (http://*:3000)
Server available at http://*:3000.
Tue Jan 4 09:42:12 2011 debug Mojolicious::Plugin::RequestTimer:28 [13533]: GET /customers (Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; en-US; rv:1.9.2.13) Gecko/20101203 Firefox/3.6.13).
Tue Jan 4 09:42:12 2011 debug Mojolicious::Routes:421 [13533]: Dispatching Ds::Controllers::Auth->protected.
Tue Jan 4 09:42:12 2011 debug Ds::Controllers::Auth:15 [13533]: = = =Ds::Auth::protected
Tue Jan 4 09:42:12 2011 debug Ds::Controllers::Auth:19 [13533]: user not defined
/customers at script/../lib/Ds/Controllers/Auth.pm line 22.
Tue Jan 4 09:42:12 2011 debug Mojolicious::Plugin::RequestTimer:53 [13533]: 302 Found (0.002587s, 386.548/s).
Tue Jan 4 09:42:12 2011 debug Mojolicious::Routes:421 [13533]: Dispatching Ds::Controllers::Customers->index.
Tue Jan 4 09:42:12 2011 debug Mojolicious::Plugin::RequestTimer:28 [13533]: GET /login (Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; en-US; rv:1.9.2.13) Gecko/20101203 Firefox/3.6.13).
Tue Jan 4 09:42:12 2011 debug Mojolicious::Routes:421 [13533]: Dispatching Ds::Controllers::Auth->index.
Tue Jan 4 09:42:12 2011 debug Ds::Controllers::Auth:36 [13533]: = = Ds::Auth::index Not logged in
Use of uninitialized value in warn at script/../lib/Ds/Controllers/Auth.pm line 38.
Warning: something's wrong at script/../lib/Ds/Controllers/Auth.pm line 38.
Tue Jan 4 09:42:12 2011 debug Mojolicious::Plugin::RequestTimer:53 [13533]: 200 OK (0.023192s, 43.118/s).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment