Skip to content
Browse files

Changing for use as a plugin, removal of PHP4 leftovers.

  • Loading branch information...
1 parent 81edeb9 commit 9e73c4e960468435d149207a8ae4750811e4a9b4 @chronon committed Aug 11, 2011
Showing with 27 additions and 29 deletions.
  1. +14 −15 controllers/components/attempt.php
  2. +13 −14 models/attempt.php
View
29 controllers/components/attempt.php
@@ -1,9 +1,9 @@
-<?php
+<?php
/**
* Attempt Component Class
- *
+ *
* Based on http://bakery.cakephp.org/articles/aep_/2006/11/04/brute-force-protection
- *
+ *
* @author Thomas Heymann
* @version 0.1
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
@@ -12,38 +12,37 @@
**/
class AttemptComponent extends Object {
- var $components = array(
+ public $components = array(
'RequestHandler'
- );
+ );
// Called before the Controller::beforeFilter().
// function initialize(&$controller, $options) {
// }
// Called after the Controller::beforeFilter() and before the controller action
- function startup(&$controller) {
- $this->controller =& $controller;
- $this->Attempt = ClassRegistry::init('Attempt');
+ public function startup($controller) {
+ $this->controller = $controller;
+ $this->Attempt = ClassRegistry::init('Attempt.Attempt');
}
-
+
public function count($action) {
return $this->Attempt->count($this->RequestHandler->getClientIP(), $action);
}
-
+
public function limit($action, $limit = 5) {
return $this->Attempt->limit($this->RequestHandler->getClientIP(), $action, $limit);
}
-
+
public function fail($action, $duration = '+10 minutes') {
return $this->Attempt->fail($this->RequestHandler->getClientIP(), $action, $duration);
}
-
+
public function reset($action) {
return $this->Attempt->reset($this->RequestHandler->getClientIP(), $action);
}
-
+
public function cleanup() {
return $this->Attempt->cleanup();
}
-}
-?>
+}
View
27 models/attempt.php
@@ -1,42 +1,41 @@
<?php
class Attempt extends AppModel {
- var $name = 'Attempt';
- var $displayField = 'ip';
-
+
+ public $displayField = 'ip';
+
public function count($ip, $action) {
return $this->find('count', array(
'conditions' => array(
'ip' => $ip,
'action' => $action,
'expires >' => date('Y-m-d H:i:s')
- )
- ));
+ )
+ ));
}
-
+
public function limit($ip, $action, $limit) {
return ($this->count($ip, $action) < $limit);
}
-
+
public function fail($ip, $action, $duration) {
$this->create(array(
'ip' => $ip,
'action' => $action,
- 'expires' => date('Y-m-d H:i:s', strtotime($duration)),
- ));
+ 'expires' => date('Y-m-d H:i:s', strtotime($duration))
+ ));
return $this->save();
}
-
+
public function reset($ip, $action) {
return $this->deleteAll(array(
'ip' => $ip,
'action' => $action
- ), false, false);
+ ),false, false);
}
-
+
public function cleanup() {
return $this->deleteAll(array(
'expires <' => date('Y-m-d H:i:s')
), false, false);
}
-}
-?>
+}

0 comments on commit 9e73c4e

Please sign in to comment.
Something went wrong with that request. Please try again.