Skip to content

Commit 5a4e2c5

Browse files
committed
Update registration controllers
1 parent 3aed298 commit 5a4e2c5

6 files changed

Lines changed: 42 additions & 0 deletions

File tree

app/Http/Controllers/AdminInviteController.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,8 @@ function ($attribute, $value, $fail) {
212212
$user->email_verified_at = $invite->verify_email ? null : now();
213213
$user->birth_date = $birthDate;
214214
$user->admin_invite_id = $invite->id;
215+
$user->register_ip = $request->ip();
216+
$user->last_ip = $request->ip();
215217
$user->save();
216218

217219
$invite->increment('total_uses');

app/Http/Controllers/Auth/LoginController.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,8 @@ protected function sendLoginResponse(Request $request)
130130

131131
$user = $this->guard()->user();
132132

133+
$user->update(['last_ip' => $request->ip()]);
134+
133135
if (! $user->email_verified_at) {
134136
$this->guard()->logout();
135137

app/Http/Controllers/Auth/RegisterController.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ protected function create(array $data)
8080
'username' => $data['username'],
8181
'email' => $data['email'],
8282
'password' => Hash::make($data['password']),
83+
'register_ip' => request()->ip(),
84+
'last_ip' => request()->ip(),
8385
]);
8486
}
8587
}

app/Http/Controllers/UserRegisterVerifyController.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,8 @@ public function claimUsername(StoreRegisterUsernameRequest $request)
217217
$user->password = Hash::make($password);
218218
$user->email_verified_at = now();
219219
$user->birth_date = $birthDate;
220+
$user->register_ip = $request->ip();
221+
$user->last_ip = $request->ip();
220222
$user->save();
221223

222224
sleep(1);

app/Models/User.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,8 @@ class User extends Authenticatable implements OAuthenticatable
127127
'delete_after',
128128
'status',
129129
'admin_invite_id',
130+
'register_ip',
131+
'last_ip',
130132
];
131133

132134
protected $hidden = [
@@ -143,6 +145,8 @@ class User extends Authenticatable implements OAuthenticatable
143145
'last_active_at',
144146
'birth_date',
145147
'admin_invite_id',
148+
'register_ip',
149+
'last_ip',
146150
];
147151

148152
protected function casts(): array
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
use Illuminate\Database\Migrations\Migration;
4+
use Illuminate\Database\Schema\Blueprint;
5+
use Illuminate\Support\Facades\Schema;
6+
7+
return new class extends Migration
8+
{
9+
/**
10+
* Run the migrations.
11+
*/
12+
public function up(): void
13+
{
14+
Schema::table('users', function (Blueprint $table) {
15+
$table->string('register_ip')->nullable();
16+
$table->string('last_ip')->nullable();
17+
});
18+
}
19+
20+
/**
21+
* Reverse the migrations.
22+
*/
23+
public function down(): void
24+
{
25+
Schema::table('users', function (Blueprint $table) {
26+
$table->dropColumn('register_ip');
27+
$table->dropColumn('last_ip');
28+
});
29+
}
30+
};

0 commit comments

Comments
 (0)