Skip to content

Commit ec8e5c7

Browse files
[5.x] Laravel 12 (#11433)
Co-authored-by: Jason Varga <[email protected]>
1 parent b35e734 commit ec8e5c7

File tree

5 files changed

+126
-15
lines changed

5 files changed

+126
-15
lines changed

.github/workflows/tests.yml

+3-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ jobs:
1717
strategy:
1818
matrix:
1919
php: [8.1, 8.2, 8.3, 8.4]
20-
laravel: [10.*, 11.*]
20+
laravel: [10.*, 11.*, 12.*]
2121
stability: [prefer-lowest, prefer-stable]
2222
os: [ubuntu-latest]
2323
include:
@@ -32,6 +32,8 @@ jobs:
3232
exclude:
3333
- php: 8.1
3434
laravel: 11.*
35+
- php: 8.1
36+
laravel: 12.*
3537
- php: 8.4
3638
laravel: 10.*
3739

composer.json

+6-6
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"composer/semver": "^3.4",
1515
"guzzlehttp/guzzle": "^6.3 || ^7.0",
1616
"james-heinrich/getid3": "^1.9.21",
17-
"laravel/framework": "^10.40 || ^11.34",
17+
"laravel/framework": "^10.40 || ^11.34 || ^12.0",
1818
"laravel/prompts": "^0.1.16 || ^0.2.0 || ^0.3.0",
1919
"league/commonmark": "^2.2",
2020
"league/csv": "^9.0",
@@ -23,12 +23,12 @@
2323
"michelf/php-smartypants": "^1.8.1",
2424
"nesbot/carbon": "^2.62.1 || ^3.0",
2525
"pixelfear/composer-dist-plugin": "^0.1.4",
26-
"rebing/graphql-laravel": "^9.7",
26+
"rebing/graphql-laravel": "^9.8",
2727
"rhukster/dom-sanitizer": "^1.0.6",
2828
"spatie/blink": "^1.3",
29-
"spatie/ignition": "^1.15",
29+
"spatie/ignition": "^1.15.1",
3030
"statamic/stringy": "^3.1.2",
31-
"stillat/blade-parser": "^1.10.1",
31+
"stillat/blade-parser": "^1.10.1 || ^2.0",
3232
"symfony/lock": "^6.4",
3333
"symfony/var-exporter": "^6.0",
3434
"symfony/yaml": "^6.0 || ^7.0",
@@ -42,8 +42,8 @@
4242
"google/cloud-translate": "^1.6",
4343
"laravel/pint": "1.16.0",
4444
"mockery/mockery": "^1.6.10",
45-
"orchestra/testbench": "^8.14 || ^9.2",
46-
"phpunit/phpunit": "^10.5.35",
45+
"orchestra/testbench": "^8.14 || ^9.2 || ^10.0",
46+
"phpunit/phpunit": "^10.5.35 || ^11.5.3",
4747
"spatie/laravel-ray": "^1.37"
4848
},
4949
"config": {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
<?php
2+
3+
namespace Statamic\Auth\Passwords;
4+
5+
use Illuminate\Auth\Passwords\DatabaseTokenRepository;
6+
use Illuminate\Contracts\Auth\CanResetPassword as CanResetPasswordContract;
7+
use Illuminate\Contracts\Hashing\Hasher as HasherContract;
8+
use Illuminate\Filesystem\Filesystem;
9+
use Illuminate\Support\Carbon;
10+
use Statamic\Facades\YAML;
11+
12+
/** @deprecated */
13+
class LaravelTwelveTokenRepository extends DatabaseTokenRepository
14+
{
15+
protected $path;
16+
17+
public function __construct(
18+
protected Filesystem $files,
19+
protected HasherContract $hasher,
20+
protected string $table,
21+
protected string $hashKey,
22+
protected int $expires = 3600,
23+
protected int $throttle = 60
24+
) {
25+
$this->path = storage_path("statamic/password_resets/$table.yaml");
26+
}
27+
28+
public function create(CanResetPasswordContract $user)
29+
{
30+
$email = $user->getEmailForPasswordReset();
31+
32+
$token = $this->createNewToken();
33+
34+
$this->insert($this->getPayload($email, $token));
35+
36+
return $token;
37+
}
38+
39+
protected function insert($payload)
40+
{
41+
$resets = $this->getResets();
42+
43+
$resets[$payload['email']] = [
44+
'token' => $payload['token'],
45+
'created_at' => $payload['created_at']->timestamp,
46+
];
47+
48+
$this->putResets($resets);
49+
}
50+
51+
public function delete(CanResetPasswordContract $user)
52+
{
53+
$this->putResets(
54+
$this->getResets()->forget($user->email())
55+
);
56+
}
57+
58+
public function deleteExpired()
59+
{
60+
$this->putResets($this->getResets()->reject(function ($item, $email) {
61+
return $this->tokenExpired($item['created_at']);
62+
}));
63+
}
64+
65+
public function exists(CanResetPasswordContract $user, $token)
66+
{
67+
$record = $this->getResets()->get($user->email());
68+
69+
return $record &&
70+
! $this->tokenExpired(Carbon::createFromTimestamp($record['created_at'], config('app.timezone')))
71+
&& $this->hasher->check($token, $record['token']);
72+
}
73+
74+
public function recentlyCreatedToken(CanResetPasswordContract $user)
75+
{
76+
$record = $this->getResets()->get($user->email());
77+
78+
return $record && parent::tokenRecentlyCreated($record['created_at']);
79+
}
80+
81+
protected function getResets()
82+
{
83+
if (! $this->files->exists($this->path)) {
84+
return collect();
85+
}
86+
87+
return collect(YAML::parse($this->files->get($this->path)));
88+
}
89+
90+
protected function putResets($resets)
91+
{
92+
if (! $this->files->isDirectory($dir = dirname($this->path))) {
93+
$this->files->makeDirectory($dir);
94+
}
95+
96+
$this->files->put($this->path, YAML::dump($resets->all()));
97+
}
98+
}

src/Auth/Passwords/PasswordBrokerManager.php

+13-2
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,23 @@ protected function createTokenRepository(array $config)
1515
$key = base64_decode(substr($key, 7));
1616
}
1717

