Skip to content

Commit

Permalink
Merge pull request #438 from barryo/1.6
Browse files Browse the repository at this point in the history
[FEATURE] Add support for Laravel 7.x
  • Loading branch information
eigan authored Mar 6, 2020
2 parents 03dd5ed + 6cb9751 commit 6f8085a
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 18 deletions.
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

```php
$scientist = new Scientist(
'Albert',
'Albert',
'Einstein'
);

Expand All @@ -36,7 +36,7 @@ EntityManager::flush();
* Password reminders implementation
* Doctrine console commands
* DoctrineExtensions supported
* Timestamps, Softdeletes and TablePrefix listeners
* Timestamps, Softdeletes and TablePrefix listeners

## Documentation

Expand All @@ -51,15 +51,16 @@ Version | Supported Laravel Versions
1.2.x | 5.2.x, 5.3.x
1.3.x | 5.4.x
~1.4.0 | 5.5.x
~1.4.3 | 5.6.x
~1.4.3 | 5.6.x
~1.4.8 | 5.7.x
~1.4.10 | 5.8.x
~1.5 | 6.x
~1.6 | 7.x

Require this package

```bash
composer require "laravel-doctrine/orm:1.5.*"
composer require "laravel-doctrine/orm:1.6.*"
```

Because of the auto package discovery feature Laravel 5.5 has, the ServiceProvider and Facades are automatically registered.
Expand Down
26 changes: 13 additions & 13 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,28 +16,28 @@
}
],
"require": {
"php": "^7.2",
"php": "^7.2.5",
"doctrine/orm": "^2.6|^2.7",
"doctrine/persistence": "^1.3",
"illuminate/auth": "^6.0",
"illuminate/console": "^6.0",
"illuminate/container": "^6.0",
"illuminate/contracts": "^6.0",
"illuminate/pagination": "^6.0",
"illuminate/routing": "^6.0",
"illuminate/support": "^6.0",
"illuminate/validation": "^6.0",
"illuminate/view": "^6.0",
"illuminate/auth": "^7.0",
"illuminate/console": "^7.0",
"illuminate/container": "^7.0",
"illuminate/contracts": "^7.0",
"illuminate/pagination": "^7.0",
"illuminate/routing": "^7.0",
"illuminate/support": "^7.0",
"illuminate/validation": "^7.0",
"illuminate/view": "^7.0",
"symfony/serializer": "^2.7|^3.0|^4.0|^5.0"
},
"require-dev": {
"phpunit/phpunit": "^7.0",
"mockery/mockery": "^1.0",
"barryvdh/laravel-debugbar": "~3.0",
"itsgoingd/clockwork": "~1.9",
"illuminate/log": "^6.0",
"illuminate/notifications": "^6.0",
"illuminate/queue": "^6.0"
"illuminate/log": "^7.0",
"illuminate/notifications": "^7.0",
"illuminate/queue": "^7.0"
},
"autoload": {
"psr-4": {
Expand Down
45 changes: 44 additions & 1 deletion src/Auth/Passwords/DoctrineTokenRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@ class DoctrineTokenRepository implements TokenRepositoryInterface
*/
protected $expires;

/**
* Minimum number of seconds before re-redefining the token.
*
* @var int
*/
protected $throttle;

/**
* Create a new token repository instance.
*
Expand All @@ -47,12 +54,13 @@ class DoctrineTokenRepository implements TokenRepositoryInterface
* @param string $hashKey
* @param int $expires
*/
public function __construct(Connection $connection, $table, $hashKey, $expires = 60)
public function __construct(Connection $connection, $table, $hashKey, $expires = 60, $throttle = 60)
{
$this->table = $table;
$this->hashKey = $hashKey;
$this->expires = $expires * 60;
$this->connection = $connection;
$this->throttle = $throttle;
}

/**
Expand Down Expand Up @@ -140,6 +148,41 @@ protected function tokenExpired($token)
return $expiresAt->isPast();
}

/**
* Determine if the given user recently created a password reset token.
*
* @param CanResetPassword $user
* @return bool
*/
public function recentlyCreatedToken(CanResetPassword $user)
{
$record = $this->getTable()
->select('*')
->from($this->table)
->where('email = :email')
->setParameter('email', $user->getEmailForPasswordReset())
->execute()->fetch();

return $record && $this->tokenRecentlyCreated($record['created_at']);
}

/**
* Determine if the token was recently created.
*
* @param string $createdAt
* @return bool
*/
protected function tokenRecentlyCreated($createdAt)
{
if ($this->throttle <= 0) {
return false;
}

return Carbon::parse($createdAt)->addSeconds(
$this->throttle
)->isFuture();
}

/**
* Delete a token record by token.
*
Expand Down
41 changes: 41 additions & 0 deletions tests/Auth/Passwords/DoctrineTokenRepositoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,47 @@ public function test_can_check_if_exists()
$this->assertTrue($this->repository->exists(new UserMock, 'token'));
}

public function test_can_check_if_recently_created_token()
{
$this->connection->shouldReceive('createQueryBuilder')
->once()
->andReturn($this->builder);

$this->builder->shouldReceive('select')
->once()
->with('*')
->andReturnSelf();

$this->builder->shouldReceive('from')
->once()
->with('password_resets')
->andReturnSelf();

$this->builder->shouldReceive('where')
->once()
->with('email = :email')
->andReturnSelf();

$this->builder->shouldReceive('setParameter')
->once()
->with('email', '[email protected]')
->andReturnSelf();

$this->builder->shouldReceive('execute')
->once()
->andReturnSelf();

$this->builder->shouldReceive('fetch')
->once()
->andReturn([
'email' => '[email protected]',
'token' => 'token',
'created_at' => Carbon::now()
]);

$this->assertTrue($this->repository->recentlyCreatedToken(new UserMock));
}

public function test_can_delete()
{
$this->connection->shouldReceive('createQueryBuilder')
Expand Down

0 comments on commit 6f8085a

Please sign in to comment.