Completed
Push — development ( e6e1bd...086a60 )
by Claudio
05:26
created

AuthServiceProvider::recover()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
namespace App\Providers;
4
5
use App\Facades\Session;
6
use App\Models\User;
7
use Illuminate\Http\Request;
8
use Illuminate\Support\Facades\Config;
9
use Illuminate\Support\ServiceProvider;
10
11
/**
12
 * Class AuthServiceProvider
13
 * @package App\Providers
14
 */
15
class AuthServiceProvider extends ServiceProvider
16
{
17
    /**
18
     * Boot the authentication services for the application.
19
     * If an User is stored in the Session recover it
20
     * Only will recover if the Path() isn't the Authentcation Path
21
     *
22
     * @return void
23
     */
24
    public function boot()
25
    {
26
        $this->app['auth']->viaRequest('api', function ($request) {
27
            return $request->path() == 'api/public/authentication/login'
28
                ? $this->auth($request) : $this->recover($request);
29
        });
30
    }
31
32
    /**
33
     * Does the Authentication
34
     *
35
     * @param Request $request
36
     * @return User|null
37
     */
38
    protected function auth(Request $request)
39
    {
40
        return Session::set('ChocolateyWEB', User::where('mail', $request->json()->get('email'))
41
            ->where('password', hash(Config::get('chocolatey.security.hash'),
42
                $request->json()->get('password')))->first());
43
    }
44
45
    /**
46
     * Recover User Data
47
     *
48
     * @param Request $request
49
     * @return User|null
50
     */
51
    protected function recover(Request $request)
0 ignored issues
show
Unused Code introduced by
The parameter $request is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
52
    {
53
        return Session::get(Config::get('chocolatey.security.session')) ?? null;
54
    }
55
}
56