Add new sql table in update file

modifié:         core/lib/Thelia/Form/FirewallForm.php
	modifié:         setup/insert.sql
	modifié:         setup/update/2.0.3.sql
This commit is contained in:
Benjamin Perche
2014-07-16 08:50:50 +02:00
parent ee11915feb
commit 3469a56c17
3 changed files with 62 additions and 11 deletions

View File

@@ -23,28 +23,28 @@ use Thelia\Model\FormFirewallQuery;
abstract class FirewallForm extends BaseForm
{
/**
* Those values are for a "normal" security context
* Those values are for a "normal" security policy
*/
const DEFAULT_TIME_TO_WAIT = 1;
const DEFAULT_ATTEMPTS = 3;
const DEFAULT_ATTEMPTS = 6;
/** @var \Thelia\Model\FormFirewall */
protected static $cachedInstance;
protected $firewallInstance;
public function __construct(Request $request, $type = "form", $data = array(), $options = array())
{
parent::__construct($request, $type, $data, $options);
static::$cachedInstance = FormFirewallQuery::create()
$this->firewallInstance = FormFirewallQuery::create()
->filterByFormName($this->getName())
->filterByIpAddress($this->request->getClientIp())
->findOne()
;
parent::__construct($request, $type, $data, $options);
}
public function isFirewallOk()
{
if (null !== $firewallRow = &static::$cachedInstance) {
if ($this->isFirewallActive() && null !== $firewallRow = &$this->firewallInstance) {
/** @var \DateTime $lastRequestDateTime */
$lastRequestDateTime = $firewallRow->getUpdatedAt();
@@ -68,13 +68,12 @@ abstract class FirewallForm extends BaseForm
return false;
}
} else {
$firewallRow = (new FormFirewall())
$this->firewallInstance = $firewallRow = (new FormFirewall())
->setIpAddress($this->request->getClientIp())
->setFormName($this->getName())
;
$firewallRow->save();
static::$cachedInstance = $firewallRow;
}
return true;
@@ -99,4 +98,9 @@ abstract class FirewallForm extends BaseForm
{
return ConfigQuery::read("form_firewall_attempts", static::DEFAULT_ATTEMPTS);
}
public function isFirewallActive()
{
return ConfigQuery::read("form_firewall_active", true);
}
}