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