1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* This program is free software: you can redistribute it and/or modify |
4
|
|
|
* it under the terms of the GNU General Public License as published by |
5
|
|
|
* the Free Software Foundation, either version 3 of the License, or |
6
|
|
|
* (at your option) any later version. |
7
|
|
|
* |
8
|
|
|
* This program is distributed in the hope that it will be useful, |
9
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
10
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
11
|
|
|
* GNU General Public License for more details. |
12
|
|
|
* |
13
|
|
|
* You should have received a copy of the GNU General Public License |
14
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
15
|
|
|
*/ |
16
|
|
|
|
17
|
|
|
namespace Filoucrackeur\Hubic\Controller\Backend; |
18
|
|
|
|
19
|
|
|
use Filoucrackeur\Hubic\Domain\Model\Account; |
20
|
|
|
use Filoucrackeur\Hubic\Service\HubicService; |
21
|
|
|
use TYPO3\CMS\Core\Messaging\AbstractMessage; |
22
|
|
|
use TYPO3\CMS\Extbase\Mvc\Controller\ActionController; |
23
|
|
|
use TYPO3\CMS\Extbase\Utility\LocalizationUtility; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Class AccountController |
27
|
|
|
*/ |
28
|
|
|
class AccountController extends ActionController |
29
|
|
|
{ |
30
|
|
|
/** |
31
|
|
|
* @var \Filoucrackeur\Hubic\Service\HubicService |
32
|
|
|
*/ |
33
|
|
|
protected $hubicService; |
34
|
|
|
|
35
|
|
|
public function indexAction(): void |
36
|
|
|
{ |
37
|
|
|
$this->view->assign('accounts', $this->hubicService->getAccounts()); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @param Account $account |
42
|
|
|
*/ |
43
|
|
|
public function showAction(Account $account): void |
44
|
|
|
{ |
45
|
|
|
if ($account->getAccessToken()) { |
46
|
|
|
$this->hubicService->setAccount($account); |
47
|
|
|
$this->view->assignMultiple([ |
48
|
|
|
'clientAccount' => $this->hubicService->getAccount(), |
49
|
|
|
'clientAccountQuota' => $this->hubicService->getAccountQuota(), |
50
|
|
|
'agreement' => $this->hubicService->getAgreement(), |
51
|
|
|
'links' => $this->hubicService->getAllLinks() |
52
|
|
|
]); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
$this->view->assign('account', $account); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* @param Account $account |
60
|
|
|
* @throws \TYPO3\CMS\Extbase\Mvc\Exception\StopActionException |
61
|
|
|
*/ |
62
|
|
|
public function refreshTokenAction(Account $account): void |
63
|
|
|
{ |
64
|
|
|
$this->hubicService->refreshToken($account); |
65
|
|
|
|
66
|
|
|
$this->forward('show', null, null, ['account' => $account]); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* @param Account $account |
71
|
|
|
*/ |
72
|
|
|
public function accessTokenAction(Account $account): void |
73
|
|
|
{ |
74
|
|
|
$this->hubicService->redirectUrlRequestToken($account); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* @param Account $account |
79
|
|
|
* @throws \RuntimeException |
80
|
|
|
* @throws \InvalidArgumentException |
81
|
|
|
* @throws \TYPO3\CMS\Extbase\Mvc\Exception\StopActionException |
82
|
|
|
*/ |
83
|
|
|
public function callbackAction(Account $account): void |
84
|
|
|
{ |
85
|
|
|
if ($this->hubicService->accessToken($account)) { |
86
|
|
|
$this->addFlashMessage(LocalizationUtility::translate('flashmessage.token_added', 'hubic'), |
87
|
|
|
LocalizationUtility::translate('flashmessage.authentication', 'hubic'), |
88
|
|
|
AbstractMessage::OK); |
89
|
|
|
} else { |
90
|
|
|
$this->addFlashMessage(LocalizationUtility::translate('flashmessage.missing_client_data', 'hubic'), |
91
|
|
|
LocalizationUtility::translate('flashmessage.authentication', 'hubic'), |
92
|
|
|
AbstractMessage::ERROR); |
93
|
|
|
} |
94
|
|
|
$this->forward('show', null, null, ['account' => $account]); |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* @param Account $account |
99
|
|
|
* @throws \InvalidArgumentException |
100
|
|
|
* @throws \TYPO3\CMS\Extbase\Mvc\Exception\StopActionException |
101
|
|
|
*/ |
102
|
|
|
public function deleteAction(Account $account): void |
103
|
|
|
{ |
104
|
|
|
$this->hubicService->delete($account); |
105
|
|
|
$this->addFlashMessage(LocalizationUtility::translate('flashmessage.account_deleted', 'hubic'), |
106
|
|
|
LocalizationUtility::translate('account', 'hubic'), |
107
|
|
|
AbstractMessage::OK); |
108
|
|
|
$this->forward('index'); |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* @param Account $account |
113
|
|
|
* @throws \InvalidArgumentException |
114
|
|
|
* @throws \TYPO3\CMS\Extbase\Mvc\Exception\StopActionException |
115
|
|
|
*/ |
116
|
|
|
public function unlinkAction(Account $account): void |
117
|
|
|
{ |
118
|
|
|
$this->hubicService->unlink($account); |
119
|
|
|
|
120
|
|
|
$this->addFlashMessage(LocalizationUtility::translate('flashmessage.account_unlinked', 'hubic'), |
121
|
|
|
LocalizationUtility::translate('account', 'hubic'), |
122
|
|
|
AbstractMessage::OK); |
123
|
|
|
$this->forward('index'); |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
/** |
127
|
|
|
* @param Account $account |
128
|
|
|
* @param string $uri |
129
|
|
|
* @throws \TYPO3\CMS\Extbase\Mvc\Exception\StopActionException |
130
|
|
|
*/ |
131
|
|
|
public function unlinkUriAction(Account $account, string $uri) |
132
|
|
|
{ |
133
|
|
|
$this->hubicService->setAccount($account); |
134
|
|
|
$this->hubicService->deleteLink($uri); |
135
|
|
|
$this->forward('show', null, null, ['account' => $account]); |
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
/** |
139
|
|
|
* @param HubicService $hubicService |
140
|
|
|
*/ |
141
|
|
|
public function injectHubicService(HubicService $hubicService): void |
142
|
|
|
{ |
143
|
|
|
$this->hubicService = $hubicService; |
144
|
|
|
} |
145
|
|
|
} |
146
|
|
|
|