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 @@ ...@@ -2,8 +2,8 @@
namespace UnicaenAuth\View\Helper; namespace UnicaenAuth\View\Helper;
use Zend\I18n\View\Helper\AbstractTranslatorHelper; use Zend\I18n\View\Helper\AbstractTranslatorHelper;
use Zend\Authentication\AuthenticationService;
use Zend\View\Exception\InvalidArgumentException; use Zend\View\Exception\InvalidArgumentException;
use UnicaenAuth\Service\UserContext;
/** /**
* Classe mère des aides de vue concernant l'utilisateur connecté. * Classe mère des aides de vue concernant l'utilisateur connecté.
...@@ -12,39 +12,39 @@ use Zend\View\Exception\InvalidArgumentException; ...@@ -12,39 +12,39 @@ use Zend\View\Exception\InvalidArgumentException;
*/ */
abstract class UserAbstract extends AbstractTranslatorHelper abstract class UserAbstract extends AbstractTranslatorHelper
{ {
protected $authService; protected $userContext;
/** /**
* Constructeur. * Constructeur.
* *
* @param AuthenticationService $authService * @param UserContext $userContext
*/ */
public function __construct(AuthenticationService $authService = null) public function __construct(UserContext $userContext = null)
{ {
if (null !== $authService) { if (null !== $userContext) {
$this->setAuthService($authService); $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 * @return UserAbstract
*/ */
public function setAuthService($authService) public function setUserContext($userContext)
{ {
$this->authService = $authService; $this->userContext = $userContext;
return $this; return $this;
} }
...@@ -56,12 +56,10 @@ abstract class UserAbstract extends AbstractTranslatorHelper ...@@ -56,12 +56,10 @@ abstract class UserAbstract extends AbstractTranslatorHelper
*/ */
public function getIdentity($preferedKey = null) public function getIdentity($preferedKey = null)
{ {
if (!$this->getAuthService() || !$this->getAuthService()->hasIdentity()) { if (!($identity = $this->getUserContext()->getIdentity())) {
return null; return null;
} }
$identity = $this->getAuthService()->getIdentity();
if (is_array($identity)) { if (is_array($identity)) {
$keys = array('ldap', 'db'); $keys = array('ldap', 'db');
if ($preferedKey) { if ($preferedKey) {
......
...@@ -20,8 +20,8 @@ class UserConnectionFactory implements FactoryInterface ...@@ -20,8 +20,8 @@ class UserConnectionFactory implements FactoryInterface
*/ */
public function createService(ServiceLocatorInterface $helperPluginManager) 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 ...@@ -40,10 +40,15 @@ class UserCurrent extends UserAbstract
$id = 'user-current-info'; $id = 'user-current-info';
$userStatusHelper = $this->getView()->plugin('userStatus'); /* @var $userStatusHelper \UnicaenAuth\View\Helper\UserStatus */ $userStatusHelper = $this->getView()->plugin('userStatus'); /* @var $userStatusHelper \UnicaenAuth\View\Helper\UserStatus */
$status = $userStatusHelper(false); $status = $userStatusHelper(false);
$userProfileSelectable = true;
if ($userProfileSelectable) {
$status .= sprintf(", <small>%s</small>", $this->getUserContext()->getSelectedIdentityRole());
}
if ($this->getIdentity()) { if ($this->getIdentity()) {
$userProfileHelper = $this->getView()->plugin('userProfile'); /* @var $userProfileHelper \UnicaenAuth\View\Helper\UserProfile */ $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 */ $userInfoHelper = $this->getView()->plugin('userInfo'); /* @var $userInfoHelper \UnicaenAuth\View\Helper\UserInfo */
......
...@@ -20,8 +20,8 @@ class UserCurrentFactory implements FactoryInterface ...@@ -20,8 +20,8 @@ class UserCurrentFactory implements FactoryInterface
*/ */
public function createService(ServiceLocatorInterface $helperPluginManager) 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 ...@@ -21,10 +21,10 @@ class UserInfoFactory implements FactoryInterface
public function createService(ServiceLocatorInterface $helperPluginManager) public function createService(ServiceLocatorInterface $helperPluginManager)
{ {
$serviceLocator = $helperPluginManager->getServiceLocator(); $serviceLocator = $helperPluginManager->getServiceLocator();
$authService = $serviceLocator->get('zfcuser_auth_service'); $authUserContext = $serviceLocator->get('authUserContext');
$mapper = $serviceLocator->get('ldap_structure_mapper'); $mapper = $serviceLocator->get('ldap_structure_mapper');
$helper = new UserInfo($authService); $helper = new UserInfo($authUserContext);
$helper->setMapperStructure($mapper); $helper->setMapperStructure($mapper);
return $helper; return $helper;
......
...@@ -10,11 +10,6 @@ use Zend\Permissions\Acl\Role\RoleInterface; ...@@ -10,11 +10,6 @@ use Zend\Permissions\Acl\Role\RoleInterface;
*/ */
class UserProfile extends UserAbstract class UserProfile extends UserAbstract
{ {
/**
* @var \UnicaenAuth\Service\UserContext
*/
protected $userContextService;
/** /**
* @var bool * @var bool
*/ */
...@@ -93,7 +88,7 @@ class UserProfile extends UserAbstract ...@@ -93,7 +88,7 @@ class UserProfile extends UserAbstract
protected function getIdentityRoles() protected function getIdentityRoles()
{ {
if (null === $this->identityRoles) { if (null === $this->identityRoles) {
$this->identityRoles = $this->getUserContextService()->getIdentityRoles(); $this->identityRoles = $this->getUserContext()->getIdentityRoles();
} }
return $this->identityRoles; return $this->identityRoles;
} }
...@@ -128,26 +123,6 @@ class UserProfile extends UserAbstract ...@@ -128,26 +123,6 @@ class UserProfile extends UserAbstract
return $roles; 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 * Spécifie s'il faut afficher les profils
* de l'utilisateur sous forme d'une liste déroulante ou de boutons radios, permettant * de l'utilisateur sous forme d'une liste déroulante ou de boutons radios, permettant
...@@ -161,6 +136,4 @@ class UserProfile extends UserAbstract ...@@ -161,6 +136,4 @@ class UserProfile extends UserAbstract
$this->userProfileSelectable = $userProfileSelectable; $this->userProfileSelectable = $userProfileSelectable;
return $this; return $this;
} }
} }
\ No newline at end of file
...@@ -21,12 +21,8 @@ class UserProfileFactory implements FactoryInterface ...@@ -21,12 +21,8 @@ class UserProfileFactory implements FactoryInterface
public function createService(ServiceLocatorInterface $helperPluginManager) public function createService(ServiceLocatorInterface $helperPluginManager)
{ {
$serviceLocator = $helperPluginManager->getServiceLocator(); $serviceLocator = $helperPluginManager->getServiceLocator();
$authService = $serviceLocator->get('zfcuser_auth_service'); $authUserContext = $serviceLocator->get('authUserContext');
$userContextService = $serviceLocator->get('AuthUserContext');
$helper = new UserProfile($authService); return new UserProfile($authUserContext);
$helper->setUserContextService($userContextService);
return $helper;
} }
} }
\ No newline at end of file
...@@ -108,7 +108,7 @@ EOS; ...@@ -108,7 +108,7 @@ EOS;
*/ */
protected function getSelectedIdentityRole() protected function getSelectedIdentityRole()
{ {
$role = $this->getUserContextService()->getSelectedIdentityRole(); $role = $this->getUserContext()->getSelectedIdentityRole();
if ($role instanceof RoleInterface) { if ($role instanceof RoleInterface) {
return $role->getRoleId(); return $role->getRoleId();
} }
...@@ -144,33 +144,13 @@ EOS; ...@@ -144,33 +144,13 @@ EOS;
return $roles; 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 * @return array
*/ */
protected function getSelectableRoles() protected function getSelectableRoles()
{ {
return $this->getUserContextService()->getSelectableIdentityRoles(); return $this->getUserContext()->getSelectableIdentityRoles();
} }
public function setFormClass($formClass) public function setFormClass($formClass)
......
...@@ -20,12 +20,8 @@ class UserProfileSelectFactory extends \UnicaenApp\View\Helper\UserProfileSelect ...@@ -20,12 +20,8 @@ class UserProfileSelectFactory extends \UnicaenApp\View\Helper\UserProfileSelect
public function createService(ServiceLocatorInterface $helperPluginManager) public function createService(ServiceLocatorInterface $helperPluginManager)
{ {
$serviceLocator = $helperPluginManager->getServiceLocator(); $serviceLocator = $helperPluginManager->getServiceLocator();
$authService = $serviceLocator->get('zfcuser_auth_service');
$userContextService = $serviceLocator->get('AuthUserContext'); $userContextService = $serviceLocator->get('AuthUserContext');
$helper = new UserProfileSelect($authService); return new UserProfileSelect($userContextService);
$helper->setUserContextService($userContextService);
return $helper;
} }
} }
\ No newline at end of file
...@@ -84,7 +84,7 @@ class UserStatus extends UserAbstract ...@@ -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; return $out;
} }
......
...@@ -20,8 +20,8 @@ class UserStatusFactory implements FactoryInterface ...@@ -20,8 +20,8 @@ class UserStatusFactory implements FactoryInterface
*/ */
public function createService(ServiceLocatorInterface $helperPluginManager) 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