From c6e51210f225f3fb60aaa04ffffacee044d737ad Mon Sep 17 00:00:00 2001 From: REJack Date: Tue, 1 Jan 2019 17:25:22 +0000 Subject: [PATCH] updated LoginAttempt Migration & Model - added user_agent db column - added user_agent check in Model --- .../Migrations/20181031063113_create_login_attempts.php | 3 +++ app/Models/Aauth/LoginAttemptModel.php | 8 ++++++++ 2 files changed, 11 insertions(+) diff --git a/app/Database/Migrations/20181031063113_create_login_attempts.php b/app/Database/Migrations/20181031063113_create_login_attempts.php index aebd0d6..35b8723 100644 --- a/app/Database/Migrations/20181031063113_create_login_attempts.php +++ b/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, diff --git a/app/Models/Aauth/LoginAttemptModel.php b/app/Models/Aauth/LoginAttemptModel.php index 0fa3bea..b2085ca 100644 --- a/app/Models/Aauth/LoginAttemptModel.php +++ b/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)));