Browse Source

updated LoginAttempt Migration & Model

- added user_agent db column
- added user_agent check in Model
v3-dev
REJack 6 years ago
parent
commit
c6e51210f2
No known key found for this signature in database
GPG Key ID: 4A44B48700429F46
  1. 3
      app/Database/Migrations/20181031063113_create_login_attempts.php
  2. 8
      app/Models/Aauth/LoginAttemptModel.php

3
app/Database/Migrations/20181031063113_create_login_attempts.php

@ -49,6 +49,9 @@ class Migration_create_login_attempts extends Migration
'constraint' => 39,
'default' => 0,
],
'user_agent' => [
'type' => 'TINYTEXT',
],
'count' => [
'type' => 'TINYINT',
'constraint' => 2,

8
app/Models/Aauth/LoginAttemptModel.php

@ -104,7 +104,9 @@ class LoginAttemptModel
*/
public function find()
{
$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)));
@ -128,13 +130,17 @@ class LoginAttemptModel
public function save()
{
$ipAddress = $this->request->getIPAddress();
$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;
$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');
@ -170,7 +176,9 @@ class LoginAttemptModel
*/
public function delete()
{
$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)));

Loading…
Cancel
Save