|
|
@ -104,20 +104,31 @@ class LoginAttemptModel |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public function find() |
|
|
|
public function find() |
|
|
|
{ |
|
|
|
{ |
|
|
|
$agent = $this->request->getUserAgent(); |
|
|
|
if ($this->config->loginAttemptCookie) |
|
|
|
$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))); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ($builder->countAllResults() !== 0) |
|
|
|
|
|
|
|
{ |
|
|
|
{ |
|
|
|
return $builder->get()->getFirstRow()->count; |
|
|
|
helper('cookie'); |
|
|
|
|
|
|
|
$cookieName = $this->config->loginAttemptCookie === true ? 'logins' : $this->config->lologinAttemptCookie; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ($cookie === get_cookie($cookieName)) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
return $cookie; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
else |
|
|
|
{ |
|
|
|
{ |
|
|
|
return 0; |
|
|
|
$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))); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ($builder->countAllResults() !== 0) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
return $builder->get()->getFirstRow()->count; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return 0; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
@ -129,40 +140,69 @@ class LoginAttemptModel |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public function save() |
|
|
|
public function save() |
|
|
|
{ |
|
|
|
{ |
|
|
|
$ipAddress = $this->request->getIPAddress(); |
|
|
|
if ($this->config->loginAttemptCookie) |
|
|
|
$agent = $this->request->getUserAgent(); |
|
|
|
|
|
|
|
$userAgent = md5($agent->getBrowser() . ' - ' . $agent->getVersion() . ' - ' . $agent->getPlatform()); |
|
|
|
|
|
|
|
$builder = $this->builder(); |
|
|
|
|
|
|
|
$builder->where('user_agent', $userAgent); |
|
|
|
|
|
|
|
$builder->where('ip_address', $ipAddress); |
|
|
|
|
|
|
|
$builder->where('updated_at >=', date('Y-m-d H:i:s', strtotime('-' . $this->config->loginAttemptLimitTimePeriod))); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (! $row = $builder->get()->getFirstRow()) |
|
|
|
|
|
|
|
{ |
|
|
|
{ |
|
|
|
$data['ip_address'] = $ipAddress; |
|
|
|
helper('cookie'); |
|
|
|
$data['user_agent'] = $userAgent; |
|
|
|
$cookieName = $this->config->loginAttemptCookie === true ? 'logins' : $this->config->lologinAttemptCookie; |
|
|
|
$data['count'] = 1; |
|
|
|
$expire = strtotime($this->config->loginAttemptLimitTimePeriod) - strtotime('now'); |
|
|
|
$data['created_at'] = date('Y-m-d H:i:s'); |
|
|
|
|
|
|
|
$data['updated_at'] = date('Y-m-d H:i:s'); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$builder->insert($data); |
|
|
|
if ($cookie = get_cookie($cookieName)) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
set_cookie($cookieName, $cookie + 1, $expire); |
|
|
|
|
|
|
|
|
|
|
|
return true; |
|
|
|
if ($cookie >= $this->config->loginAttemptLimit) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
return true; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
set_cookie($cookieName, 1, $expire); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return true; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
else |
|
|
|
{ |
|
|
|
{ |
|
|
|
$data['count'] = $row->count + 1; |
|
|
|
$ipAddress = $this->request->getIPAddress(); |
|
|
|
$data['updated_at'] = date('Y-m-d H:i:s'); |
|
|
|
$agent = $this->request->getUserAgent(); |
|
|
|
|
|
|
|
$userAgent = md5($agent->getBrowser() . ' - ' . $agent->getVersion() . ' - ' . $agent->getPlatform()); |
|
|
|
$builder->update($data, ['id' => $row->id]); |
|
|
|
$builder = $this->builder(); |
|
|
|
|
|
|
|
$builder->where('user_agent', $userAgent); |
|
|
|
|
|
|
|
$builder->where('ip_address', $ipAddress); |
|
|
|
|
|
|
|
$builder->where('updated_at >=', date('Y-m-d H:i:s', strtotime('-' . $this->config->loginAttemptLimitTimePeriod))); |
|
|
|
|
|
|
|
|
|
|
|
if ($data['count'] >= $this->config->loginAttemptLimit) |
|
|
|
if (! $row = $builder->get()->getFirstRow()) |
|
|
|
{ |
|
|
|
{ |
|
|
|
return false; |
|
|
|
$data['ip_address'] = $ipAddress; |
|
|
|
|
|
|
|
$data['user_agent'] = $userAgent; |
|
|
|
|
|
|
|
$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; |
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
else |
|
|
|
{ |
|
|
|
{ |
|
|
|
return true; |
|
|
|
$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) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
return true; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -176,13 +216,21 @@ class LoginAttemptModel |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public function delete() |
|
|
|
public function delete() |
|
|
|
{ |
|
|
|
{ |
|
|
|
$agent = $this->request->getUserAgent(); |
|
|
|
if ($this->config->loginAttemptCookie) |
|
|
|
$builder = $this->builder(); |
|
|
|
{ |
|
|
|
$builder->where('user_agent', md5($agent->getBrowser() . ' - ' . $agent->getVersion() . ' - ' . $agent->getPlatform())); |
|
|
|
helper('cookie'); |
|
|
|
$builder->where('ip_address', $this->request->getIPAddress()); |
|
|
|
$cookieName = $this->config->loginAttemptCookie === true ? 'logins' : $this->config->lologinAttemptCookie; |
|
|
|
$builder->where('updated_at >=', date('Y-m-d H:i:s', strtotime('-' . $this->config->loginAttemptLimitTimePeriod))); |
|
|
|
delete_cookie($cookieName); |
|
|
|
|
|
|
|
} |
|
|
|
$builder->delete(); |
|
|
|
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; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|