mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-18 15:33:15 +00:00
Add registration routes
This commit is contained in:
@@ -17,6 +17,8 @@ use Alchemy\Phrasea\Account\Command\UpdatePasswordCommand;
|
||||
use Alchemy\Phrasea\Application\Helper\DataboxLoggerAware;
|
||||
use Alchemy\Phrasea\Application\Helper\DispatcherAware;
|
||||
use Alchemy\Phrasea\Authentication\Context;
|
||||
use Alchemy\Phrasea\Authentication\Exception\RegistrationException;
|
||||
use Alchemy\Phrasea\Authentication\RegistrationService;
|
||||
use Alchemy\Phrasea\Border\Attribute\Status;
|
||||
use Alchemy\Phrasea\Border\Checker\Response as CheckerResponse;
|
||||
use Alchemy\Phrasea\Border\File;
|
||||
@@ -850,10 +852,7 @@ class V1Controller extends Controller
|
||||
|
||||
public function unlockAccount(Request $request, $token)
|
||||
{
|
||||
/** @var \Alchemy\Phrasea\Authentication\RegistrationService $service */
|
||||
$service = $this->app['authentication.registration_service'];
|
||||
|
||||
$service->unlockAccount($token);
|
||||
$this->getRegistrationService()->unlockAccount($token);
|
||||
}
|
||||
|
||||
public function addRecordAction(Request $request)
|
||||
@@ -2450,6 +2449,41 @@ class V1Controller extends Controller
|
||||
return Result::create($request, $ret)->createResponse();
|
||||
}
|
||||
|
||||
public function createAccessDemand(Request $request)
|
||||
{
|
||||
$service = $this->getRegistrationService();
|
||||
$data = json_decode($request->getContent(false), true);
|
||||
$collections = null;
|
||||
|
||||
if (isset($data['collections'])) {
|
||||
$collections = $data['collections'];
|
||||
}
|
||||
|
||||
try {
|
||||
$user = $service->registerUser($data, $collections);
|
||||
$token = $service->getAccountUnlockToken($user);
|
||||
}
|
||||
catch (RegistrationException $exception) {
|
||||
return Result::createError($request, 500, $exception->getMessage())->createResponse();
|
||||
}
|
||||
|
||||
return Result::create($request, [
|
||||
'user' => $user,
|
||||
'token' => $token
|
||||
])->createResponse();
|
||||
}
|
||||
|
||||
public function createCollectionRequests(Request $request)
|
||||
{
|
||||
$service = $this->getRegistrationService();
|
||||
$user = $this->getAuthenticatedUser();
|
||||
$data = json_decode($request->getContent(false), true);
|
||||
|
||||
$service->createCollectionRequests($user, $data);
|
||||
|
||||
return Result::create($request, $this->listUserDemands($user))->createResponse();
|
||||
}
|
||||
|
||||
public function ensureAdmin(Request $request)
|
||||
{
|
||||
if (!$user = $this->getApiAuthenticatedUser()->isAdmin()) {
|
||||
@@ -2556,6 +2590,14 @@ class V1Controller extends Controller
|
||||
return $this->app['accounts.service'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return RegistrationService
|
||||
*/
|
||||
public function getRegistrationService()
|
||||
{
|
||||
return $this->app['authentication.registration_service'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return ApiOauthTokenRepository
|
||||
*/
|
||||
|
@@ -248,9 +248,9 @@ class V1 implements ControllerProviderInterface, ServiceProviderInterface
|
||||
->assert('story_id', '\d+');
|
||||
|
||||
$controllers->get('/me/', 'controller.api.v1:getCurrentUserAction');
|
||||
|
||||
$controllers->delete('/me/', 'controller.api.v1:deleteCurrentUserAction');
|
||||
|
||||
$controllers->post('/me/request-collections/', 'controller.api.v1:createCollectionRequests');
|
||||
$controllers->post('/me/update-account/', 'controller.api.v1:updateCurrentUserAction');
|
||||
$controllers->post('/me/update-password/', 'controller.api.v1:updateCurrentUserPasswordAction');
|
||||
|
||||
@@ -260,6 +260,12 @@ class V1 implements ControllerProviderInterface, ServiceProviderInterface
|
||||
$controllers->post('/accounts/update-password/{token}/', 'controller.api.v1:resetPassword')
|
||||
->before('controller.api.v1:ensureAdmin');
|
||||
|
||||
$controllers->post('/accounts/access-demand/', 'controller.api.v1:createAccessDemand')
|
||||
->before('controller.api.v1:ensureAdmin');
|
||||
|
||||
$controllers->post('/accounts/unlock/{token}/', 'controller.api.v1:unlockAccount')
|
||||
->before('controller.api.v1:ensureAdmin');
|
||||
|
||||
return $controllers;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user