Browse Source

Update username reminder to be sent to recipient

Will 4 years ago
parent
commit
997bfe72fc

+ 2 - 2
app/Http/Controllers/Auth/ForgotUsernameController.php

@@ -41,8 +41,8 @@ class ForgotUsernameController extends Controller
 
         $recipient = Recipient::all()->where('email', $request->email)->first();
 
-        if (isset($recipient->user)) {
-            $recipient->user->sendUsernameReminderNotification();
+        if (isset($recipient)) {
+            $recipient->sendUsernameReminderNotification();
         }
 
         return back()->with('status', 'A reminder has been sent if that email exists.');

+ 1 - 11
app/Notifications/UsernameReminder.php

@@ -11,16 +11,6 @@ class UsernameReminder extends Notification implements ShouldQueue
 {
     use Queueable;
 
-    /**
-     * Create a new notification instance.
-     *
-     * @return void
-     */
-    public function __construct()
-    {
-        //
-    }
-
     /**
      * Get the notification's delivery channels.
      *
@@ -43,7 +33,7 @@ class UsernameReminder extends Notification implements ShouldQueue
         return (new MailMessage)
             ->subject("AnonAddy Username Reminder")
             ->markdown('mail.username_reminder', [
-                'username' => $notifiable->username
+                'username' => $notifiable->user->username
             ])
             ->withSwiftMessage(function ($message) {
                 $message->getHeaders()

+ 11 - 0
app/Recipient.php

@@ -2,6 +2,7 @@
 
 namespace App;
 
+use App\Notifications\UsernameReminder;
 use App\Traits\HasEncryptedAttributes;
 use App\Traits\HasUuid;
 use Illuminate\Auth\Notifications\VerifyEmail;
@@ -103,6 +104,16 @@ class Recipient extends Model
         $this->notify(new VerifyEmail);
     }
 
+    /**
+     * Send the username reminder notification.
+     *
+     * @return void
+     */
+    public function sendUsernameReminderNotification()
+    {
+        $this->notify(new UsernameReminder);
+    }
+
     /**
      * Get the email address that should be used for verification.
      *

+ 0 - 11
app/User.php

@@ -2,7 +2,6 @@
 
 namespace App;
 
-use App\Notifications\UsernameReminder;
 use App\Traits\HasEncryptedAttributes;
 use App\Traits\HasUuid;
 use Illuminate\Contracts\Auth\MustVerifyEmail;
@@ -218,16 +217,6 @@ class User extends Authenticatable implements MustVerifyEmail
         return $this->aliases()->whereDoesntHave('recipients');
     }
 
-    /**
-     * Send the username reminder notification.
-     *
-     * @return void
-     */
-    public function sendUsernameReminderNotification()
-    {
-        $this->notify(new UsernameReminder);
-    }
-
     public function hasVerifiedDefaultRecipient()
     {
         return ! is_null($this->defaultRecipient->email_verified_at);

+ 4 - 2
tests/Feature/LoginTest.php

@@ -80,12 +80,14 @@ class LoginTest extends TestCase
     {
         Notification::fake();
 
+        $recipient = $this->user->recipients[0];
+
         $this->post('/username/email', [
-            'email' => $this->user->email
+            'email' => $recipient->email
         ]);
 
         Notification::assertSentTo(
-            $this->user,
+            $recipient,
             UsernameReminder::class
         );
     }