Garbage-collect email/password/auth tokens. closes #217

This commit is contained in:
Toby Zerner
2015-12-05 15:24:05 +10:30
parent 3efd5fbcb0
commit 262dc70fe1

View File

@ -10,6 +10,9 @@
namespace Flarum\Http; namespace Flarum\Http;
use Flarum\Core\AuthToken;
use Flarum\Core\EmailToken;
use Flarum\Core\PasswordToken;
use Flarum\Foundation\Application; use Flarum\Foundation\Application;
use Zend\Diactoros\Server; use Zend\Diactoros\Server;
use Flarum\Foundation\AbstractServer as BaseAbstractServer; use Flarum\Foundation\AbstractServer as BaseAbstractServer;
@ -45,6 +48,12 @@ abstract class AbstractServer extends BaseAbstractServer
{ {
if ($this->hitsLottery()) { if ($this->hitsLottery()) {
AccessToken::whereRaw('last_activity <= ? - lifetime', [time()])->delete(); AccessToken::whereRaw('last_activity <= ? - lifetime', [time()])->delete();
$earliestToKeep = date('Y-m-d H:i:s', time() - 24 * 60 * 60);
EmailToken::where('created_at', '<=', $earliestToKeep)->delete();
PasswordToken::where('created_at', '<=', $earliestToKeep)->delete();
AuthToken::where('created_at', '<=', $earliestToKeep)->delete();
} }
} }