Fix login mail handing, #5173

This commit is contained in:
James Cole 2021-10-13 05:57:11 +02:00
parent 98358f7578
commit 66303f614b
No known key found for this signature in database
GPG Key ID: BDE6667570EADBD5
4 changed files with 56 additions and 5 deletions

View File

@ -0,0 +1,44 @@
<?php
declare(strict_types=1);
/*
* ActuallyLoggedIn.php
* Copyright (c) 2021 james@firefly-iii.org
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
namespace FireflyIII\Events;
use FireflyIII\User;
use Illuminate\Queue\SerializesModels;
/**
* Class ActuallyLoggedIn
*/
class ActuallyLoggedIn extends Event
{
use SerializesModels;
public User $user;
/**
* @param User $user
*/
public function __construct(User $user)
{
$this->user = $user;
}
}

View File

@ -25,6 +25,7 @@ namespace FireflyIII\Handlers\Events;
use Carbon\Carbon;
use Exception;
use FireflyIII\Events\ActuallyLoggedIn;
use FireflyIII\Events\DetectedNewIPAddress;
use FireflyIII\Events\RegisteredUser;
use FireflyIII\Events\RequestedNewPassword;
@ -317,11 +318,9 @@ class UserEventHandler
}
/**
* @param Login $event
*
* @throws FireflyException
* @param ActuallyLoggedIn $event
*/
public function storeUserIPAddress(Login $event): void
public function storeUserIPAddress(ActuallyLoggedIn $event): void
{
Log::debug('Now in storeUserIPAddress');
/** @var User $user */
@ -337,7 +336,7 @@ class UserEventHandler
}
$inArray = false;
$ip = request()->ip();
Log::debug(sprintf('User logging in from IP address %s using guard "%s"', $ip, $event->guard));
Log::debug(sprintf('User logging in from IP address %s', $ip));
// update array if in array
foreach ($preference as $index => $row) {

View File

@ -25,6 +25,7 @@ namespace FireflyIII\Http\Controllers\Auth;
use Adldap;
use Cookie;
use DB;
use FireflyIII\Events\ActuallyLoggedIn;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Http\Controllers\Controller;
use FireflyIII\Providers\RouteServiceProvider;
@ -119,6 +120,10 @@ class LoginController extends Controller
// if you just logged in, it can't be that you have a valid 2FA cookie.
// send a custom login event because laravel will also fire a login event if a "remember me"-cookie
// restores the event.
event(new ActuallyLoggedIn($this->guard()->user()));
return $this->sendLoginResponse($request);
}
Log::warning('Login attempt failed.');

View File

@ -23,6 +23,7 @@ declare(strict_types=1);
namespace FireflyIII\Providers;
use Exception;
use FireflyIII\Events\ActuallyLoggedIn;
use FireflyIII\Events\AdminRequestedTestMessage;
use FireflyIII\Events\DestroyedTransactionGroup;
use FireflyIII\Events\DetectedNewIPAddress;
@ -74,6 +75,8 @@ class EventServiceProvider extends ServiceProvider
Login::class => [
'FireflyIII\Handlers\Events\UserEventHandler@checkSingleUserIsAdmin',
'FireflyIII\Handlers\Events\UserEventHandler@demoUserBackToEnglish',
],
ActuallyLoggedIn::class => [
'FireflyIII\Handlers\Events\UserEventHandler@storeUserIPAddress',
],
DetectedNewIPAddress::class => [