Ver código fonte

Updated verification email throttle

Will Browning 6 anos atrás
pai
commit
1272e1d9ae

+ 13 - 3
app/Console/Commands/ReceiveEmail.php

@@ -180,12 +180,22 @@ class ReceiveEmail extends Command
             // or pass number and if forwarded equals that no. then block?
         }
 
-        $alias = $user->aliases()->firstOrCreate([
+        $alias = $user->aliases()->firstOrNew([
             'email' => $recipient['local_part'] . '@' . $recipient['domain'],
             'local_part' => $recipient['local_part'],
             'domain' => $recipient['domain'],
             'domain_id' => $customDomainId
-        ])->refresh();
+        ]);
+
+        if (!isset($alias->id) && $user->hasExceededNewAliasLimit()) {
+            // New aliases per hour limit exceededs
+            $this->error('4.2.1 New aliases per hour limit exceeded for user ' . $user->username . '.');
+
+            exit(1);
+        } else {
+            $alias->save();
+            $alias->refresh();
+        }
 
         // This is simply a class that allows us to base64_encode all attachment data before serialization
         $emailData = new EmailData($this->parser);
@@ -222,7 +232,7 @@ class ReceiveEmail extends Command
 
                     exit(1);
                 }
-        );
+            );
     }
 
     protected function getParser($file)

+ 1 - 1
app/Http/Controllers/Auth/VerificationController.php

@@ -39,7 +39,7 @@ class VerificationController extends Controller
     {
         $this->middleware('auth');
         $this->middleware('signed')->only('verify');
-        $this->middleware('throttle:1,300')->only('verify', 'resend');
+        $this->middleware('throttle:1,5')->only('verify', 'resend');
     }
 
     /**

+ 1 - 1
app/Http/Controllers/RecipientVerificationController.php

@@ -6,7 +6,7 @@ class RecipientVerificationController extends Controller
 {
     public function __construct()
     {
-        $this->middleware('throttle:1,300');
+        $this->middleware('throttle:1,5');
     }
 
     public function resend($id)

+ 8 - 0
app/User.php

@@ -205,4 +205,12 @@ class User extends Authenticatable implements MustVerifyEmail
     {
         return ($this->bandwidth / $this->getBandwidthLimit()) > 0.9;
     }
+
+    public function hasExceededNewAliasLimit()
+    {
+        return $this
+                ->aliases()
+                ->where('created_at', '>=', now()->subHour())
+                ->count() >= 10; // TODO update for different plans
+    }
 }

+ 15 - 15
composer.lock

@@ -4771,16 +4771,16 @@
         },
         {
             "name": "phpunit/php-code-coverage",
-            "version": "7.0.5",
+            "version": "7.0.6",
             "source": {
                 "type": "git",
                 "url": "https://github.com/sebastianbergmann/php-code-coverage.git",
-                "reference": "aed67b57d459dcab93e84a5c9703d3deb5025dff"
+                "reference": "d471d0d2b529a67c6a722dd446c4ec90881ac315"
             },
             "dist": {
                 "type": "zip",
-                "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/aed67b57d459dcab93e84a5c9703d3deb5025dff",
-                "reference": "aed67b57d459dcab93e84a5c9703d3deb5025dff",
+                "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/d471d0d2b529a67c6a722dd446c4ec90881ac315",
+                "reference": "d471d0d2b529a67c6a722dd446c4ec90881ac315",
                 "shasum": ""
             },
             "require": {
@@ -4789,17 +4789,17 @@
                 "php": "^7.2",
                 "phpunit/php-file-iterator": "^2.0.2",
                 "phpunit/php-text-template": "^1.2.1",
-                "phpunit/php-token-stream": "^3.0.1",
+                "phpunit/php-token-stream": "^3.0.2",
                 "sebastian/code-unit-reverse-lookup": "^1.0.1",
-                "sebastian/environment": "^4.1",
+                "sebastian/environment": "^4.2.2",
                 "sebastian/version": "^2.0.1",
-                "theseer/tokenizer": "^1.1"
+                "theseer/tokenizer": "^1.1.3"
             },
             "require-dev": {
-                "phpunit/phpunit": "^8.0"
+                "phpunit/phpunit": "^8.2.2"
             },
             "suggest": {
-                "ext-xdebug": "^2.6.1"
+                "ext-xdebug": "^2.7.2"
             },
             "type": "library",
             "extra": {
@@ -4830,7 +4830,7 @@
                 "testing",
                 "xunit"
             ],
-            "time": "2019-06-06T12:28:18+00:00"
+            "time": "2019-07-08T05:29:42+00:00"
         },
         {
             "name": "phpunit/php-file-iterator",
@@ -4974,16 +4974,16 @@
         },
         {
             "name": "phpunit/php-token-stream",
-            "version": "3.0.1",
+            "version": "3.0.2",
             "source": {
                 "type": "git",
                 "url": "https://github.com/sebastianbergmann/php-token-stream.git",
-                "reference": "c99e3be9d3e85f60646f152f9002d46ed7770d18"
+                "reference": "c4a66b97f040e3e20b3aa2a243230a1c3a9f7c8c"
             },
             "dist": {
                 "type": "zip",
-                "url": "https://api.github.com/repos/sebastianbergmann/php-token-stream/zipball/c99e3be9d3e85f60646f152f9002d46ed7770d18",
-                "reference": "c99e3be9d3e85f60646f152f9002d46ed7770d18",
+                "url": "https://api.github.com/repos/sebastianbergmann/php-token-stream/zipball/c4a66b97f040e3e20b3aa2a243230a1c3a9f7c8c",
+                "reference": "c4a66b97f040e3e20b3aa2a243230a1c3a9f7c8c",
                 "shasum": ""
             },
             "require": {
@@ -5019,7 +5019,7 @@
             "keywords": [
                 "tokenizer"
             ],
-            "time": "2018-10-30T05:52:18+00:00"
+            "time": "2019-07-08T05:24:54+00:00"
         },
         {
             "name": "phpunit/phpunit",

Diferenças do arquivo suprimidas por serem muito extensas
+ 372 - 250
package-lock.json


+ 2 - 2
package.json

@@ -13,8 +13,8 @@
     "dependencies": {
         "axios": "^0.18.1",
         "cross-env": "^5.1",
-        "dayjs": "^1.8.14",
-        "laravel-mix": "^4.0.16",
+        "dayjs": "^1.8.15",
+        "laravel-mix": "^4.1.2",
         "laravel-mix-purgecss": "^4.1.0",
         "lodash": "^4.17.11",
         "portal-vue": "^2.1.5",

+ 6 - 1
resources/js/pages/Recipients.vue

@@ -410,7 +410,12 @@ export default {
         })
         .catch(error => {
           this.resendVerificationLoading = false
-          this.error()
+          console.log(error.response)
+          if (error.response.status === 429) {
+            this.error('You can only resend the email once every 5 minutes')
+          } else {
+            this.error()
+          }
         })
     },
     openDeleteModal(id) {

Alguns arquivos não foram mostrados porque muitos arquivos mudaram nesse diff