public function testCreatorShouldBeGivenRights() { $place1 = new Place(); $this->assertEmpty($place1->getUsers(), 'new place without current user should have no users'); $user = new User(); User::setCurrentUser($user); $place2 = new Place(); $this->assertCount(1, $place2->getUsers(), 'new place with current user should have a user'); $this->assertSame($user, $place2->getUsers()[0], 'new place with current user should have a user'); }
public function testCreatorShouldBeGivenRights() { User::setCurrentUser(null); $calendar1 = new Calendar(); $this->assertEmpty($calendar1->getUsers(), 'new calendar without current user should have no users'); $user = new User(); User::setCurrentUser($user); $calendar2 = new Calendar(); $this->assertCount(1, $calendar2->getUsers(), 'new calendar with current user should have a user'); $this->assertSame($user, $calendar2->getUsers()[0], 'new calendar with current user should have a user'); }
/** * If the AUTHORIZATION HTTP header is found, validate and return the user, otherwise default to 'guest' * @param \ZF\MvcAuth\MvcAuthEvent $e * @return \Application\Authentication\AuthenticatedIdentity|\ZF\MvcAuth\Identity\GuestIdentity */ public function __invoke(\ZF\MvcAuth\MvcAuthEvent $e) { $guest = new \ZF\MvcAuth\Identity\GuestIdentity(); $header = $e->getMvcEvent()->getRequest()->getHeader('AUTHORIZATION'); if (!$header) { return $guest; } $token = $header->getFieldValue(); $jwt = new \OAuth2\Encryption\Jwt(); $key = $this->config['cryptoKey']; $tokenData = $jwt->decode($token, $key); // If the token is invalid, give up if (!$tokenData) { return $guest; } $user = $this->entityManager->getRepository(\Application\Model\User::class)->findOneById($tokenData['id']); if (!$user) { return $guest; } \Application\Model\User::setCurrentUser($user); $identity = new \Application\Authentication\AuthenticatedIdentity($user); return $identity; }
public function setUser(User $user = null) { $this->user = $user; \Application\Model\User::setCurrentUser($user); }