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
|
|
|
|