]> BookStack Code Mirror - bookstack/blob - app/Http/Controllers/Auth/HandlesPartialLogins.php
c7f3621517f58881febe1dc94e425de9d8290082
[bookstack] / app / Http / Controllers / Auth / HandlesPartialLogins.php
1 <?php
2
3 namespace BookStack\Http\Controllers\Auth;
4
5 use BookStack\Auth\Access\LoginService;
6 use BookStack\Auth\User;
7 use BookStack\Exceptions\NotFoundException;
8
9 trait HandlesPartialLogins
10 {
11     /**
12      * @throws NotFoundException
13      */
14     protected function currentOrLastAttemptedUser(): User
15     {
16         $loginService = app()->make(LoginService::class);
17         $user = auth()->user() ?? $loginService->getLastLoginAttemptUser();
18
19         if (!$user) {
20             throw new NotFoundException('A user for this action could not be found');
21         }
22
23         return $user;
24     }
25 }