1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* This program is free software: you can redistribute it and/or modify |
5
|
|
|
* it under the terms of the GNU Lesser General Public License as published by |
6
|
|
|
* the Free Software Foundation, either version 3 of the License, or |
7
|
|
|
* (at your option) any later version. |
8
|
|
|
* |
9
|
|
|
* This program is distributed in the hope that it will be useful, |
10
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
11
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12
|
|
|
* GNU Lesser General Public License for more details. |
13
|
|
|
* |
14
|
|
|
* You should have received a copy of the GNU Lesser General Public License |
15
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
16
|
|
|
*/ |
17
|
|
|
|
18
|
|
|
namespace fkooman\RemoteStorage; |
19
|
|
|
|
20
|
|
|
use fkooman\RemoteStorage\Http\HtmlResponse; |
21
|
|
|
use fkooman\RemoteStorage\Http\RedirectResponse; |
22
|
|
|
use fkooman\RemoteStorage\Http\Request; |
23
|
|
|
use fkooman\RemoteStorage\OAuth\TokenStorage; |
24
|
|
|
|
25
|
|
|
class UiModule |
26
|
|
|
{ |
27
|
|
|
private $remoteStorage; |
28
|
|
|
|
29
|
|
|
/** @var TplInterface */ |
30
|
|
|
private $tpl; |
31
|
|
|
|
32
|
|
|
/** @var \fkooman\RemoteStorage\OAuth\TokenStorage */ |
33
|
|
|
private $tokenStorage; |
34
|
|
|
|
35
|
|
|
public function __construct(RemoteStorage $remoteStorage, TplInterface $tpl, TokenStorage $tokenStorage) |
36
|
|
|
{ |
37
|
|
|
$this->remoteStorage = $remoteStorage; |
38
|
|
|
$this->tpl = $tpl; |
39
|
|
|
$this->tokenStorage = $tokenStorage; |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @param Request $request |
44
|
|
|
* @param string $userId |
45
|
|
|
*/ |
46
|
|
|
public function getHome(Request $request, $userId) |
47
|
|
|
{ |
48
|
|
|
$approvalList = $this->tokenStorage->getAuthorizedClients($userId); |
49
|
|
|
|
50
|
|
|
return new HtmlResponse( |
51
|
|
|
$this->tpl->render( |
52
|
|
|
'home', |
53
|
|
|
[ |
54
|
|
|
'approval_list' => $approvalList, |
55
|
|
|
'host' => $request->getServerName(), |
56
|
|
|
'user_id' => $userId, |
57
|
|
|
'disk_usage' => $this->remoteStorage->getFolderSize(new Path(sprintf('/%s/', $userId))), |
58
|
|
|
'request_url' => $request->getUri(), |
59
|
|
|
'show_account_icon' => true, |
60
|
|
|
] |
61
|
|
|
) |
62
|
|
|
); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @param Request $request |
67
|
|
|
* @param string $userId |
68
|
|
|
*/ |
69
|
|
|
public function postHome(Request $request, $userId) |
70
|
|
|
{ |
71
|
|
|
// XXX InputValidation |
72
|
|
|
$clientId = $request->getPostParameter('client_id'); |
73
|
|
|
$this->tokenStorage->removeClientTokens($userId, $clientId); |
74
|
|
|
|
75
|
|
|
return new RedirectResponse($request->getUri(), 302); |
76
|
|
|
} |
77
|
|
|
} |
78
|
|
|
|