Ejemplo n.º 1
0
 /**
  * getUserProperty
  *
  * @param User   $user              user
  * @param string $propertyNameSpace propertyNameSpace
  * @param null   $dflt              dflt
  * @param bool   $refresh           refresh
  *
  * @return mixed
  */
 public function getUserProperty(User $user, $propertyNameSpace, $dflt = null, $refresh = false)
 {
     $property = $user->getProperty($propertyNameSpace, null);
     // if a property is not set, see try to get it from an event listener
     if ($property === null || $refresh) {
         // @event getUserProperty.pre -
         $this->getEventManager()->trigger('getUserProperty', $this, ['user' => $user, 'propertyNameSpace' => $propertyNameSpace]);
     }
     $property = $user->getProperty($propertyNameSpace, $dflt);
     return $property;
 }
Ejemplo n.º 2
0
 /**
  * getUserProperty
  *
  * @param string $propertyId
  * @param null   $default
  *
  * @return null
  */
 public function getUserProperty($propertyId, $default = null)
 {
     return $this->suUser->getProperty($propertyId, $default);
 }
Ejemplo n.º 3
0
 /**
  * getUserRoles
  *
  * @param User|null $user user
  *
  * @return null
  */
 public function getUserRoles($user)
 {
     if (!$user instanceof User) {
         return $this->getGuestRole();
     }
     /** @var $userRoleProperty UserRoleProperty */
     $userRoleProperty = $user->getProperty(UserRoleProperty::PROPERTY_KEY);
     if (!$userRoleProperty instanceof UserRoleProperty) {
         return [];
     }
     return $userRoleProperty->getRoles();
 }
Ejemplo n.º 4
0
 /**
  * testSetGet
  *
  * @covers \RcmUser\User\Entity\User
  *
  * @return void
  */
 public function testSetGet()
 {
     $user = new User();
     $value = 'id123';
     $user->setId($value);
     $this->assertEquals($value, $user->getId(), 'Setter or getter failed.');
     $value = 'usernamexxx';
     $user->setUsername($value);
     $this->assertEquals($value, $user->getUsername(), 'Setter or getter failed.');
     $value = '';
     $user->setUsername($value);
     $this->assertNull($user->getUsername(), 'Setter or getter failed.');
     $value = 'passwordxxx';
     $user->setPassword($value);
     $this->assertEquals($value, $user->getPassword(), 'Setter or getter failed.');
     $value = '';
     $user->setPassword($value);
     $this->assertNull($user->getPassword(), 'Setter or getter failed.');
     $value = 'statexxx';
     $user->setState($value);
     $this->assertEquals($value, $user->getState(), 'Setter or getter failed.');
     $value = '';
     $user->setState($value);
     $this->assertNull($user->getState(), 'Setter or getter failed.');
     $value = '*****@*****.**';
     $user->setEmail($value);
     $this->assertEquals($value, $user->getEmail(), 'Setter or getter failed.');
     $value = '';
     $user->setEmail($value);
     $this->assertNull($user->getEmail(), 'Setter or getter failed.');
     $value = 'namesxxx';
     $user->setName($value);
     $this->assertEquals($value, $user->getName(), 'Setter or getter failed.');
     $this->assertEquals($value, $user->get('name', null), 'Getter failed.');
     $value = '';
     $user->setName($value);
     $this->assertNull($user->getName(), 'Setter or getter failed.');
     // cannot set or get iterator
     $hasSet = $user->set('iterator', 'something');
     $this->assertFalse($hasSet, 'Failed to stop iterator property set.');
     $this->assertNull($user->get('iterator', null), 'Getter failed to exclude.');
     $value = null;
     $user->setProperties($value);
     $this->assertTrue(is_array($user->getProperties()), 'Setter or getter failed.');
     $pvalue = ['Y' => 'propertyYYY'];
     $value = 'propertyXXX';
     $user->setProperties($pvalue);
     $this->assertArrayHasKey('Y', $user->getProperties(), 'Setter or getter failed.');
     $user->setProperty('X', $value);
     $this->assertEquals($value, $user->getProperty('X'), 'Setter or getter failed.');
     $this->assertArrayHasKey('Y', $user->getProperties(), 'Setter or getter failed.');
     $this->assertTrue($user->getProperty('nope', 'not_found') === 'not_found', 'Setter or getter failed.');
     $this->assertEquals('propertyYYY', $user->get('Y', null), 'Getter failed.');
     $badPropertyName = 'N*P#_^^^^';
     $hasSet = $user->set($badPropertyName, 'something');
     $this->assertFalse($hasSet, 'Failed to stop bad property set.');
     $hasException = false;
     try {
         $user->setProperty($badPropertyName, 'something');
     } catch (RcmUserException $e) {
         $hasException = true;
         $this->assertInstanceOf('\\RcmUser\\Exception\\RcmUserException', $e);
     }
     if (!$hasException) {
         $this->fail("Expected exception not thrown");
     }
 }
Ejemplo n.º 5
0
 /**
  * getImpersonatorUser Get the admin user from the user if SUed
  *
  * @param User $user
  *
  * @return mixed|null
  */
 public function getImpersonatorUser(User $user)
 {
     /** @var SuProperty $suProperty */
     $suProperty = $user->getProperty(SuProperty::SU_PROPERTY);
     if (empty($suProperty)) {
         // ERROR
         return null;
     }
     $suUser = $suProperty->getUser();
     if (empty($suUser)) {
         // ERROR
         return null;
     }
     return $suUser;
 }