[Flow] Login show Username
Bastian Waidelich
bastian at typo3.org
Wed Jan 7 14:41:42 CET 2015
On 06.01.15, at 17:01, Carsten Bleicker wrote:
Hi Patric & Carsten,
> I think you should not publish any kind of account data in you application
> because the account identifier is a login credential.
Well, rendering the username shouldn't be a problem. We do that all the
time (for example in the neos backend).
> class Foo extends ActionController {
>
> /**
> * @var \TYPO3\Flow\Security\Context
> * @Flow\Inject
> */
> protected $securityContext;
>
> public function indexAction(){
> $this->view->assign('party', $this->securityContext->getParty())
> }
> }
As a follow-up for Patric:
With:
public function indexAction() {
$this->view->assign('username',
$this->securityContext->getAccount()->getAccountIdentifier());
}
instead of the above you could just pass the username of the currently
authenticated user to the view.
But, heads-up, by default no account is authenticated and this would
issue a fatal error "Call to a member function getAccountIdentifier() on
a non-object". But usually you want to work with objects anyways in your
controller rather than with simple types like strings or numbers:
public function indexAction() {
$this->view->assign('account', $this->securityContext->getAccount());
}
Now you can access the username like this:
{account.accountIdentifier}
and properties of the related party like:
{account.party.*}
If you need the currently authenticated user in more places (for example
inside the fluid layout) it might make sense to create a common base
controller that assigns it to the view:
abstract class AbstractBaseController extends ActionController {
/**
* @var \TYPO3\Flow\Security\Account
*/
protected $account;
/**
* @Flow\Inject
* @var \TYPO3\Flow\Security\Context
*/
protected $securityContext;
/**
* @return void
*/
protected function initializeAction() {
$this->account = $this->securityContext->getAccount();
}
/**
* @param \TYPO3\Flow\Mvc\View\ViewInterface $view
* @return void
*/
protected function initializeView(ViewInterface $view) {
$view->assign('account', $this->account);
}
}
..and then extend *this* controller instead of ActionController
HTH
--
Bastian Waidelich
More information about the Flow
mailing list