8000 Add filter to logout users which are banned · laravelio/laravel.io@6c80b59 · GitHub
[go: up one dir, main page]

Skip to content

Commit 6c80b59

Browse files
committed
Add filter to logout users which are banned
1 parent 06d00cd commit 6c80b59

File tree

3 files changed

+42
-3
lines changed

3 files changed

+42
-3
lines changed

app/Lio/Http/Filters/Banned.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
namespace Lio\Http\Filters;
3+
4+
use Illuminate\Auth\AuthManager;
5+
6+
class Banned
7+
{
8+
/**
9+
* @var \Illuminate\Auth\Guard
10+
*/
11+
private $auth;
12+
13+
/**
14+
* @param \Illuminate\Auth\AuthManager $auth
15+
*/
16+
public function __construct(AuthManager $auth)
17+
{
18+
$this->auth = $auth;
19+
}
20+
21+
/**
22+
* Logout the user if he's banned
23+
*
24+
* If the current authenticated user is banned and is trying
25+
* to access protected areas, log him out of the system.
26+
*
27+
* @return void
28+
*/
29+
public function filter()
30+
{
31+
if ($this->auth->check() && $this->auth->user()->is_banned) {
32+
$this->auth->logout();
33+
}
34+
}
35+
}
36+

app/controllers/Admin/UsersController.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,12 @@ public function postEdit($userId)
3535
$user = $this->users->requireById($userId);
3636

3737
$user->fill(Input::all());
38-
if ( ! Input::has('is_banned')) {
38+
39+
if (! Input::has('is_banned')) {
3940
$user->is_banned = 0;
4041
}
4142

42-
if ( ! $user->isValid()) {
43+
if (! $user->isValid()) {
4344
return $this->redirectBack(['errors' => $user->getErrors()]);
4445
}
4546

app/routes.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
Route::filter('banned', 'Lio\Http\Filters\Banned');
4+
35
Route::group(array('domain' => 'bin.laravel.io'), function() {
46
Route::get('{wildcard}', function($wildcard) {
57
return Redirect::to('http://laravel.io/bin/' . $wildcard);
@@ -69,7 +71,7 @@
6971
// Route::get('articles/search', 'ArticlesController@getSearch');
7072

7173
// forum
72-
Route::group(['before' => 'auth'], function() {
74+
Route::group(['before' => 'auth|banned'], function() {
7375
Route::get('forum/create-thread', 'ForumThreadsController@getCreateThread');
7476
Route::post('forum/create-thread', 'ForumThreadsController@postCreateThread');
7577

0 commit comments

Comments
 (0)
0