Get logged in user with Smarty

A place for users and developers of the Xataface to discuss and receive support.

Get logged in user with Smarty

Postby Gershy » Tue Dec 18, 2012 12:18 pm

Hey all, how do I use smarty to get the name of the logged in user? It would be easy if the authentication tool were included in $ENV, like $ENV.AUTHENTICATION_TOOL

then I could just do
Code: Select all
{$ENV.AUTHENTICATION_TOOL->getLoggedInUser()->val('Name')}


But it doesn't exist, so in lieu what's the best way to go about this?
Gershy
 
Posts: 25
Joined: Wed Nov 14, 2012 12:28 pm

Re: Get logged in user with Smarty

Postby Gershy » Tue Dec 18, 2012 12:58 pm

figured it out; answer is easy: {$ENV.APPLICATION_OBJECT->getAuthenticationTool()} gets you to the authentication tool. The rest is simple.

Another way I figured out which I like more is in the beforeHandleRequest() function in the application delegate, you can use the following code to get the skintool;
Code: Select all
import('Dataface/SkinTool.php');
$sTool = Dataface_SkinTool::getInstance();

and you can then insert any value you wish using the assign function. Say I want to get the "LoggedInUserName" with smarty as {$LoggedInUser} I could say
Code: Select all
$user =& Dataface_AuthenticationTool::getInstance()->getLoggedInUser();
$sTool->assign('LoggedInName', $user->val('Name'));
Gershy
 
Posts: 25
Joined: Wed Nov 14, 2012 12:28 pm

Re: Get logged in user with Smarty

Postby shannah » Tue Dec 18, 2012 3:49 pm

Yes. That will work. An alternative is also:

{$ENV.user} To get the Dataface_Record object for the currently logged in user.
or
{$ENV.username} To get the username of the currently logged in user.

You can see most of the environment variables that are set in the Skin tool source.
http://weblite.ca/svn/dataface/core/tru ... inTool.php

Steve
--
Steve Hannah
@shannah78 (on twitter)
sjhannah.com blog
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm


Return to Xataface Users

Who is online

Users browsing this forum: No registered users and 1 guest

Powered by Dataface
© 2005-2007 Steve Hannah All rights reserved