/
EmailActivationThrottler.php
44 lines (37 loc) · 1.06 KB
/
EmailActivationThrottler.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<?php
/*
* This file is part of Flarum.
*
* For detailed copyright and license information, please view the
* LICENSE file that was distributed with this source code.
*/
namespace Flarum\User\Throttler;
use Carbon\Carbon;
use Flarum\Http\RequestUtil;
use Flarum\User\EmailToken;
use Psr\Http\Message\ServerRequestInterface;
/**
* Unactivated users can request a confirmation email,
* this throttler applies a timeout of 5 minutes between confirmation requests.
*/
class EmailActivationThrottler
{
public static $timeout = 300;
/**
* @return bool|void
*/
public function __invoke(ServerRequestInterface $request)
{
if ($request->getAttribute('routeName') !== 'users.confirmation.send') {
return;
}
$actor = RequestUtil::getActor($request);
if (EmailToken::query()
->where('user_id', $actor->id)
->where('email', $actor->email)
->where('created_at', '>=', Carbon::now()->subSeconds(self::$timeout))
->exists()) {
return true;
}
}
}