| Conditions | 6 |
| Paths | 5 |
| Total Lines | 20 |
| Code Lines | 8 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 9 |
| CRAP Score | 6 |
| Changes | 0 | ||
| 1 | <?php |
||
| 18 | public function handle($request, Closure $next) |
||
| 19 | { |
||
| 20 | // Verifies a valid signature and still outside expiration period |
||
| 21 | if (! $request->hasValidSignature()) { |
||
| 22 | return redirect()->route('invite.expired'); |
||
| 23 | } |
||
| 24 | |||
| 25 | if (! $invitation = Invitation::findByToken($request->token)) { |
||
| 26 | return redirect()->route('invite.expired'); |
||
| 27 | } |
||
| 28 | |||
| 29 | if (in_array($invitation->state(), [InvitationState::ACCEPTED, InvitationState::REVOKED])) { |
||
| 30 | |||
| 31 | // We allow the user to pass if the invitee is already logged in. Otherwise the invite link cannot be reused. |
||
| 32 | if (! auth()->guard('chief')->check() || ! auth()->guard('chief')->user()->is($invitation->invitee)) { |
||
| 33 | return redirect()->route('invite.expired'); |
||
| 34 | } |
||
| 35 | } |
||
| 36 | |||
| 37 | return $next($request); |
||
| 38 | } |
||
| 40 |