소스 검색

Update username reminder to be sent to recipient

Will 4 년 전
부모
커밋
997bfe72fc
5개의 변경된 파일18개의 추가작업 그리고 26개의 파일을 삭제
  1. 2 2
      app/Http/Controllers/Auth/ForgotUsernameController.php
  2. 1 11
      app/Notifications/UsernameReminder.php
  3. 11 0
      app/Recipient.php
  4. 0 11
      app/User.php
  5. 4 2
      tests/Feature/LoginTest.php

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

@@ -41,8 +41,8 @@ class ForgotUsernameController extends Controller
 
 
         $recipient = Recipient::all()->where('email', $request->email)->first();
         $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.');
         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;
     use Queueable;
 
 
-    /**
-     * Create a new notification instance.
-     *
-     * @return void
-     */
-    public function __construct()
-    {
-        //
-    }
-
     /**
     /**
      * Get the notification's delivery channels.
      * Get the notification's delivery channels.
      *
      *
@@ -43,7 +33,7 @@ class UsernameReminder extends Notification implements ShouldQueue
         return (new MailMessage)
         return (new MailMessage)
             ->subject("AnonAddy Username Reminder")
             ->subject("AnonAddy Username Reminder")
             ->markdown('mail.username_reminder', [
             ->markdown('mail.username_reminder', [
-                'username' => $notifiable->username
+                'username' => $notifiable->user->username
             ])
             ])
             ->withSwiftMessage(function ($message) {
             ->withSwiftMessage(function ($message) {
                 $message->getHeaders()
                 $message->getHeaders()

+ 11 - 0
app/Recipient.php

@@ -2,6 +2,7 @@
 
 
 namespace App;
 namespace App;
 
 
+use App\Notifications\UsernameReminder;
 use App\Traits\HasEncryptedAttributes;
 use App\Traits\HasEncryptedAttributes;
 use App\Traits\HasUuid;
 use App\Traits\HasUuid;
 use Illuminate\Auth\Notifications\VerifyEmail;
 use Illuminate\Auth\Notifications\VerifyEmail;
@@ -103,6 +104,16 @@ class Recipient extends Model
         $this->notify(new VerifyEmail);
         $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.
      * Get the email address that should be used for verification.
      *
      *

+ 0 - 11
app/User.php

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

+ 4 - 2
tests/Feature/LoginTest.php

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