sintonia/airtime_mvc/application/models/LoginAttempts.php
paul.baranowski 7f78a7f663 CC-1927: Remove PEAR DB
First pass through the model classes to remove use of $CC_DBC.
Web application is working.
There are still other parts of the app that use PEAR DB.
2012-04-19 16:33:05 -04:00

36 lines
No EOL
1.2 KiB
PHP

<?php
class Application_Model_LoginAttempts {
public function __construct(){
}
public static function increaseAttempts($ip){
$con = Propel::getConnection();
$sql = "select count(*) from cc_login_attempts WHERE ip='$ip'";
$res = $con->query($sql)->fetchColumn(0);
if ($res) {
$sql = "UPDATE cc_login_attempts SET attempts=attempts+1 WHERE ip='$ip'";
$con->exec($sql);
} else {
$sql = "INSERT INTO cc_login_attempts (ip, attempts) values ('$ip', '1')";
$con->exec($sql);
}
}
public static function getAttempts($ip){
$con = Propel::getConnection();
$sql = "select attempts from cc_login_attempts WHERE ip='$ip'";
$res = $con->query($sql)->fetchColumn(0);
return $res ? $res : 0;
}
public static function resetAttempts($ip){
$con = Propel::getConnection();
$sql = "select count(*) from cc_login_attempts WHERE ip='$ip'";
$res = $con->query($sql)->fetchColumn(0);
if ($res > 0) {
$sql = "DELETE FROM cc_login_attempts WHERE ip='$ip'";
$con->exec($sql);
}
}
}