Skip to content
Snippets Groups Projects
Commit d1611cc5 authored by Bertrand Gauthier's avatar Bertrand Gauthier
Browse files

Aides de vue User* : Injection du UserContext (et plus du service d'authentification).

Aide vue UserCurrent : affichage du rôle courant de l'utilisateur à côté du nom.
parent 8f50d28a
No related branches found
No related tags found
No related merge requests found
Showing with 43 additions and 95 deletions
......@@ -2,8 +2,8 @@
namespace UnicaenAuth\View\Helper;
use Zend\I18n\View\Helper\AbstractTranslatorHelper;
use Zend\Authentication\AuthenticationService;
use Zend\View\Exception\InvalidArgumentException;
use UnicaenAuth\Service\UserContext;
/**
* Classe mère des aides de vue concernant l'utilisateur connecté.
......@@ -12,39 +12,39 @@ use Zend\View\Exception\InvalidArgumentException;
*/
abstract class UserAbstract extends AbstractTranslatorHelper
{
protected $authService;
protected $userContext;
/**
* Constructeur.
*
* @param AuthenticationService $authService
* @param UserContext $userContext
*/
public function __construct(AuthenticationService $authService = null)
public function __construct(UserContext $userContext = null)
{
if (null !== $authService) {
$this->setAuthService($authService);
if (null !== $userContext) {
$this->setUserContext($userContext);
}
}
/**
* Get Authentication Service.
* Get UserContext Service.
*
* @return \Zend\Authentication\AuthenticationService
* @return UserContext
*/
public function getAuthService()
public function getUserContext()
{
return $this->authService;
return $this->userContext;
}
/**
* Set Authentication Service.
* Set UserContext.
*
* @param \Zend\Authentication\AuthenticationService $authService
* @param UserContext $userContext
* @return UserAbstract
*/
public function setAuthService($authService)
public function setUserContext($userContext)
{
$this->authService = $authService;
$this->userContext = $userContext;
return $this;
}
......@@ -56,12 +56,10 @@ abstract class UserAbstract extends AbstractTranslatorHelper
*/
public function getIdentity($preferedKey = null)
{
if (!$this->getAuthService() || !$this->getAuthService()->hasIdentity()) {
if (!($identity = $this->getUserContext()->getIdentity())) {
return null;
}
$identity = $this->getAuthService()->getIdentity();
if (is_array($identity)) {
$keys = array('ldap', 'db');
if ($preferedKey) {
......
......@@ -20,8 +20,8 @@ class UserConnectionFactory implements FactoryInterface
*/
public function createService(ServiceLocatorInterface $helperPluginManager)
{
$authService = $helperPluginManager->getServiceLocator()->get('zfcuser_auth_service');
$authUserContext = $helperPluginManager->getServiceLocator()->get('authUserContext');
return new UserConnection($authService);
return new UserConnection($authUserContext);
}
}
\ No newline at end of file
......@@ -40,10 +40,15 @@ class UserCurrent extends UserAbstract
$id = 'user-current-info';
$userStatusHelper = $this->getView()->plugin('userStatus'); /* @var $userStatusHelper \UnicaenAuth\View\Helper\UserStatus */
$status = $userStatusHelper(false);
$userProfileSelectable = true;
if ($userProfileSelectable) {
$status .= sprintf(", <small>%s</small>", $this->getUserContext()->getSelectedIdentityRole());
}
if ($this->getIdentity()) {
$userProfileHelper = $this->getView()->plugin('userProfile'); /* @var $userProfileHelper \UnicaenAuth\View\Helper\UserProfile */
$userProfileHelper->setUserProfileSelectable();
$userProfileHelper->setUserProfileSelectable($userProfileSelectable);
$userInfoHelper = $this->getView()->plugin('userInfo'); /* @var $userInfoHelper \UnicaenAuth\View\Helper\UserInfo */
......
......@@ -20,8 +20,8 @@ class UserCurrentFactory implements FactoryInterface
*/
public function createService(ServiceLocatorInterface $helperPluginManager)
{
$authService = $helperPluginManager->getServiceLocator()->get('zfcuser_auth_service');
$authUserContext = $helperPluginManager->getServiceLocator()->get('authUserContext');
return new UserCurrent($authService);
return new UserCurrent($authUserContext);
}
}
\ No newline at end of file
......@@ -21,10 +21,10 @@ class UserInfoFactory implements FactoryInterface
public function createService(ServiceLocatorInterface $helperPluginManager)
{
$serviceLocator = $helperPluginManager->getServiceLocator();
$authService = $serviceLocator->get('zfcuser_auth_service');
$authUserContext = $serviceLocator->get('authUserContext');
$mapper = $serviceLocator->get('ldap_structure_mapper');
$helper = new UserInfo($authService);
$helper = new UserInfo($authUserContext);
$helper->setMapperStructure($mapper);
return $helper;
......
......@@ -10,11 +10,6 @@ use Zend\Permissions\Acl\Role\RoleInterface;
*/
class UserProfile extends UserAbstract
{
/**
* @var \UnicaenAuth\Service\UserContext
*/
protected $userContextService;
/**
* @var bool
*/
......@@ -93,7 +88,7 @@ class UserProfile extends UserAbstract
protected function getIdentityRoles()
{
if (null === $this->identityRoles) {
$this->identityRoles = $this->getUserContextService()->getIdentityRoles();
$this->identityRoles = $this->getUserContext()->getIdentityRoles();
}
return $this->identityRoles;
}
......@@ -128,26 +123,6 @@ class UserProfile extends UserAbstract
return $roles;
}
/**
*
* @return \UnicaenAuth\Service\UserContext
*/
public function getUserContextService()
{
return $this->userContextService;
}
/**
*
* @param \UnicaenAuth\Service\UserContext $userContextService
* @return self
*/
public function setUserContextService(\UnicaenAuth\Service\UserContext $userContextService = null)
{
$this->userContextService = $userContextService;
return $this;
}
/**
* Spécifie s'il faut afficher les profils
* de l'utilisateur sous forme d'une liste déroulante ou de boutons radios, permettant
......@@ -161,6 +136,4 @@ class UserProfile extends UserAbstract
$this->userProfileSelectable = $userProfileSelectable;
return $this;
}
}
\ No newline at end of file
......@@ -21,12 +21,8 @@ class UserProfileFactory implements FactoryInterface
public function createService(ServiceLocatorInterface $helperPluginManager)
{
$serviceLocator = $helperPluginManager->getServiceLocator();
$authService = $serviceLocator->get('zfcuser_auth_service');
$userContextService = $serviceLocator->get('AuthUserContext');
$authUserContext = $serviceLocator->get('authUserContext');
$helper = new UserProfile($authService);
$helper->setUserContextService($userContextService);
return $helper;
return new UserProfile($authUserContext);
}
}
\ No newline at end of file
......@@ -108,7 +108,7 @@ EOS;
*/
protected function getSelectedIdentityRole()
{
$role = $this->getUserContextService()->getSelectedIdentityRole();
$role = $this->getUserContext()->getSelectedIdentityRole();
if ($role instanceof RoleInterface) {
return $role->getRoleId();
}
......@@ -144,33 +144,13 @@ EOS;
return $roles;
}
/**
*
* @return \UnicaenAuth\Service\UserContext
*/
public function getUserContextService()
{
return $this->userContextService;
}
/**
*
* @param \UnicaenAuth\Service\UserContext $userContextService
* @return self
*/
public function setUserContextService(\UnicaenAuth\Service\UserContext $userContextService = null)
{
$this->userContextService = $userContextService;
return $this;
}
/**
*
* @return array
*/
protected function getSelectableRoles()
{
return $this->getUserContextService()->getSelectableIdentityRoles();
return $this->getUserContext()->getSelectableIdentityRoles();
}
public function setFormClass($formClass)
......
......@@ -20,12 +20,8 @@ class UserProfileSelectFactory extends \UnicaenApp\View\Helper\UserProfileSelect
public function createService(ServiceLocatorInterface $helperPluginManager)
{
$serviceLocator = $helperPluginManager->getServiceLocator();
$authService = $serviceLocator->get('zfcuser_auth_service');
$userContextService = $serviceLocator->get('AuthUserContext');
$helper = new UserProfileSelect($authService);
$helper->setUserContextService($userContextService);
return $helper;
return new UserProfileSelect($userContextService);
}
}
\ No newline at end of file
......@@ -84,7 +84,7 @@ class UserStatus extends UserAbstract
}
}
$out = sprintf('<strong>%s</strong>', $name);
$out = sprintf('<span class="glyphicon glyphicon-user"></span> <strong>%s</strong>', $name);
return $out;
}
......
......@@ -20,8 +20,8 @@ class UserStatusFactory implements FactoryInterface
*/
public function createService(ServiceLocatorInterface $helperPluginManager)
{
$authService = $helperPluginManager->getServiceLocator()->get('zfcuser_auth_service');
$userContext = $helperPluginManager->getServiceLocator()->get('authUserContext');
return new UserStatus($authService);
return new UserStatus($userContext);
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment