[Catalyst] Question about Chained Controller
Charlie Garrison
garrison at zeta.org.au
Mon Nov 15 03:00:19 GMT 2010
Good afternoon,
On 15/11/10 at 10:03 AM +0800, woosley. xu. <redicaps at gmail.com> wrote:
>Caught exception in SEA::Controller::User->get "Can't call method "id"
>on an undefined value
>
>
>What is the problem with this code?
I've never bothered to find out why, but I've run into
situations where $c->user_exists returns true and $c->user
returns false. I just check for defined($c->user) instead and
that solved it for me.
I also agree with other users that auto is a better place to do
that check.
>First I use this piece of code to make sure that a user is logged in, if
>not, the use will be forward to the login page, and I assume after login, it
>will return back to the original page
You need to handle that yourself. Save the current URI in the
session before redirecting to login page, and then redirect to
session-saved URI after successful $c->authenticate.
$c->session->{login_back} = $c->req->uri
unless ($c->action =~ /^(login|logout|rest\/)/ ||
$c->action eq '/');
And then after authenticate (simplified code, may not work as-is):
$c->response->redirect( delete $c->session->{login_back} ||
$c->uri_for_action('/index') );
Charlie
--
Ꮚ Charlie Garrison ♊ <garrison at zeta.org.au>
O< ascii ribbon campaign - stop html mail - www.asciiribbon.org
〠 http://www.ietf.org/rfc/rfc1855.txt
More information about the Catalyst
mailing list