Skip to content

Commit 8a679e9

Browse files
committed
chore: add log user info for auth middleware
Change-Id: I7998d35f9c0337ae8a9e01b93a9b3c889e3b0dc3
1 parent 36038fd commit 8a679e9

2 files changed

Lines changed: 42 additions & 0 deletions

File tree

app/Http/Middleware/Authenticate.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
**/
1414
use Closure;
1515
use Illuminate\Support\Facades\Auth;
16+
use Illuminate\Support\Facades\Log;
17+
use Illuminate\Support\Facades\Route;
1618
use Illuminate\Support\Facades\Session;
1719
use Illuminate\Support\Facades\Redirect;
1820
use Illuminate\Support\Facades\URL;
@@ -37,10 +39,40 @@ public function handle($request, Closure $next, $guard = null)
3739
Session::save();
3840
return Redirect::action('UserController@getLogin');
3941
}
42+
43+
// log debug info about the user and his request
44+
$url = $request->getRequestUri();
45+
$method = $request->getMethod();
46+
$current_user = Auth::user();
47+
Log::debug
48+
(
49+
sprintf
50+
(
51+
"Authenticate::handle method %s url %s current user %s (%s) groups %s",
52+
$method,
53+
$url,
54+
$current_user->getEmail(),
55+
$current_user->getId(),
56+
$current_user->getGroupsNice()
57+
)
58+
);
4059
$redirect = Session::get('backurl');
4160
if (!empty($redirect)) {
4261
Session::forget('backurl');
4362
Session::save();
63+
Log::debug
64+
(
65+
sprintf
66+
(
67+
"Authenticate::handle method %s url %s current user %s (%s) groups %s redirecting to %s",
68+
$method,
69+
$url,
70+
$current_user->getEmail(),
71+
$current_user->getId(),
72+
$current_user->getGroupsNice(),
73+
$redirect
74+
)
75+
);
4476
return Redirect::to($redirect);
4577
}
4678

app/libs/Auth/Models/User.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -831,6 +831,16 @@ public function getGroups()
831831
return $this->groups;
832832
}
833833

834+
public function getGroupsNice(): string
835+
{
836+
$groups = $this->getGroups();
837+
$res = [];
838+
foreach ($groups as $group) {
839+
$res[] = $group->getName();
840+
}
841+
return implode(', ', $res);
842+
}
843+
834844
/**
835845
* @return ApiScope[]
836846
*/

0 commit comments

Comments
 (0)