mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-17 23:13:15 +00:00
Create phraseanet oauth application when installation is done
This commit is contained in:
@@ -77,6 +77,7 @@ use Alchemy\Phrasea\Core\Event\Subscriber\LogoutSubscriber;
|
||||
use Alchemy\Phrasea\Core\Event\Subscriber\PhraseaLocaleSubscriber;
|
||||
use Alchemy\Phrasea\Core\Event\Subscriber\MaintenanceSubscriber;
|
||||
use Alchemy\Phrasea\Core\Event\Subscriber\CookiesDisablerSubscriber;
|
||||
use Alchemy\Phrasea\Core\Event\Subscriber\PhraseaInstallSubscriber;
|
||||
use Alchemy\Phrasea\Core\Middleware\ApiApplicationMiddlewareProvider;
|
||||
use Alchemy\Phrasea\Core\Middleware\BasketMiddlewareProvider;
|
||||
use Alchemy\Phrasea\Core\Middleware\TokenMiddlewareProvider;
|
||||
@@ -473,6 +474,7 @@ class Application extends SilexApplication
|
||||
$dispatcher->addSubscriber(new PhraseaLocaleSubscriber($app));
|
||||
$dispatcher->addSubscriber(new MaintenanceSubscriber($app));
|
||||
$dispatcher->addSubscriber(new CookiesDisablerSubscriber($app));
|
||||
$dispatcher->addSubscriber(new PhraseaInstallSubscriber($app));
|
||||
|
||||
return $dispatcher;
|
||||
})
|
||||
|
31
lib/Alchemy/Phrasea/Core/Event/InstallFinishEvent.php
Normal file
31
lib/Alchemy/Phrasea/Core/Event/InstallFinishEvent.php
Normal file
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Phraseanet
|
||||
*
|
||||
* (c) 2005-2014 Alchemy
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Alchemy\Phrasea\Core\Event;
|
||||
|
||||
use Alchemy\Phrasea\Application;
|
||||
use Alchemy\Phrasea\Model\Entities\User;
|
||||
use Symfony\Component\EventDispatcher\Event as SfEvent;
|
||||
|
||||
class InstallFinishEvent extends SfEvent
|
||||
{
|
||||
private $user;
|
||||
|
||||
public function __construct(User $user)
|
||||
{
|
||||
$this->user = $user;
|
||||
}
|
||||
|
||||
public function getUser()
|
||||
{
|
||||
return $this->user;
|
||||
}
|
||||
}
|
@@ -0,0 +1,77 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Phraseanet
|
||||
*
|
||||
* (c) 2005-2014 Alchemy
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Alchemy\Phrasea\Core\Event\Subscriber;
|
||||
|
||||
use Alchemy\Phrasea\Core\Event\InstallFinishEvent;
|
||||
use Alchemy\Phrasea\Core\PhraseaEvents;
|
||||
use Alchemy\Phrasea\Model\Entities\ApiApplication;
|
||||
use Silex\Application;
|
||||
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
||||
|
||||
class PhraseaInstallSubscriber implements EventSubscriberInterface
|
||||
{
|
||||
private $app;
|
||||
|
||||
public function __construct(Application $app)
|
||||
{
|
||||
$this->app = $app;
|
||||
}
|
||||
|
||||
public static function getSubscribedEvents()
|
||||
{
|
||||
return [
|
||||
PhraseaEvents::INSTALL_FINISH => 'onInstallFinished'
|
||||
];
|
||||
}
|
||||
|
||||
public function onInstallFinished(InstallFinishEvent $event)
|
||||
{
|
||||
$this->createNavigatorApplication();
|
||||
$this->createOfficePluginApplication();
|
||||
}
|
||||
|
||||
private function createNavigatorApplication()
|
||||
{
|
||||
$application = $this->app['manipulator.api-application']->create(
|
||||
\API_OAuth2_Application_Navigator::CLIENT_NAME,
|
||||
ApiApplication::DESKTOP_TYPE,
|
||||
'',
|
||||
'http://www.phraseanet.com',
|
||||
null,
|
||||
ApiApplication::NATIVE_APP_REDIRECT_URI
|
||||
);
|
||||
|
||||
$application->setGrantPassword(true);
|
||||
$application->setClientId(\API_OAuth2_Application_Navigator::CLIENT_ID);
|
||||
$application->setClientSecret(\API_OAuth2_Application_Navigator::CLIENT_SECRET);
|
||||
|
||||
$this->app['manipulator.api-application']->update($application);
|
||||
}
|
||||
|
||||
private function createOfficePluginApplication()
|
||||
{
|
||||
$application = $this->app['manipulator.api-application']->create(
|
||||
\API_OAuth2_Application_OfficePlugin::CLIENT_NAME,
|
||||
ApiApplication::DESKTOP_TYPE,
|
||||
'',
|
||||
'http://www.phraseanet.com',
|
||||
null,
|
||||
ApiApplication::NATIVE_APP_REDIRECT_URI
|
||||
);
|
||||
|
||||
$application->setGrantPassword(true);
|
||||
$application->setClientId(\API_OAuth2_Application_OfficePlugin::CLIENT_ID);
|
||||
$application->setClientSecret(\API_OAuth2_Application_OfficePlugin::CLIENT_SECRET);
|
||||
|
||||
$this->app['manipulator.api-application']->update($application);
|
||||
}
|
||||
}
|
@@ -18,6 +18,8 @@ final class PhraseaEvents
|
||||
const PRE_AUTHENTICATE = 'phrasea.pre-authenticate';
|
||||
const POST_AUTHENTICATE = 'phrasea.post-authenticate';
|
||||
|
||||
const INSTALL_FINISH = "phrasea.install-finish";
|
||||
|
||||
const API_OAUTH2_START = 'api.oauth2.start';
|
||||
const API_OAUTH2_END = 'api.oauth2.end';
|
||||
const API_LOAD_START = 'api.load.start';
|
||||
|
@@ -12,10 +12,12 @@
|
||||
namespace Alchemy\Phrasea\Setup;
|
||||
|
||||
use Alchemy\Phrasea\Application;
|
||||
use Alchemy\Phrasea\Core\PhraseaEvents;
|
||||
use Alchemy\Phrasea\Core\Event\InstallFinishEvent;
|
||||
use Alchemy\Phrasea\Model\Entities\User;
|
||||
use Doctrine\DBAL\Driver\Connection;
|
||||
use Doctrine\DBAL\DBALException;
|
||||
use Doctrine\ORM\Tools\SchemaTool;
|
||||
use Alchemy\Phrasea\Model\Entities\User;
|
||||
|
||||
class Installer
|
||||
{
|
||||
@@ -46,6 +48,8 @@ class Installer
|
||||
throw $e;
|
||||
}
|
||||
|
||||
$this->app['dispatcher']->dispatch(PhraseaEvents::INSTALL_FINISH, new InstallFinishEvent($user));
|
||||
|
||||
return $user;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user