sub login_sc : Local { my ( $self, $c ) = _; $c->login( $c->req->params->{username}, $c->req->params->{password} ); my $u = $c->session->{__user};
if ($u && $c->user_object->roles) { my $rol = $c->user_object->roles->next; etc...
if($c->user_exists) { my $u = $c->session->{__user}; etc...
--vb
On 12/28/06, Octavian Rasnita < orasnitagmail.com">orasnitagmail.com> wrote:
Hi,
Can you tell me how can I access the name of the currently logged user for printing it in a TT template? I have tried:
if ($c->user_exists) { $c->stash->{user} = $c->user; }
But it gives the following error:
Coldn't render template "undef error - Can't call method "from_session" on an undefined value at D:/usr/site/lib/CatalystPluginAuthentication.pm line 122.
I have spent a lot of time for finding that this is the problem, and I even found some threads on the list about this issue, but the only solution I have seen was to downgrade from C::P::Authentication 0.08 to
0.007, or to upgrade to 0.09. I am already using the version 0.09 though.
If I use the following static text, it works:
if ($c->user_exists) { $c->stash->{user} = "Gigi"; }
So the issue is using $c->user. How can I access the user in another way that doesn't give errors?
I have also tried (in the code and templates):
$c->user->name $c->user->username
[% c.user %]
But all of them use in fact $c->user, so of course they didn't work.