Got time to look more into the problems now. As you have found out, stash
entries do not survive a redirect_to
, but you can use flash
instead.
I've done some minor changes to the code as well to at least get rid of some of the most peculiar things. After those changes, the debug output from morbo
looks sane.
lib/Login.pm
Instead of calling a controller action for checking if a user is logged in, use a simple callback:
my $logged_in = $r->under->to(cb => sub {
my $self = shift;
return defined $self->session('user');
});
lib/Login/Login.pm
Renamed the logged_in
sub to dashboard
(which fix the action not found error), and add a proper render
call at the end (to render the login/dashboard
template).
sub dashboard {
my $self = shift;
$self->stash(
urls => $self->urls->getUrls($self->session('user')),
);
return $self->render;
}
In sub send_url
I changed the $self->stash(result =>
to flash
:
my $params = $self->req->params->to_hash;
if ($params) {
$self->flash(result => "Errors - not sent");
}
templates/login/dashboard.html.ep
Your check for result
became:
<li><%= flash('result') // 'result not in flash' %></li>
And some final advices:
- The database access can be improved a lot. Use the excellent Mojolicious::Plugin::Database instead of trying to figure out how to get things working with prefork/hypnotoad.
- Never, never, never untar the Mojolicious source code directly into your app! (or checking in the VCS...)
- Use a proper build environment (EU::MM, M::B etc).
- Read the Mojolicious documentation, and begin coding in small scale (Mojolicious::Lite) and grow it to a full app if neccessary (following the guidelines in Mojolicious::Guides::Growing).
Good luck!