Skip to content

Commit e48544b

Browse files
committed
Log ip addresses for users, threads and replies
1 parent 63584c9 commit e48544b

File tree

7 files changed

+52
-4
lines changed

7 files changed

+52
-4
lines changed

app/Lio/Accounts/User.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class User extends Entity implements UserInterface, RemindableInterface, Present
1919

2020
protected $table = 'users';
2121
protected $hidden = ['github_id', 'email', 'remember_token'];
22-
protected $fillable = ['email', 'name', 'github_url', 'github_id', 'image_url', 'is_banned'];
22+
protected $fillable = ['email', 'name', 'github_url', 'github_id', 'image_url', 'is_banned', 'ip'];
2323
protected $dates = ['deleted_at'];
2424

2525
protected $validationRules = [

app/Lio/Forum/Replies/Reply.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class Reply extends Entity implements PresenterInterface
99
use SoftDeletingTrait;
1010

1111
protected $table = 'forum_replies';
12-
protected $fillable = ['body', 'author_id', 'thread_id'];
12+
protected $fillable = ['body', 'author_id', 'thread_id', 'ip'];
1313
protected $with = ['author'];
1414
protected $dates = ['deleted_at'];
1515

app/Lio/Forum/Threads/Thread.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class Thread extends Entity implements PresenterInterface
1111
use SoftDeletingTrait;
1212

1313
protected $table = 'forum_threads';
14-
protected $fillable = ['subject', 'body', 'author_id', 'is_question', 'solution_reply_id', 'category_slug', 'laravel_version'];
14+
protected $fillable = ['subject', 'body', 'author_id', 'is_question', 'solution_reply_id', 'category_slug', 'laravel_version', 'ip'];
1515
protected $dates = ['deleted_at'];
1616

1717
protected $validationRules = [

app/controllers/AuthController.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,10 @@ public function postSignupConfirm()
8080
->withErrors($validator->errors());
8181
}
8282

83-
return App::make('Lio\Accounts\UserCreator')->create($this, Session::get('userGithubData'));
83+
$data = Session::get('userGithubData');
84+
$data['ip'] = Request::ip();
85+
86+
return App::make('Lio\Accounts\UserCreator')->create($this, $data);
8487
}
8588

8689
/**

app/controllers/Forum/ForumRepliesController.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ public function postCreateReply($threadSlug)
4848
return App::make('Lio\Forum\Replies\ReplyCreator')->create($this, [
4949
'body' => Input::get('body'),
5050
'author' => Auth::user(),
51+
'ip' => Request::ip(),
5152
], $thread->id, new ReplyForm);
5253
}
5354

app/controllers/Forum/ForumThreadsController.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ public function postCreateThread()
110110
'laravel_version' => Input::get('laravel_version'),
111111
'is_question' => Input::get('is_question'),
112112
'tags' => $this->tags->getTagsByIds(Input::get('tags')),
113+
'ip' => Request::ip(),
113114
], new ThreadForm);
114115
}
115116

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
3+
use Illuminate\Database\Schema\Blueprint;
4+
use Illuminate\Database\Migrations\Migration;
5+
6+
class CreateIpColumns extends Migration
7+
{
8+
/**
9+
* Run the migrations.
10+
*
11+
* @return void
12+
*/
13+
public function up()
14+
{
15+
Schema::table('users', function (Blueprint $table) {
16+
$table->string('ip', 100);
17+
});
18+
Schema::table('forum_threads', function (Blueprint $table) {
19+
$table->string('ip', 100);
20+
});
21+
Schema::table('forum_replies', function (Blueprint $table) {
22+
$table->string('ip', 100);
23+
});
24+
}
25+
26+
/**
27+
* Reverse the migrations.
28+
*
29+
* @return void
30+
*/
31+
public function down()
32+
{
33+
Schema::table('users', function (Blueprint $table) {
34+
$table->dropColumn('ip');
35+
});
36+
Schema::table('forum_threads', function (Blueprint $table) {
37+
$table->dropColumn('ip');
38+
});
39+
Schema::table('forum_replies', function (Blueprint $table) {
40+
$table->dropColumn('ip');
41+
});
42+
}
43+
}

0 commit comments

Comments
 (0)