Issues (20)

src/Http/Controllers/TokenSenderController.php (13 issues)

Labels
Severity
1
<?php
2
3
namespace Imanghafoori\TokenizedLogin\Http\Controllers;
4
5
use Illuminate\Routing\Controller;
6
use Illuminate\Support\Facades\Validator;
7
use Imanghafoori\TokenizedLogin\Facades\AuthFacade;
8
use Imanghafoori\TokenizedLogin\Facades\TokenGeneratorFacade;
9
use Imanghafoori\TokenizedLogin\Facades\TokenSenderFacade;
10
use Imanghafoori\TokenizedLogin\Facades\TokenStoreFacade;
11
use Imanghafoori\TokenizedLogin\Facades\UserProviderFacade;
12
use Imanghafoori\TokenizedLogin\Http\ResponderFacade;
13
14
class TokenSenderController extends Controller
15
{
16
    public function loginWithToken()
17
    {
18
        $token = request('token');
19
        $uid = TokenStoreFacade::getUidByToken($token)->getOrSend(
0 ignored issues
show
The method getUidByToken() does not exist on Imanghafoori\TokenizedLo...acades\TokenStoreFacade. Since you implemented __callStatic, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

19
        $uid = TokenStoreFacade::/** @scrutinizer ignore-call */ getUidByToken($token)->getOrSend(
Loading history...
20
            [ResponderFacade::class, 'tokenNotFound']
21
        );
22
23
        AuthFacade::loginById($uid);
0 ignored issues
show
The method loginById() does not exist on Imanghafoori\TokenizedLogin\Facades\AuthFacade. Since you implemented __callStatic, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

23
        AuthFacade::/** @scrutinizer ignore-call */ 
24
                    loginById($uid);
Loading history...
24
25
        return ResponderFacade::loggedIn();
0 ignored issues
show
The method loggedIn() does not exist on Imanghafoori\TokenizedLogin\Http\ResponderFacade. Since you implemented __callStatic, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

25
        return ResponderFacade::/** @scrutinizer ignore-call */ loggedIn();
Loading history...
26
    }
27
28
    public function issueToken()
29
    {
30
        $email = request('email');
31
32
        $this->validateEmailIsValid();
33
        $this->checkUserIsGuest();
34
        // throttle the route
35
36
        // find user row in DB or Fail
37
        $user = UserProviderFacade::getUserByEmail($email)->getOrSend(
0 ignored issues
show
The method getUserByEmail() does not exist on Imanghafoori\TokenizedLo...ades\UserProviderFacade. Since you implemented __callStatic, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

37
        $user = UserProviderFacade::/** @scrutinizer ignore-call */ getUserByEmail($email)->getOrSend(
Loading history...
38
            [ResponderFacade::class, 'userNotFound']
39
        );
40
41
        // 1. stop block users
42
        if (UserProviderFacade::isBanned($user->id)) {
0 ignored issues
show
The method isBanned() does not exist on Imanghafoori\TokenizedLo...ades\UserProviderFacade. Since you implemented __callStatic, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

42
        if (UserProviderFacade::/** @scrutinizer ignore-call */ isBanned($user->id)) {
Loading history...
43
            return ResponderFacade::blockedUser();
0 ignored issues
show
The method blockedUser() does not exist on Imanghafoori\TokenizedLogin\Http\ResponderFacade. Since you implemented __callStatic, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

43
            return ResponderFacade::/** @scrutinizer ignore-call */ blockedUser();
Loading history...
44
        }
45
46
        // 2. generate token
47
        $token = TokenGeneratorFacade::generateToken();
0 ignored issues
show
The method generateToken() does not exist on Imanghafoori\TokenizedLo...es\TokenGeneratorFacade. Since you implemented __callStatic, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

47
        /** @scrutinizer ignore-call */ 
48
        $token = TokenGeneratorFacade::generateToken();
Loading history...
48
        // 3. save token
49
        TokenStoreFacade::saveToken($token, $user->id);
0 ignored issues
show
The method saveToken() does not exist on Imanghafoori\TokenizedLo...acades\TokenStoreFacade. Since you implemented __callStatic, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

49
        TokenStoreFacade::/** @scrutinizer ignore-call */ 
50
                          saveToken($token, $user->id);
Loading history...
50
        // 4. send token
51
        TokenSenderFacade::send($token, $user);
0 ignored issues
show
The method send() does not exist on Imanghafoori\TokenizedLo...cades\TokenSenderFacade. Since you implemented __callStatic, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

51
        TokenSenderFacade::/** @scrutinizer ignore-call */ 
52
                           send($token, $user);
Loading history...
52
        // 5. send Response
53
        return ResponderFacade::tokenSent();
0 ignored issues
show
The method tokenSent() does not exist on Imanghafoori\TokenizedLogin\Http\ResponderFacade. Since you implemented __callStatic, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

53
        return ResponderFacade::/** @scrutinizer ignore-call */ tokenSent();
Loading history...
54
    }
55
56
    private function validateEmailIsValid()
57
    {
58
        $v = Validator::make(request()->all(), ['email' => 'email|required']);
59
        if ($v->fails()) {
60
            ResponderFacade::emailNotValid()->throwResponse();
0 ignored issues
show
The method emailNotValid() does not exist on Imanghafoori\TokenizedLogin\Http\ResponderFacade. Since you implemented __callStatic, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

60
            ResponderFacade::/** @scrutinizer ignore-call */ 
61
                             emailNotValid()->throwResponse();
Loading history...
61
        }
62
    }
63
64
    private function checkUserIsGuest()
65
    {
66
        if (AuthFacade::check()) {
0 ignored issues
show
The method check() does not exist on Imanghafoori\TokenizedLogin\Facades\AuthFacade. Since you implemented __callStatic, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

66
        if (AuthFacade::/** @scrutinizer ignore-call */ check()) {
Loading history...
67
            ResponderFacade::youShouldBeGuest()->throwResponse();
0 ignored issues
show
The method youShouldBeGuest() does not exist on Imanghafoori\TokenizedLogin\Http\ResponderFacade. Since you implemented __callStatic, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

67
            ResponderFacade::/** @scrutinizer ignore-call */ 
68
                             youShouldBeGuest()->throwResponse();
Loading history...
68
        }
69
    }
70
}
71