From 1dcb00b39fb5c5ab6d0b5dbc349d7b8abe274e0a Mon Sep 17 00:00:00 2001 From: DualFroz Date: Fri, 2 Oct 2026 16:39:14 +0200 Subject: [PATCH] fix(notifications): point the new login in-app url at account.security --- ...0000_fix_new_login_detected_in_app_url.php | 29 ++++++++++++++++++ database/seeders/EmailTemplateSeeder.php | 2 +- tests/Feature/Auth/LoginTest.php | 30 +++++++++++++++++++ 3 files changed, 60 insertions(+), 1 deletion(-) create mode 100644 database/migrations/2026_10_02_160000_fix_new_login_detected_in_app_url.php diff --git a/database/migrations/2026_10_02_160000_fix_new_login_detected_in_app_url.php b/database/migrations/2026_10_02_160000_fix_new_login_detected_in_app_url.php new file mode 100644 index 0000000..2541688 --- /dev/null +++ b/database/migrations/2026_10_02_160000_fix_new_login_detected_in_app_url.php @@ -0,0 +1,29 @@ +where('key', 'new_login_detected') + ->where('in_app_url', '{{ route("profile.security") }}') + ->update(['in_app_url' => '{{ route("account.security") }}']); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + DB::table('notification_templates') + ->where('key', 'new_login_detected') + ->where('in_app_url', '{{ route("account.security") }}') + ->update(['in_app_url' => '{{ route("profile.security") }}']); + } +}; diff --git a/database/seeders/EmailTemplateSeeder.php b/database/seeders/EmailTemplateSeeder.php index f3c75b5..2e2bcf6 100644 --- a/database/seeders/EmailTemplateSeeder.php +++ b/database/seeders/EmailTemplateSeeder.php @@ -30,7 +30,7 @@ class EmailTemplateSeeder extends Seeder 'mail_enabled' => 'force', 'in_app_enabled' => 'choice_off', 'edit_preference_message' => 'Alert me about new login attempts', - 'in_app_url' => '{{ route("profile.security") }}', + 'in_app_url' => '{{ route("account.security") }}', ], 'new_invoice_created' => [ 'subject' => 'New invoice created', diff --git a/tests/Feature/Auth/LoginTest.php b/tests/Feature/Auth/LoginTest.php index 365eb2f..3b5e91c 100644 --- a/tests/Feature/Auth/LoginTest.php +++ b/tests/Feature/Auth/LoginTest.php @@ -3,6 +3,7 @@ namespace Tests\Feature\Auth; use App\Livewire\Auth\Login; +use App\Models\NotificationTemplate; use App\Models\User; use Illuminate\Foundation\Testing\RefreshDatabase; use Illuminate\Support\Facades\Hash; @@ -56,6 +57,35 @@ class LoginTest extends TestCase $this->assertAuthenticated(); } + /** + * Test if a login from a new ip sends the in-app alert to a user who opted in + */ + public function test_can_login_with_in_app_new_login_alert_enabled() + { + $user = User::factory()->create([ + 'email' => 'tests@paymenter.org', + 'password' => Hash::make('password'), + ]); + + $user->notificationsPreferences()->create([ + 'notification_template_id' => NotificationTemplate::where('key', 'new_login_detected')->value('id'), + 'mail_enabled' => true, + 'in_app_enabled' => true, + ]); + + Livewire::test(Login::class) + ->set('email', 'tests@paymenter.org') + ->set('password', 'password') + ->call('submit') + ->assertHasNoErrors() + ->assertRedirect(route('dashboard')); + + $this->assertDatabaseHas('notifications', [ + 'user_id' => $user->id, + 'url' => route('account.security'), + ]); + } + /** * Test if the user can't login with valid credentials but wrong captcha */