Skip to content

Commit

Permalink
Merge pull request #30 from Saeven/feature/travis-change
Browse files Browse the repository at this point in the history
Added method to helper, requireIdentity
  • Loading branch information
Saeven authored Dec 12, 2017
2 parents 869b8bc + e0a78ca commit c7e864f
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Spec\CirclicalUser\Controller\Plugin;

use CirclicalUser\Exception\UserRequiredException;
use CirclicalUser\Provider\UserInterface as User;
use CirclicalUser\Service\AccessService;
use CirclicalUser\Service\AuthenticationService;
Expand Down Expand Up @@ -49,4 +50,16 @@ public function it_creates_users($authenticationService, $newUser)
$authenticationService->create($newUser, 'userA', '123')->shouldBeCalled();
$this->create($newUser, 'userA', '123');
}

public function it_fails_on_require_when_there_is_no_auth(AuthenticationService $authenticationService)
{
$authenticationService->getIdentity()->willReturn(null);
$this->shouldThrow(UserRequiredException::class)->during('requireIdentity');
}

public function it_succeeds_on_require_when_there_is_auth(AuthenticationService $authenticationService, User $user)
{
$authenticationService->getIdentity()->willReturn($user);
$this->requireIdentity()->shouldBe($user);
}
}
1 change: 0 additions & 1 deletion phpspec.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,4 @@ extensions:
- src
blacklist:
- src/CirclicalUser/Mapper
- src/CirclicalUser/Entity
- src/CirclicalUser/Exception
16 changes: 16 additions & 0 deletions src/CirclicalUser/Controller/Plugin/AuthenticationPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace CirclicalUser\Controller\Plugin;

use CirclicalUser\Exception\UserRequiredException;
use CirclicalUser\Provider\UserInterface as User;
use CirclicalUser\Service\AccessService;
use CirclicalUser\Service\AuthenticationService;
Expand Down Expand Up @@ -47,6 +48,21 @@ public function getIdentity()
return $this->authenticationService->getIdentity();
}

/**
* Get a user identity, or else!
* @return User|null
* @throws UserRequiredException
*/
public function requireIdentity()
{
$user = $this->authenticationService->getIdentity();
if (!$user) {
throw new UserRequiredException();
}

return $user;
}

/**
* Clear identity and reset tokens
*/
Expand Down
10 changes: 4 additions & 6 deletions src/CirclicalUser/Mapper/UserResetTokenMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,10 @@ public function invalidateUnusedTokens(AuthenticationRecordInterface $authentica
->set('r.status', UserResetTokenInterface::STATUS_INVALID)
->where('r.authentication = :authentication')
->andWhere('r.status = :status_unused')
->setParameters(
[
'authentication' => $authenticationRecord,
'status_unused' => UserResetTokenInterface::STATUS_UNUSED,
]
)
->setParameters([
'authentication' => $authenticationRecord,
'status_unused' => UserResetTokenInterface::STATUS_UNUSED,
])
->getQuery();

$query->execute();
Expand Down

0 comments on commit c7e864f

Please sign in to comment.