|
|
|
@ -97,44 +97,39 @@ class LoginAttemptModel
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Provides a shared instance of the Query Builder. |
|
|
|
|
* Get Login Attempt |
|
|
|
|
* |
|
|
|
|
* @param string $table Table name |
|
|
|
|
* Get login attempt based on time and ip address |
|
|
|
|
* |
|
|
|
|
* @return BaseBuilder |
|
|
|
|
* @return integer |
|
|
|
|
*/ |
|
|
|
|
protected function builder(string $table = null) |
|
|
|
|
public function find() |
|
|
|
|
{ |
|
|
|
|
if ($this->builder instanceof BaseBuilder) |
|
|
|
|
$builder = $this->builder(); |
|
|
|
|
$builder->where('ip_address', $this->request->getIPAddress()); |
|
|
|
|
$builder->where('updated_at >=', date('Y-m-d H:i:s', strtotime('-' . $this->config->loginAttemptLimitTimePeriod))); |
|
|
|
|
|
|
|
|
|
if ($builder->countAllResults() !== 0) |
|
|
|
|
{ |
|
|
|
|
return $this->builder; |
|
|
|
|
return $builder->get()->getFirstRow()->count; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$table = empty($table) ? $this->table : $table; |
|
|
|
|
|
|
|
|
|
// Ensure we have a good db connection |
|
|
|
|
if (! $this->db instanceof BaseConnection) |
|
|
|
|
else |
|
|
|
|
{ |
|
|
|
|
$this->db = Database::connect($this->DBGroup); |
|
|
|
|
return 0; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$this->builder = $this->db->table($table); |
|
|
|
|
|
|
|
|
|
return $this->builder; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Update Login Attempt |
|
|
|
|
* Save Login Attempt |
|
|
|
|
* |
|
|
|
|
* @param integer $id Login attempt id |
|
|
|
|
* @param array $data Data array |
|
|
|
|
* Inserts or Updates Login Attempt |
|
|
|
|
* |
|
|
|
|
* @return BaseBuilder |
|
|
|
|
* @return boolean |
|
|
|
|
*/ |
|
|
|
|
public function update(int $id = null, array $data = null) |
|
|
|
|
public function save() |
|
|
|
|
{ |
|
|
|
|
$builder = $this->builder(); |
|
|
|
|
$ipAddress = $this->request->getIPAddress(); |
|
|
|
|
$builder = $this->builder(); |
|
|
|
|
$builder->where('ip_address', $ipAddress); |
|
|
|
|
$builder->where('updated_at >=', date('Y-m-d H:i:s', strtotime('-' . $this->config->loginAttemptLimitTimePeriod))); |
|
|
|
|
|
|
|
|
@ -144,6 +139,7 @@ class LoginAttemptModel
|
|
|
|
|
$data['count'] = 1; |
|
|
|
|
$data['created_at'] = date('Y-m-d H:i:s'); |
|
|
|
|
$data['updated_at'] = date('Y-m-d H:i:s'); |
|
|
|
|
|
|
|
|
|
$builder->insert($data); |
|
|
|
|
|
|
|
|
|
return true; |
|
|
|
@ -152,6 +148,7 @@ class LoginAttemptModel
|
|
|
|
|
{ |
|
|
|
|
$data['count'] = $row->count + 1; |
|
|
|
|
$data['updated_at'] = date('Y-m-d H:i:s'); |
|
|
|
|
|
|
|
|
|
$builder->update($data, ['id' => $row->id]); |
|
|
|
|
|
|
|
|
|
if ($data['count'] > $this->config->loginAttemptLimit) |
|
|
|
@ -166,44 +163,46 @@ class LoginAttemptModel
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Get Login Attempt |
|
|
|
|
* Delete login attempt. |
|
|
|
|
* |
|
|
|
|
* Get login attempt based on time and ip address |
|
|
|
|
* Delete login attempt based on time and ip address |
|
|
|
|
* |
|
|
|
|
* @return integer |
|
|
|
|
* @return BaseBuilder |
|
|
|
|
*/ |
|
|
|
|
public function get() |
|
|
|
|
public function delete() |
|
|
|
|
{ |
|
|
|
|
$builder = $this->builder(); |
|
|
|
|
$ipAddress = $this->request->getIPAddress(); |
|
|
|
|
$builder->where('ip_address', $ipAddress); |
|
|
|
|
$builder = $this->builder(); |
|
|
|
|
$builder->where('ip_address', $this->request->getIPAddress()); |
|
|
|
|
$builder->where('updated_at >=', date('Y-m-d H:i:s', strtotime('-' . $this->config->loginAttemptLimitTimePeriod))); |
|
|
|
|
|
|
|
|
|
if ($builder->countAllResults() !== 0) |
|
|
|
|
{ |
|
|
|
|
$row = $builder->get()->getFirstRow(); |
|
|
|
|
return $row->count; |
|
|
|
|
} |
|
|
|
|
else |
|
|
|
|
{ |
|
|
|
|
return 0; |
|
|
|
|
} |
|
|
|
|
return $builder->delete(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Delete login attempt. |
|
|
|
|
* Provides a shared instance of the Query Builder. |
|
|
|
|
* |
|
|
|
|
* Delete login attempt based on time and ip address |
|
|
|
|
* @param string $table Table name |
|
|
|
|
* |
|
|
|
|
* @return BaseBuilder |
|
|
|
|
*/ |
|
|
|
|
public function delete() |
|
|
|
|
protected function builder(string $table = null) |
|
|
|
|
{ |
|
|
|
|
$builder = $this->builder(); |
|
|
|
|
$ipAddress = $this->request->getIPAddress(); |
|
|
|
|
$builder->where('ip_address', $ipAddress); |
|
|
|
|
$builder->where('updated_at >=', date('Y-m-d H:i:s', strtotime('-' . $this->config->loginAttemptLimitTimePeriod))); |
|
|
|
|
if ($this->builder instanceof BaseBuilder) |
|
|
|
|
{ |
|
|
|
|
return $this->builder; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return $builder->delete(); |
|
|
|
|
$table = empty($table) ? $this->table : $table; |
|
|
|
|
|
|
|
|
|
// Ensure we have a good db connection |
|
|
|
|
if (! $this->db instanceof BaseConnection) |
|
|
|
|
{ |
|
|
|
|
$this->db = Database::connect($this->DBGroup); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$this->builder = $this->db->table($table); |
|
|
|
|
|
|
|
|
|
return $this->builder; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|