Jelajahi Sumber

Fixed uppercase username issue

Will Browning 6 tahun lalu
induk
melakukan
2d21cd5381

+ 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:6,1')->only('verify', 'resend');
+        $this->middleware('throttle:1,300')->only('verify', 'resend');
     }
 
     /**

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

@@ -19,7 +19,7 @@ class RecipientController extends Controller
 
     public function store(StoreRecipientRequest $request)
     {
-        $recipient = user()->recipients()->create(['email' => $request->email]);
+        $recipient = user()->recipients()->create(['email' => strtolower($request->email)]);
 
         $recipient->sendEmailVerificationNotification();
 

+ 5 - 0
app/Http/Controllers/RecipientVerificationController.php

@@ -4,6 +4,11 @@ namespace App\Http\Controllers;
 
 class RecipientVerificationController extends Controller
 {
+    public function __construct()
+    {
+        $this->middleware('throttle:1,300');
+    }
+
     public function resend($id)
     {
         $recipient = user()->recipients()->findOrFail($id);

+ 1 - 1
app/Rules/NotBlacklisted.php

@@ -25,7 +25,7 @@ class NotBlacklisted implements Rule
      */
     public function passes($attribute, $value)
     {
-        return !in_array($value, config('anonaddy.blacklist'));
+        return !in_array(strtolower($value), config('anonaddy.blacklist'));
     }
 
     /**

+ 1 - 1
app/Rules/NotDeletedUsername.php

@@ -32,7 +32,7 @@ class NotDeletedUsername implements Rule
             })
             ->toArray();
 
-        return !in_array($value, $deletedUsernames);
+        return !in_array(strtolower($value), $deletedUsernames);
     }
 
     /**

+ 1 - 1
app/Rules/UniqueUserRecipient.php

@@ -35,7 +35,7 @@ class UniqueUserRecipient implements Rule
             })
             ->toArray();
 
-        return !in_array($value, $userRecipients);
+        return !in_array(strtolower($value), $userRecipients);
     }
 
     /**

+ 4 - 0
resources/views/auth/verify.blade.php

@@ -26,6 +26,10 @@
                         <a class="bg-cyan-400 w-full text-center hover:bg-cyan-300 text-cyan-900 font-bold py-3 px-4 rounded focus:shadow-outline no-underline mx-auto" href="{{ route('verification.resend') }}">
                             {{ __('Resend verification email') }}
                         </a>
+
+                        <p class="text-sm text-grey-600 mt-4 text-center w-full">
+                            You can resend once every 5 minutes.
+                        </p>
                     </div>
                 </div>
             </div>

+ 0 - 3
tests/Feature/ReceiveEmailTest.php

@@ -654,7 +654,6 @@ class ReceiveEmailTest extends TestCase
     public function it_can_forward_email_from_file_for_all_domains()
     {
         Mail::fake();
-        Notification::fake();
 
         Mail::assertNothingSent();
 
@@ -688,7 +687,5 @@ class ReceiveEmailTest extends TestCase
         Mail::assertQueued(ForwardEmail::class, function ($mail) {
             return $mail->hasTo($this->user->email);
         });
-
-        Notification::assertNothingSent();
     }
 }

+ 67 - 0
tests/Feature/RecipientsTest.php

@@ -6,8 +6,10 @@ use App\Alias;
 use App\AliasRecipient;
 use App\Recipient;
 use App\User;
+use Illuminate\Auth\Notifications\VerifyEmail;
 use Illuminate\Foundation\Testing\RefreshDatabase;
 use Illuminate\Support\Carbon;
+use Illuminate\Support\Facades\Notification;
 use Tests\TestCase;
 
 class RecipientsTest extends TestCase
@@ -113,6 +115,23 @@ class RecipientsTest extends TestCase
             ->assertJsonValidationErrors('email');
     }
 
+    /** @test */
+    public function user_can_not_create_the_same_recipient_in_uppercase()
+    {
+        factory(Recipient::class)->create([
+            'user_id' => $this->user->id,
+            'email' => 'johndoe@example.com'
+        ]);
+
+        $response = $this->json('POST', '/recipients', [
+            'email' => 'JOHNdoe@example.com'
+        ]);
+
+        $response
+            ->assertStatus(422)
+            ->assertJsonValidationErrors('email');
+    }
+
     /** @test */
     public function user_can_not_create_the_same_recipient_as_default()
     {
@@ -165,4 +184,52 @@ class RecipientsTest extends TestCase
         $this->assertCount(1, $this->user->recipients);
         $this->assertEquals($defaultRecipient->id, $this->user->defaultRecipient->id);
     }
+
+    /** @test */
+    public function user_can_resend_recipient_verification_email()
+    {
+        Notification::fake();
+
+        Notification::assertNothingSent();
+
+        $recipient = factory(Recipient::class)->create([
+            'user_id' => $this->user->id,
+            'email_verified_at' => null
+        ]);
+
+        $response = $this->get('/recipients/'.$recipient->id.'/email/resend');
+
+        $response->assertStatus(200);
+
+        Notification::assertSentTo(
+            $recipient,
+            VerifyEmail::class
+        );
+    }
+
+    /** @test */
+    public function user_must_wait_before_resending_recipient_verification_email()
+    {
+        Notification::fake();
+
+        Notification::assertNothingSent();
+
+        $recipient = factory(Recipient::class)->create([
+            'user_id' => $this->user->id,
+            'email_verified_at' => null
+        ]);
+
+        $response = $this->get('/recipients/'.$recipient->id.'/email/resend');
+
+        $response->assertStatus(200);
+
+        Notification::assertSentTo(
+            $recipient,
+            VerifyEmail::class
+        );
+
+        $response2 = $this->get('/recipients/'.$recipient->id.'/email/resend');
+
+        $response2->assertStatus(429);
+    }
 }

+ 38 - 0
tests/Feature/RegistrationTest.php

@@ -117,6 +117,24 @@ class RegistrationTest extends TestCase
         ]);
     }
 
+    /** @test */
+    public function user_cannot_register_with_uppercase_blacklisted_username()
+    {
+        $response = $this->post('/register', [
+            'username' => 'Www',
+            'email' => 'johndoe@example.com',
+            'email_confirmation' => 'johndoe@example.com',
+            'password' => 'mypassword',
+            'terms' => true,
+        ]);
+
+        $response->assertSessionHasErrors(['username']);
+
+        $this->assertDatabaseMissing('users', [
+            'username' => 'www'
+        ]);
+    }
+
     /** @test */
     public function user_cannot_register_with_deleted_username()
     {
@@ -136,4 +154,24 @@ class RegistrationTest extends TestCase
             'username' => 'johndoe'
         ]);
     }
+
+    /** @test */
+    public function user_cannot_register_with_uppercase_deleted_username()
+    {
+        DeletedUsername::create(['username' => 'johndoe']);
+
+        $response = $this->post('/register', [
+            'username' => 'joHndoe',
+            'email' => 'johndoe@example.com',
+            'email_confirmation' => 'johndoe@example.com',
+            'password' => 'mypassword',
+            'terms' => true,
+        ]);
+
+        $response->assertSessionHasErrors(['username']);
+
+        $this->assertDatabaseMissing('users', [
+            'username' => 'johndoe'
+        ]);
+    }
 }