Admin view will show some IP addresses.

Signed-off-by: James Cole <thegrumpydictator@gmail.com>
This commit is contained in:
James Cole
2016-08-03 20:57:01 +02:00
parent d870e0f42e
commit 1186e95c51
7 changed files with 125 additions and 2 deletions

View File

@@ -0,0 +1,40 @@
<?php
/**
* UserIsConfirmed.php
* Copyright (C) 2016 thegrumpydictator@gmail.com
*
* 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;
}
}

View File

@@ -0,0 +1,62 @@
<?php
/**
* UserSaveIpAddress.php
* Copyright (C) 2016 thegrumpydictator@gmail.com
*
* 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;
}
}

View File

@@ -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')));

View File

@@ -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',

View File

@@ -142,6 +142,7 @@ return [
'Route',
'Auth',
'Lang',
'Preferences',
'URL',
'Config',
'ExpandedForm' => [

View File

@@ -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',

View File

@@ -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>