Skip to content

Commit

Permalink
Merge pull request #29 from benlumley/master
Browse files Browse the repository at this point in the history
Fix for null argument to lifetime not being considered.
  • Loading branch information
cesargb committed Oct 3, 2020
2 parents a1d0e9a + 7bcf9b0 commit b5f319c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/MagicLink.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,11 @@ public static function getValidMagicLinkByToken($token)

return self::where('id', $tokenId)
->where('token', $tokenSecret)
->where('available_at', '>=', Carbon::now())
->where(function ($query) {
$query
->whereNull('available_at')
->orWhere('available_at', '>=', Carbon::now());
})
->where(function ($query) {
$query
->whereNull('max_visits')
Expand Down
8 changes: 8 additions & 0 deletions tests/MagicLinkTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,14 @@ public function test_fails_when_date_is_expired()
->assertStatus(403);
}

public function test_ok_when_date_is_null()
{
$magiclink = MagicLink::create(new LoginAction(User::first()), null);

$this->get($magiclink->url)
->assertStatus(302);
}

public function test_fail_when_max_visits_completed()
{
$magiclink = MagicLink::create(new LoginAction(User::first()));
Expand Down

0 comments on commit b5f319c

Please sign in to comment.