Skip to content

Commit 6f8085a

Browse files
authored
Merge pull request #438 from barryo/1.6
[FEATURE] Add support for Laravel 7.x
2 parents 03dd5ed + 6cb9751 commit 6f8085a

File tree

4 files changed

+103
-18
lines changed

4 files changed

+103
-18
lines changed

README.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
```php
1515
$scientist = new Scientist(
16-
'Albert',
16+
'Albert',
1717
'Einstein'
1818
);
1919

@@ -36,7 +36,7 @@ EntityManager::flush();
3636
* Password reminders implementation
3737
* Doctrine console commands
3838
* DoctrineExtensions supported
39-
* Timestamps, Softdeletes and TablePrefix listeners
39+
* Timestamps, Softdeletes and TablePrefix listeners
4040

4141
## Documentation
4242

@@ -51,15 +51,16 @@ Version | Supported Laravel Versions
5151
1.2.x | 5.2.x, 5.3.x
5252
1.3.x | 5.4.x
5353
~1.4.0 | 5.5.x
54-
~1.4.3 | 5.6.x
54+
~1.4.3 | 5.6.x
5555
~1.4.8 | 5.7.x
5656
~1.4.10 | 5.8.x
5757
~1.5 | 6.x
58+
~1.6 | 7.x
5859

5960
Require this package
6061

6162
```bash
62-
composer require "laravel-doctrine/orm:1.5.*"
63+
composer require "laravel-doctrine/orm:1.6.*"
6364
```
6465

6566
Because of the auto package discovery feature Laravel 5.5 has, the ServiceProvider and Facades are automatically registered.

composer.json

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,28 +16,28 @@
1616
}
1717
],
1818
"require": {
19-
"php": "^7.2",
19+
"php": "^7.2.5",
2020
"doctrine/orm": "^2.6|^2.7",
2121
"doctrine/persistence": "^1.3",
22-
"illuminate/auth": "^6.0",
23-
"illuminate/console": "^6.0",
24-
"illuminate/container": "^6.0",
25-
"illuminate/contracts": "^6.0",
26-
"illuminate/pagination": "^6.0",
27-
"illuminate/routing": "^6.0",
28-
"illuminate/support": "^6.0",
29-
"illuminate/validation": "^6.0",
30-
"illuminate/view": "^6.0",
22+
"illuminate/auth": "^7.0",
23+
"illuminate/console": "^7.0",
24+
"illuminate/container": "^7.0",
25+
"illuminate/contracts": "^7.0",
26+
"illuminate/pagination": "^7.0",
27+
"illuminate/routing": "^7.0",
28+
"illuminate/support": "^7.0",
29+
"illuminate/validation": "^7.0",
30+
"illuminate/view": "^7.0",
3131
"symfony/serializer": "^2.7|^3.0|^4.0|^5.0"
3232
},
3333
"require-dev": {
3434
"phpunit/phpunit": "^7.0",
3535
"mockery/mockery": "^1.0",
3636
"barryvdh/laravel-debugbar": "~3.0",
3737
"itsgoingd/clockwork": "~1.9",
38-
"illuminate/log": "^6.0",
39-
"illuminate/notifications": "^6.0",
40-
"illuminate/queue": "^6.0"
38+
"illuminate/log": "^7.0",
39+
"illuminate/notifications": "^7.0",
40+
"illuminate/queue": "^7.0"
4141
},
4242
"autoload": {
4343
"psr-4": {

src/Auth/Passwords/DoctrineTokenRepository.php

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,13 @@ class DoctrineTokenRepository implements TokenRepositoryInterface
3939
*/
4040
protected $expires;
4141

42+
/**
43+
* Minimum number of seconds before re-redefining the token.
44+
*
45+
* @var int
46+
*/
47+
protected $throttle;
48+
4249
/**
4350
* Create a new token repository instance.
4451
*
@@ -47,12 +54,13 @@ class DoctrineTokenRepository implements TokenRepositoryInterface
4754
* @param string $hashKey
4855
* @param int $expires
4956
*/
50-
public function __construct(Connection $connection, $table, $hashKey, $expires = 60)
57+
public function __construct(Connection $connection, $table, $hashKey, $expires = 60, $throttle = 60)
5158
{
5259
$this->table = $table;
5360
$this->hashKey = $hashKey;
5461
$this->expires = $expires * 60;
5562
$this->connection = $connection;
63+
$this->throttle = $throttle;
5664
}
5765

5866
/**
@@ -140,6 +148,41 @@ protected function tokenExpired($token)
140148
return $expiresAt->isPast();
141149
}
142150

151+
/**
152+
* Determine if the given user recently created a password reset token.
153+
*
154+
* @param CanResetPassword $user
155+
* @return bool
156+
*/
157+
public function recentlyCreatedToken(CanResetPassword $user)
158+
{
159+
$record = $this->getTable()
160+
->select('*')
161+
->from($this->table)
162+
->where('email = :email')
163+
->setParameter('email', $user->getEmailForPasswordReset())
164+
->execute()->fetch();
165+
166+
return $record && $this->tokenRecentlyCreated($record['created_at']);
167+
}
168+
169+
/**
170+
* Determine if the token was recently created.
171+
*
172+
* @param string $createdAt
173+
* @return bool
174+
*/
175+
protected function tokenRecentlyCreated($createdAt)
176+
{
177+
if ($this->throttle <= 0) {
178+
return false;
179+
}
180+
181+
return Carbon::parse($createdAt)->addSeconds(
182+
$this->throttle
183+
)->isFuture();
184+
}
185+
143186
/**
144187
* Delete a token record by token.
145188
*

tests/Auth/Passwords/DoctrineTokenRepositoryTest.php

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,47 @@ public function test_can_check_if_exists()
153153
$this->assertTrue($this->repository->exists(new UserMock, 'token'));
154154
}
155155

156+
public function test_can_check_if_recently_created_token()
157+
{
158+
$this->connection->shouldReceive('createQueryBuilder')
159+
->once()
160+
->andReturn($this->builder);
161+
162+
$this->builder->shouldReceive('select')
163+
->once()
164+
->with('*')
165+
->andReturnSelf();
166+
167+
$this->builder->shouldReceive('from')
168+
->once()
169+
->with('password_resets')
170+
->andReturnSelf();
171+
172+
$this->builder->shouldReceive('where')
173+
->once()
174+
->with('email = :email')
175+
->andReturnSelf();
176+
177+
$this->builder->shouldReceive('setParameter')
178+
->once()
179+
->with('email', '[email protected]')
180+
->andReturnSelf();
181+
182+
$this->builder->shouldReceive('execute')
183+
->once()
184+
->andReturnSelf();
185+
186+
$this->builder->shouldReceive('fetch')
187+
->once()
188+
->andReturn([
189+
'email' => '[email protected]',
190+
'token' => 'token',
191+
'created_at' => Carbon::now()
192+
]);
193+
194+
$this->assertTrue($this->repository->recentlyCreatedToken(new UserMock));
195+
}
196+
156197
public function test_can_delete()
157198
{
158199
$this->connection->shouldReceive('createQueryBuilder')

0 commit comments

Comments
 (0)