diff --git a/app/Events/UserIsConfirmed.php b/app/Events/UserIsConfirmed.php new file mode 100644 index 0000000000..8313d835a0 --- /dev/null +++ b/app/Events/UserIsConfirmed.php @@ -0,0 +1,40 @@ +user = $user; + $this->ipAddress = $ipAddress; + } +} diff --git a/app/Handlers/Events/UserSaveIpAddress.php b/app/Handlers/Events/UserSaveIpAddress.php new file mode 100644 index 0000000000..5b34ebc6da --- /dev/null +++ b/app/Handlers/Events/UserSaveIpAddress.php @@ -0,0 +1,62 @@ +user, 'registration_ip_address', $event->ipAddress); + + return true; + } + + /** + * Handle the event. + * + * @param UserIsConfirmed $event + * + * @return bool + */ + public function saveFromConfirmation(UserIsConfirmed $event): bool + { + Preferences::setForUser($event->user, 'confirmation_ip_address', $event->ipAddress); + + return true; + } +} \ No newline at end of file diff --git a/app/Http/Controllers/Auth/ConfirmationController.php b/app/Http/Controllers/Auth/ConfirmationController.php index ef0a045fd3..ea45b5efb8 100644 --- a/app/Http/Controllers/Auth/ConfirmationController.php +++ b/app/Http/Controllers/Auth/ConfirmationController.php @@ -13,6 +13,7 @@ namespace FireflyIII\Http\Controllers\Auth; use Auth; use FireflyIII\Events\ResendConfirmation; +use FireflyIII\Events\UserIsConfirmed; use FireflyIII\Exceptions\FireflyException; use FireflyIII\Http\Controllers\Controller; use Illuminate\Http\Request; @@ -36,12 +37,13 @@ class ConfirmationController extends Controller } /** - * @param string $code + * @param Request $request + * @param string $code * * @return mixed * @throws FireflyException */ - public function doConfirmation(string $code) + public function doConfirmation(Request $request, string $code) { // check user_confirmed_last_mail @@ -51,6 +53,10 @@ class ConfirmationController extends Controller $maxDiff = config('firefly.confirmation_age'); if ($database === $code && ($now - $time <= $maxDiff)) { + + // trigger user registration event: + event(new UserIsConfirmed(Auth::user(), $request->ip())); + Preferences::setForUser(Auth::user(), 'user_confirmed', true); Preferences::setForUser(Auth::user(), 'user_confirmed_confirmed', time()); Session::flash('success', strval(trans('firefly.account_is_confirmed'))); diff --git a/app/Providers/EventServiceProvider.php b/app/Providers/EventServiceProvider.php index dc6e71565e..2758e7f0b6 100644 --- a/app/Providers/EventServiceProvider.php +++ b/app/Providers/EventServiceProvider.php @@ -62,6 +62,10 @@ class EventServiceProvider extends ServiceProvider 'FireflyIII\Handlers\Events\SendRegistrationMail', 'FireflyIII\Handlers\Events\AttachUserRole', 'FireflyIII\Handlers\Events\UserConfirmation@sendConfirmation', + 'FireflyIII\Handlers\Events\UserSaveIpAddress@saveFromRegistration', + ], + 'FireflyIII\Events\UserIsConfirmed' => [ + 'FireflyIII\Handlers\Events\UserSaveIpAddress@saveFromConfirmation', ], 'FireflyIII\Events\ResendConfirmation' => [ 'FireflyIII\Handlers\Events\UserConfirmation@resendConfirmation', diff --git a/config/twigbridge.php b/config/twigbridge.php index 2064bbf643..586f7f047e 100644 --- a/config/twigbridge.php +++ b/config/twigbridge.php @@ -142,6 +142,7 @@ return [ 'Route', 'Auth', 'Lang', + 'Preferences', 'URL', 'Config', 'ExpandedForm' => [ diff --git a/resources/lang/en_US/list.php b/resources/lang/en_US/list.php index 743b67adfa..193740c717 100644 --- a/resources/lang/en_US/list.php +++ b/resources/lang/en_US/list.php @@ -58,6 +58,8 @@ return [ 'is_blocked' => 'Is blocked', 'is_admin' => 'Is admin', 'has_two_factor' => 'Has 2FA', + 'confirmed_from' => 'Confirmed from', + 'registered_from' => 'Registered from', 'blocked_code' => 'Block code', 'domain' => 'Domain', 'registration_attempts' => 'Registration attempts', diff --git a/resources/views/admin/users/index.twig b/resources/views/admin/users/index.twig index 05bd5375f7..15cf943bcb 100644 --- a/resources/views/admin/users/index.twig +++ b/resources/views/admin/users/index.twig @@ -17,6 +17,8 @@   {{ trans('list.email') }} {{ trans('list.registered_at') }} + {{ trans('list.registered_from') }} + {{ trans('list.confirmed_from') }} {{ trans('list.is_admin') }} {{ trans('list.has_two_factor') }} {{ trans('list.is_activated') }} @@ -34,6 +36,12 @@ {{ user.created_at.formatLocalized(monthAndDayFormat) }} {{ user.created_at.format('H:i') }} + + {{ Preferences.getForUser(user,"registration_ip_address").data }} + + + {{ Preferences.getForUser(user,"confirmation_ip_address").data }} + {% if user.isAdmin %}