Add setting for recording IP address (#1221)
* Add setting for recording IP address * Record IP on registration
This commit is contained in:
@@ -54,6 +54,13 @@
|
|||||||
options: ''
|
options: ''
|
||||||
type: text
|
type: text
|
||||||
description: 'Enter your Google Analytics Tracking ID'
|
description: 'Enter your Google Analytics Tracking ID'
|
||||||
|
- key: general.record_user_ip
|
||||||
|
name: 'Record user IP address'
|
||||||
|
group: general
|
||||||
|
value: true
|
||||||
|
options: ''
|
||||||
|
type: boolean
|
||||||
|
description: Record the user's IP address on register/login
|
||||||
- key: units.currency
|
- key: units.currency
|
||||||
name: 'Currency'
|
name: 'Currency'
|
||||||
group: units
|
group: units
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ namespace App\Http\Controllers\Auth;
|
|||||||
use App\Contracts\Controller;
|
use App\Contracts\Controller;
|
||||||
use App\Exceptions\PilotIdNotFound;
|
use App\Exceptions\PilotIdNotFound;
|
||||||
use App\Models\Enums\UserState;
|
use App\Models\Enums\UserState;
|
||||||
|
use App\Models\User;
|
||||||
use App\Services\UserService;
|
use App\Services\UserService;
|
||||||
use Illuminate\Foundation\Auth\AuthenticatesUsers;
|
use Illuminate\Foundation\Auth\AuthenticatesUsers;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
@@ -104,11 +105,16 @@ class LoginController extends Controller
|
|||||||
*/
|
*/
|
||||||
protected function sendLoginResponse(Request $request)
|
protected function sendLoginResponse(Request $request)
|
||||||
{
|
{
|
||||||
|
/** @var User $user */
|
||||||
$user = Auth::user();
|
$user = Auth::user();
|
||||||
|
|
||||||
|
if (setting('general.record_user_ip', true)) {
|
||||||
|
$user->last_ip = $request->ip();
|
||||||
|
$user->save();
|
||||||
|
}
|
||||||
|
|
||||||
if ($user->state !== UserState::ACTIVE && $user->state !== UserState::ON_LEAVE) {
|
if ($user->state !== UserState::ACTIVE && $user->state !== UserState::ON_LEAVE) {
|
||||||
Log::info('Trying to login '.$user->ident.', state '
|
Log::info('Trying to login '.$user->ident.', state '.UserState::label($user->state));
|
||||||
.UserState::label($user->state));
|
|
||||||
|
|
||||||
// Log them out
|
// Log them out
|
||||||
$this->guard()->logout();
|
$this->guard()->logout();
|
||||||
|
|||||||
@@ -119,11 +119,16 @@ class RegisterController extends Controller
|
|||||||
*
|
*
|
||||||
* @return User
|
* @return User
|
||||||
*/
|
*/
|
||||||
protected function create(array $opts)
|
protected function create(Request $request): User
|
||||||
{
|
{
|
||||||
// Default options
|
// Default options
|
||||||
|
$opts = $request->all();
|
||||||
$opts['password'] = Hash::make($opts['password']);
|
$opts['password'] = Hash::make($opts['password']);
|
||||||
|
|
||||||
|
if (setting('general.record_user_ip', true)) {
|
||||||
|
$opts['last_ip'] = $request->ip();
|
||||||
|
}
|
||||||
|
|
||||||
// Convert transfer hours into minutes
|
// Convert transfer hours into minutes
|
||||||
if (isset($opts['transfer_time'])) {
|
if (isset($opts['transfer_time'])) {
|
||||||
$opts['transfer_time'] *= 60;
|
$opts['transfer_time'] *= 60;
|
||||||
@@ -158,7 +163,7 @@ class RegisterController extends Controller
|
|||||||
{
|
{
|
||||||
$this->validator($request->all())->validate();
|
$this->validator($request->all())->validate();
|
||||||
|
|
||||||
$user = $this->create($request->all());
|
$user = $this->create($request);
|
||||||
if ($user->state === UserState::PENDING) {
|
if ($user->state === UserState::PENDING) {
|
||||||
return view('auth.pending');
|
return view('auth.pending');
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,6 +34,7 @@ use Laratrust\Traits\LaratrustUserTrait;
|
|||||||
* @property int rank_id
|
* @property int rank_id
|
||||||
* @property string discord_id
|
* @property string discord_id
|
||||||
* @property int state
|
* @property int state
|
||||||
|
* @property string last_ip
|
||||||
* @property bool opt_in
|
* @property bool opt_in
|
||||||
* @property Pirep[] pireps
|
* @property Pirep[] pireps
|
||||||
* @property string last_pirep_id
|
* @property string last_pirep_id
|
||||||
@@ -82,6 +83,7 @@ class User extends Authenticatable
|
|||||||
'status',
|
'status',
|
||||||
'toc_accepted',
|
'toc_accepted',
|
||||||
'opt_in',
|
'opt_in',
|
||||||
|
'last_ip',
|
||||||
'created_at',
|
'created_at',
|
||||||
'updated_at',
|
'updated_at',
|
||||||
];
|
];
|
||||||
@@ -93,6 +95,7 @@ class User extends Authenticatable
|
|||||||
'api_key',
|
'api_key',
|
||||||
'discord_id',
|
'discord_id',
|
||||||
'password',
|
'password',
|
||||||
|
'last_ip',
|
||||||
'remember_token',
|
'remember_token',
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|||||||
@@ -107,6 +107,10 @@
|
|||||||
<td>Flight Time</td>
|
<td>Flight Time</td>
|
||||||
<td>@minutestotime($user->flight_time)</td>
|
<td>@minutestotime($user->flight_time)</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>IP Address</td>
|
||||||
|
<td>{{ $user->last_ip ?? '-' }}</td>
|
||||||
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td>Registered On</td>
|
<td>Registered On</td>
|
||||||
<td>{{ show_datetime($user->created_at) }}</td>
|
<td>{{ show_datetime($user->created_at) }}</td>
|
||||||
|
|||||||
Reference in New Issue
Block a user