23
23
use League\OAuth2\Server\AuthorizationServer;
24
24
use League\OAuth2\Server\Grant\AuthCodeGrant;
25
25
use League\OAuth2\Server\Util\RedirectUri;
26
use League\OAuth2\Server\Util\SecureKey;
26
use Xibo\Entity\Application;
27
use Xibo\Exception\AccessDeniedException;
27
28
use Xibo\Factory\ApplicationFactory;
28
29
use Xibo\Helper\Help;
29
30
use Xibo\Helper\Log;
33
34
use Xibo\Storage\ApiClientStorage;
34
35
use Xibo\Storage\ApiScopeStorage;
35
36
use Xibo\Storage\ApiSessionStorage;
36
use Xibo\Storage\PDOConnect;
39
39
class Applications extends Base
52
52
public function grid()
54
54
$this->getState()->template = 'grid';
55
$this->getState()->setData(ApplicationFactory::query($this->gridRenderSort(), $this->gridRenderFilter()));
56
$applications = ApplicationFactory::query($this->gridRenderSort(), $this->gridRenderFilter());
58
foreach ($applications as $application) {
59
/* @var Application $application */
63
// Include the buttons property
64
$application->includeProperty('buttons');
66
// Add an Edit button (edit form also exposes the secret - not possible to get through the API)
67
$application->buttons = [];
69
if ($application->userId == $this->getUser()->userId || $this->getUser()->getUserTypeId() == 1) {
72
$application->buttons[] = array(
73
'id' => 'application_edit_button',
74
'url' => $this->urlFor('application.edit.form', array('id' => $application->key)),
80
$this->getState()->setData($applications);
56
81
$this->getState()->recordsTotal = ApplicationFactory::countLast();
154
public function editForm($clientId)
157
$client = ApplicationFactory::getById($clientId);
159
if ($client->userId != $this->getUser()->userId && $this->getUser()->getUserTypeId() != 1)
160
throw new AccessDeniedException();
163
$this->getState()->template = 'applications-form-edit';
164
$this->getState()->setData([
166
'help' => Help::Link('Services', 'Register')
130
171
* Register a new application with OAuth
132
173
public function add()
134
// Make and ID/Secret
135
$id = SecureKey::generate();
136
$secret = SecureKey::generate(254);
138
// Simple Insert for now
140
INSERT INTO `oauth_clients` (`id`, `secret`, `name`)
141
VALUES (:id, :secret, :name)
145
'name' => Sanitize::getString('name')
149
PDOConnect::insert('INSERT INTO `oauth_client_redirect_uris` (client_id, redirect_uri) VALUES (:clientId, :redirectUri)', [
151
'redirectUri' => Sanitize::getString('redirectUri')
155
$this->getState()->hydrate([
156
'message' => sprintf(__('Added %s'), Sanitize::getString('name')),
175
$application = ApplicationFactory::create();
176
$application->name = Sanitize::getString('name');
177
$application->save();
180
$this->getState()->hydrate([
181
'message' => sprintf(__('Added %s'), $application->name),
182
'data' => $application,
183
'id' => $application->key
187
public function edit($clientId)
190
$client = ApplicationFactory::getById($clientId);
192
if ($client->userId != $this->getUser()->userId && $this->getUser()->getUserTypeId() != 1)
193
throw new AccessDeniedException();
195
$client->name = Sanitize::getString('name');
197
if (Sanitize::getCheckbox('resetKeys') == 1) {
198
$client->resetKeys();
204
$this->getState()->hydrate([
205
'message' => sprintf(__('Added %s'), $client->name),
b'\\ No newline at end of file'