Completed
Push — master ( 424357...d1d6a1 )
by Nate
24:35 queued 09:39
created

AuthorizationController::verbs()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 0
cts 4
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 2
1
<?php
2
3
/**
4
 * @copyright  Copyright (c) Flipbox Digital Limited
5
 * @license    https://flipboxfactory.com/software/patron/license
6
 * @link       https://www.flipboxfactory.com/software/patron/
7
 */
8
9
namespace flipbox\patron\controllers;
10
11
use craft\helpers\ArrayHelper;
12
use flipbox\craft\ember\controllers\AbstractController;
13
use flipbox\craft\ember\filters\CallableFilter;
14
use flipbox\patron\actions\authorization\Callback;
15
use flipbox\patron\Patron;
16
17
/**
18
 * @author Flipbox Factory <[email protected]>
19
 * @since 1.0.0
20
 */
21
class AuthorizationController extends AbstractController
22
{
23
    /**
24
     * @inheritdoc
25
     */
26
    public function behaviors()
27
    {
28
        return ArrayHelper::merge(
29
            parent::behaviors(),
30
            [
31
                'redirect' => [
32
                    'class' => CallableFilter::class,
33
                    'actions' => [
34
                        'callback' => function () {
35
                            $redirectUrl = Patron::getInstance()->getSession()->getRedirectUrl();
36
                            Patron::getInstance()->getSession()->removeAll();
37
38
                            if ($redirectUrl) {
39
                                return $this->redirect($redirectUrl);
40
                            }
41
                        }
42
                    ]
43
                ]
44
            ]
45
        );
46
    }
47
48
    /**
49
     * @inheritdoc
50
     */
51
    protected function verbs(): array
52
    {
53
        return [
54
            'callback' => ['get']
55
        ];
56
    }
57
58
    /**
59
     * @inheritdoc
60
     */
61
    public function actions()
62
    {
63
        return [
64
            'callback' => [
65
                'class' => Callback::class,
66
                'checkAccess' => [$this, 'checkCallbackAccess']
67
            ]
68
        ];
69
    }
70
71
    /**
72
     * @return bool
73
     */
74
    public function checkCallbackAccess()
75
    {
76
        $this->requireLogin();
77
        return true;
78
    }
79
}
80