ChiefValidateInvite   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 9
dl 0
loc 28
rs 10
c 0
b 0
f 0
wmc 6

1 Method

Rating   Name   Duplication   Size   Complexity  
A handle() 0 19 6
1
<?php
2
3
namespace Thinktomorrow\Chief\App\Http\Middleware;
4
5
use Closure;
6
use Thinktomorrow\Chief\Admin\Users\Invites\Invitation;
7
use Thinktomorrow\Chief\Admin\Users\Invites\InvitationState;
8
9
class ChiefValidateInvite
10
{
11
    /**
12
     * Handle an incoming request.
13
     *
14
     * @param  \Illuminate\Http\Request  $request
15
     * @param  \Closure  $next
16
     * @return mixed
17
     */
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->getState(InvitationState::KEY), [InvitationState::accepted, InvitationState::revoked])) {
0 ignored issues
show
Bug introduced by
The constant Thinktomorrow\Chief\Admi...es\InvitationState::KEY was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
30
            // We allow the user to pass if the invitee is already logged in. Otherwise the invite link cannot be reused.
31
            if (! auth()->guard('chief')->check() || ! auth()->guard('chief')->user()->is($invitation->invitee)) {
0 ignored issues
show
Bug introduced by
The property invitee does not seem to exist on Illuminate\Database\Eloq...elations\HasManyThrough.
Loading history...
Bug introduced by
The property invitee does not seem to exist on Illuminate\Database\Eloq...Relations\HasOneThrough.
Loading history...
32
                return redirect()->route('invite.expired');
33
            }
34
        }
35
36
        return $next($request);
37
    }
38
}
39