SessionAuthGateway::log()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
rs 10
c 0
b 0
f 0
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
        $roles = $userModel->roles()->pluck('name')->toArray();
21
        return new User($userModel->uuid, $userModel->email, $userModel->firstname, $userModel->lastname, $userModel->organization_id, $userModel->path_picture, $roles, $userModel->providers);
22
    }
23
24
    public function log(User $u)
25
    {
26
        $authenticate = \App\User::where('uuid', $u->id())->first();
27
        Auth::login($authenticate, true);
28
    }
29
30
    public function wikiSessionId():? string
31
    {
32
        return Session::get('wiki_session_id');
33
    }
34
35
}
36