OauthController   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 14
c 1
b 0
f 0
dl 0
loc 62
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A actionConnect() 0 9 1
A actionCallback() 0 7 1
A actionDisconnect() 0 16 1
1
<?php
2
/**
3
 * @link      https://dukt.net/videos/
4
 * @copyright Copyright (c) Dukt
5
 * @license   https://github.com/dukt/videos/blob/v2/LICENSE.md
6
 */
7
8
namespace dukt\videos\controllers;
9
10
use Craft;
11
use craft\web\Controller;
12
use dukt\videos\Plugin as Videos;
13
use yii\base\InvalidConfigException;
14
use yii\web\Response;
15
16
/**
17
 * OAuth controller
18
 */
19
class OauthController extends Controller
20
{
21
    // Public Methods
22
    // =========================================================================
23
24
    /**
25
     * Connect.
26
     *
27
     * @return Response
28
     * @throws InvalidConfigException
29
     * @throws \craft\errors\MissingComponentException
30
     */
31
    public function actionConnect(): Response
32
    {
33
        $gatewayHandle = Craft::$app->getRequest()->getParam('gateway');
34
35
        $gateway = Videos::$plugin->getGateways()->getGateway($gatewayHandle, false);
36
37
        Craft::$app->getSession()->set('videos.oauthGateway', $gatewayHandle);
38
39
        return $gateway->oauthConnect();
40
    }
41
42
    /**
43
     * Callback.
44
     *
45
     * @return Response
46
     * @throws InvalidConfigException
47
     * @throws \craft\errors\MissingComponentException
48
     */
49
    public function actionCallback(): Response
50
    {
51
        $gatewayHandle = Craft::$app->getSession()->get('videos.oauthGateway');
52
53
        $gateway = Videos::$plugin->getGateways()->getGateway($gatewayHandle, false);
54
55
        return $gateway->oauthCallback();
56
    }
57
58
    /**
59
     * Disconnect.
60
     *
61
     * @return Response
62
     * @throws InvalidConfigException
63
     * @throws \craft\errors\MissingComponentException
64
     */
65
    public function actionDisconnect(): Response
66
    {
67
        $gatewayHandle = Craft::$app->getRequest()->getParam('gateway');
68
        $gateway = Videos::$plugin->getGateways()->getGateway($gatewayHandle, false);
69
70
        Videos::$plugin->getOauth()->deleteToken($gateway->getHandle());
71
72
        // set notice
73
        Craft::$app->getSession()->setNotice(Craft::t('videos', 'Disconnected.'));
74
75
76
        // redirect
77
78
        $redirect = Craft::$app->getRequest()->referrer;
79
80
        return $this->redirect($redirect);
81
    }
82
}
83