Completed
Push — master ( 33476c...427ebd )
by Bertrand
09:14
created

SessionAuthGateway   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 8
dl 0
loc 20
rs 10
c 0
b 0
f 0
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A current() 0 7 2
A log() 0 4 1
A wikiSessionId() 0 3 1
1
<?php
2
3
4
namespace App\Src\UseCases\Infra\Gateway;
5
6
7
use App\Src\UseCases\Domain\Shared\Gateway\AuthGateway;
8
use App\Src\UseCases\Domain\User;
9
use Illuminate\Support\Facades\Auth;
10
use Illuminate\Support\Facades\Session;
11
12
class SessionAuthGateway implements AuthGateway
13
{
14
    public function current(): ?User
15
    {
16
        $userModel = Auth::user();
17
        if(!isset($userModel)){
18
            return null;
19
        }
20
        return new User($userModel->uuid, $userModel->email, $userModel->firstname, $userModel->lastname, $userModel->organization_id);
21
    }
22
23
    public function log(User $u)
24
    {
25
        $authenticate = \App\User::where('uuid', $u->id())->first();
26
        Auth::login($authenticate, true);
27
    }
28
29
    public function wikiSessionId():? string
30
    {
31
        return Session::get('wiki_session_id');
32
    }
33
34
}
35