Skip to content

Firefly III: a personal finances manager

Admin view will show some IP addresses.

James Cole1186e95c5177
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 @@
+<?php
+/**
+ * UserIsConfirmed.php
+ * Copyright (C) 2016 [email protected]
+ *
+ * This software may be modified and distributed under the terms
+ * of the MIT license. See the LICENSE file for details.
+ */
+
+declare(strict_types = 1);
+
+namespace FireflyIII\Events;
+
+use FireflyIII\User;
+use Illuminate\Queue\SerializesModels;
+
+/**
+ * Class UserIsConfirmed
+ *
+ * @package FireflyIII\Events
+ */
+class UserIsConfirmed extends Event
+{
+ use SerializesModels;
+
+ public $ipAddress;
+ public $user;
+
+ /**
+ * Create a new event instance.
+ *
+ * @param User $user
+ * @param string $ipAddress
+ */
+ public function __construct(User $user, string $ipAddress)
+ {
+ $this->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 @@
+<?php
+/**
+ * UserSaveIpAddress.php
+ * Copyright (C) 2016 [email protected]
+ *
+ * This software may be modified and distributed under the terms
+ * of the MIT license. See the LICENSE file for details.
+ */
+
+declare(strict_types = 1);
+
+namespace FireflyIII\Handlers\Events;
+
+use FireflyIII\Events\UserIsConfirmed;
+use FireflyIII\Events\UserRegistration;
+use FireflyIII\User;
+use Preferences;
+
+/**
+ * Class UserSaveIpAddress
+ *
+ * @package FireflyIII\Handlers\Events
+ */
+class UserSaveIpAddress
+{
+ /**
+ * Create the event listener.
+ *
+ */
+ public function __construct()
+ {
+ //
+ }
+
+ /**
+ * Handle the event.
+ *
+ * @param UserRegistration $event
+ *
+ * @return bool
+ */
+ public function saveFromRegistration(UserRegistration $event): bool
+ {
+ Preferences::setForUser($event->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 @@
<th colspan="2">&nbsp;</th>
<th>{{ trans('list.email') }}</th>
<th>{{ trans('list.registered_at') }}</th>
+ <th>{{ trans('list.registered_from') }}</th>
+ <th>{{ trans('list.confirmed_from') }}</th>
<th>{{ trans('list.is_admin') }}</th>
<th>{{ trans('list.has_two_factor') }}</th>
<th>{{ trans('list.is_activated') }}</th>
@@ -34,6 +36,12 @@
{{ user.created_at.formatLocalized(monthAndDayFormat) }}
{{ user.created_at.format('H:i') }}
</td>
+ <td>
+ {{ Preferences.getForUser(user,"registration_ip_address").data }}
+ </td>
+ <td>
+ {{ Preferences.getForUser(user,"confirmation_ip_address").data }}
+ </td>
<td>
{% if user.isAdmin %}
<small class="text-success"><i class="fa fa-fw fa-check"></i></small>