Bristol SU Support Package
CheckDatabaseUserOwnsControlUser.php
Go to the documentation of this file.
1 <?php
2 
4 
8 use Closure;
12 
17 {
18 
25 
31  private $authentication;
32 
40  {
41  $this->userAuthentication = $userAuthentication;
42  $this->authentication = $authentication;
43  }
44 
53  public function handle(Request $request, \Closure $next)
54  {
55  if ($this->hasUsers() && !$this->usersAreEqual()) {
56  throw new IncorrectLogin('Logged into incorrect user');
57  }
58 
59  return $next($request);
60  }
61 
67  private function hasUsers(): bool
68  {
69  return $this->userAuthentication->getUser() !== null && $this->authentication->getUser() !== null;
70  }
71 
72  private function usersAreEqual(): bool
73  {
74  return $this->userAuthentication->getUser()->controlUser()->id() === $this->authentication->getUser()->id();
75  }
76 }
__construct(UserAuthentication $userAuthentication, Authentication $authentication)