Skip to content
Snippets Groups Projects
Commit 70b37d47 authored by JediKev's avatar JediKev
Browse files

cron: Clean Expired Passwd Resets

This adds functionality to clean expired password reset tokens on cron runs.
parent 1fdd6783
No related branches found
No related tags found
No related merge requests found
...@@ -176,6 +176,20 @@ extends VerySimpleModel { ...@@ -176,6 +176,20 @@ extends VerySimpleModel {
$this->updated = SqlFunction::NOW(); $this->updated = SqlFunction::NOW();
return parent::save($this->dirty || $refetch); return parent::save($this->dirty || $refetch);
} }
// Clean password reset tokens that have expired
static function cleanPwResets() {
global $cfg;
if (!$cfg || !($period = $cfg->getPwResetWindow())) // In seconds
return false;
return ConfigItem::objects()
->filter(array(
'namespace' => 'pwreset',
'updated__lt' => SqlFunction::NOW()->minus(SqlInterval::SECOND($period)),
))->delete();
}
} }
class OsticketConfig extends Config { class OsticketConfig extends Config {
......
...@@ -56,6 +56,11 @@ class Cron { ...@@ -56,6 +56,11 @@ class Cron {
DbSessionBackend::cleanup(); DbSessionBackend::cleanup();
} }
function CleanPwResets() {
require_once(INCLUDE_DIR.'class.config.php');
ConfigItem::cleanPwResets();
}
function MaybeOptimizeTables() { function MaybeOptimizeTables() {
// Once a week on a 5-minute cron // Once a week on a 5-minute cron
$chance = rand(1,2000); $chance = rand(1,2000);
...@@ -106,6 +111,7 @@ class Cron { ...@@ -106,6 +111,7 @@ class Cron {
self::TicketMonitor(); self::TicketMonitor();
self::PurgeLogs(); self::PurgeLogs();
self::CleanExpiredSessions(); self::CleanExpiredSessions();
self::CleanPwResets();
// Run file purging about every 10 cron runs // Run file purging about every 10 cron runs
if (mt_rand(1, 9) == 4) if (mt_rand(1, 9) == 4)
self::CleanOrphanedFiles(); self::CleanOrphanedFiles();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment