|
|
|
@ -103,6 +103,18 @@ class LoginAttemptModel
|
|
|
|
|
* @return integer |
|
|
|
|
*/ |
|
|
|
|
public function find() |
|
|
|
|
{ |
|
|
|
|
if ($this->config->loginAttemptCookie) |
|
|
|
|
{ |
|
|
|
|
helper('cookie'); |
|
|
|
|
$cookieName = $this->config->loginAttemptCookie === true ? 'logins' : $this->config->lologinAttemptCookie; |
|
|
|
|
|
|
|
|
|
if ($cookie === get_cookie($cookieName)) |
|
|
|
|
{ |
|
|
|
|
return $cookie; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
else |
|
|
|
|
{ |
|
|
|
|
$agent = $this->request->getUserAgent(); |
|
|
|
|
$builder = $this->builder(); |
|
|
|
@ -114,10 +126,9 @@ class LoginAttemptModel
|
|
|
|
|
{ |
|
|
|
|
return $builder->get()->getFirstRow()->count; |
|
|
|
|
} |
|
|
|
|
else |
|
|
|
|
{ |
|
|
|
|
return 0; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return 0; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
@ -128,6 +139,34 @@ class LoginAttemptModel
|
|
|
|
|
* @return boolean |
|
|
|
|
*/ |
|
|
|
|
public function save() |
|
|
|
|
{ |
|
|
|
|
if ($this->config->loginAttemptCookie) |
|
|
|
|
{ |
|
|
|
|
helper('cookie'); |
|
|
|
|
$cookieName = $this->config->loginAttemptCookie === true ? 'logins' : $this->config->lologinAttemptCookie; |
|
|
|
|
$expire = strtotime($this->config->loginAttemptLimitTimePeriod) - strtotime('now'); |
|
|
|
|
|
|
|
|
|
if ($cookie = get_cookie($cookieName)) |
|
|
|
|
{ |
|
|
|
|
set_cookie($cookieName, $cookie + 1, $expire); |
|
|
|
|
|
|
|
|
|
if ($cookie >= $this->config->loginAttemptLimit) |
|
|
|
|
{ |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
else |
|
|
|
|
{ |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
else |
|
|
|
|
{ |
|
|
|
|
set_cookie($cookieName, 1, $expire); |
|
|
|
|
|
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
else |
|
|
|
|
{ |
|
|
|
|
$ipAddress = $this->request->getIPAddress(); |
|
|
|
|
$agent = $this->request->getUserAgent(); |
|
|
|
@ -166,6 +205,7 @@ class LoginAttemptModel
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Delete login attempt. |
|
|
|
@ -175,14 +215,22 @@ class LoginAttemptModel
|
|
|
|
|
* @return boolean |
|
|
|
|
*/ |
|
|
|
|
public function delete() |
|
|
|
|
{ |
|
|
|
|
if ($this->config->loginAttemptCookie) |
|
|
|
|
{ |
|
|
|
|
helper('cookie'); |
|
|
|
|
$cookieName = $this->config->loginAttemptCookie === true ? 'logins' : $this->config->lologinAttemptCookie; |
|
|
|
|
delete_cookie($cookieName); |
|
|
|
|
} |
|
|
|
|
else |
|
|
|
|
{ |
|
|
|
|
$agent = $this->request->getUserAgent(); |
|
|
|
|
$builder = $this->builder(); |
|
|
|
|
$builder->where('user_agent', md5($agent->getBrowser() . ' - ' . $agent->getVersion() . ' - ' . $agent->getPlatform())); |
|
|
|
|
$builder->where('ip_address', $this->request->getIPAddress()); |
|
|
|
|
$builder->where('updated_at >=', date('Y-m-d H:i:s', strtotime('-' . $this->config->loginAttemptLimitTimePeriod))); |
|
|
|
|
|
|
|
|
|
$builder->delete(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|