18-
return new TokenRepository(
18+
if (version_compare(app()->version(), '12', '<')) {
19+
return new TokenRepository(
20+
$this->app['files'],
21+
$this->app['hash'],
22+
$config['table'],
23+
$key,
24+
$config['expire'],
25+
$config['throttle'] ?? 0
26+
);
27+
}
28+
29+
return new LaravelTwelveTokenRepository(
1930
$this->app['files'],
2031
$this->app['hash'],
2132
$config['table'],
2233
$key,
23-
$config['expire'],
34+
($config['expire'] ?? 60) * 60,
2435
$config['throttle'] ?? 0
2536
);
2637
}

tests/Auth/Protect/PasswordEntryTest.php

+6-6
Original file line numberDiff line numberDiff line change
@@ -110,16 +110,16 @@ public static function localPasswordProvider()
110110
{
111111
return [
112112
'string' => [
113-
'value' => 'the-local-password',
114-
'submitted' => 'the-local-password',
113+
'the-local-password',
114+
'the-local-password',
115115
],
116116
'array with single value' => [
117-
'value' => ['the-local-password'],
118-
'submitted' => 'the-local-password',
117+
['the-local-password'],
118+
'the-local-password',
119119
],
120120
'array with multiple values' => [
121-
'value' => ['first-local-password', 'second-local-password'],
122-
'submitted' => 'second-local-password',
121+
['first-local-password', 'second-local-password'],
122+
'second-local-password',
123123
],
124124
];
125125
}

0 commit comments

Comments
 (0)