mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-18 15:33:15 +00:00
Remove some circular references
This commit is contained in:
@@ -86,7 +86,7 @@ class Authenticator
|
||||
|
||||
private function populateSession(Session $session)
|
||||
{
|
||||
$user = $session->getUser($this->app);
|
||||
$user = $session->getUser();
|
||||
|
||||
$rights = [];
|
||||
if ($this->app['acl']->get($user)->has_right('taskmanager')) {
|
||||
|
@@ -16,14 +16,15 @@ use Alchemy\Phrasea\Authentication\Exception\NotAuthenticatedException;
|
||||
use Alchemy\Phrasea\Authentication\Provider\Token\Token;
|
||||
use Alchemy\Phrasea\Authentication\Provider\Token\Identity;
|
||||
use Alchemy\Phrasea\Model\Entities\User;
|
||||
use Doctrine\Common\Persistence\ObjectRepository;
|
||||
|
||||
class SuggestionFinder
|
||||
{
|
||||
private $app;
|
||||
private $repository;
|
||||
|
||||
public function __construct(Application $app)
|
||||
public function __construct(ObjectRepository $repository)
|
||||
{
|
||||
$this->app = $app;
|
||||
$this->repository = $repository;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -40,7 +41,7 @@ class SuggestionFinder
|
||||
$infos = $token->getIdentity();
|
||||
|
||||
if ($infos->has(Identity::PROPERTY_EMAIL)) {
|
||||
return $this->app['manipulator.user']->getRepository()->findByEmail($infos->get(Identity::PROPERTY_EMAIL));
|
||||
return $this->repository->findByEmail($infos->get(Identity::PROPERTY_EMAIL));
|
||||
}
|
||||
|
||||
return null;
|
||||
|
@@ -109,7 +109,7 @@ class Oauth2 implements ControllerProviderInterface
|
||||
}
|
||||
}
|
||||
|
||||
$account = $oauth2_adapter->updateAccount($app['authentication']->getUser()->getId());
|
||||
$account = $oauth2_adapter->updateAccount($app['authentication']->getUser());
|
||||
|
||||
$params['account_id'] = $account->get_id();
|
||||
|
||||
|
@@ -608,7 +608,7 @@ class Login implements ControllerProviderInterface
|
||||
$app->abort(401, 'A token is required');
|
||||
}
|
||||
|
||||
$form = $app->form(new PhraseaRecoverPasswordForm($app));
|
||||
$form = $app->form(new PhraseaRecoverPasswordForm($app['tokens']));
|
||||
$form->setData(['token' => $token]);
|
||||
|
||||
if ('POST' === $request->getMethod()) {
|
||||
|
@@ -45,7 +45,7 @@ class AuthenticationManagerServiceProvider implements ServiceProviderInterface
|
||||
});
|
||||
|
||||
$app['authentication.suggestion-finder'] = $app->share(function (Application $app) {
|
||||
return new SuggestionFinder($app);
|
||||
return new SuggestionFinder($app['manipulator.user']->getRepository());
|
||||
});
|
||||
|
||||
$app['authentication.providers.factory'] = $app->share(function (Application $app) {
|
||||
|
@@ -48,7 +48,7 @@ class RegistrationServiceProvider implements ServiceProviderInterface
|
||||
'type' => 'text',
|
||||
'constraints' => [
|
||||
new Assert\NotBlank(),
|
||||
new NewLogin($app),
|
||||
NewLogin::create($app),
|
||||
]
|
||||
],
|
||||
'gender' => [
|
||||
|
@@ -12,26 +12,27 @@
|
||||
namespace Alchemy\Phrasea\Form\Constraint;
|
||||
|
||||
use Alchemy\Phrasea\Application;
|
||||
use Doctrine\Common\Persistence\ObjectRepository;
|
||||
use Symfony\Component\Validator\Constraint;
|
||||
|
||||
class NewEmail extends Constraint
|
||||
{
|
||||
public $message = 'This email is already bound to an account';
|
||||
private $app;
|
||||
private $repository;
|
||||
|
||||
public function __construct(Application $app)
|
||||
public function __construct(ObjectRepository $repository)
|
||||
{
|
||||
$this->app = $app;
|
||||
$this->repository = $repository;
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public function isAlreadyRegistered($email)
|
||||
{
|
||||
return (Boolean) $this->app['manipulator.user']->getRepository()->findByEmail($email);
|
||||
return (Boolean) $this->repository->findByEmail($email);
|
||||
}
|
||||
|
||||
public static function create(Application $app)
|
||||
{
|
||||
return new static($app);
|
||||
return new static($app['manipulator.user']->getRepository());
|
||||
}
|
||||
}
|
||||
|
@@ -12,26 +12,27 @@
|
||||
namespace Alchemy\Phrasea\Form\Constraint;
|
||||
|
||||
use Alchemy\Phrasea\Application;
|
||||
use Doctrine\Common\Persistence\ObjectRepository;
|
||||
use Symfony\Component\Validator\Constraint;
|
||||
|
||||
class NewLogin extends Constraint
|
||||
{
|
||||
public $message = 'This login is already registered';
|
||||
private $app;
|
||||
private $repository;
|
||||
|
||||
public function __construct(Application $app)
|
||||
public function __construct(ObjectRepository $repository)
|
||||
{
|
||||
$this->app = $app;
|
||||
$this->repository = $repository;
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public function isAlreadyRegistered($login)
|
||||
{
|
||||
return (Boolean) $this->app['manipulator.user']->getRepository()->findByLogin($login);
|
||||
return (Boolean) $this->repository->findByLogin($login);
|
||||
}
|
||||
|
||||
public static function create(Application $app)
|
||||
{
|
||||
return new static($app);
|
||||
return new static($app['manipulator.user']->getRepository());
|
||||
}
|
||||
}
|
||||
|
@@ -18,12 +18,10 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
class PasswordToken extends Constraint
|
||||
{
|
||||
public $message = 'The token provided is not valid anymore';
|
||||
private $app;
|
||||
private $random;
|
||||
|
||||
public function __construct(Application $app, \random $random)
|
||||
public function __construct(\random $random)
|
||||
{
|
||||
$this->app = $app;
|
||||
$this->random = $random;
|
||||
parent::__construct();
|
||||
}
|
||||
@@ -41,6 +39,6 @@ class PasswordToken extends Constraint
|
||||
|
||||
public static function create(Application $app)
|
||||
{
|
||||
return new static($app, $app['tokens']);
|
||||
return new static($app['tokens']);
|
||||
}
|
||||
}
|
||||
|
@@ -22,11 +22,11 @@ use Symfony\Component\Validator\Constraints as Assert;
|
||||
*/
|
||||
class PhraseaRecoverPasswordForm extends AbstractType
|
||||
{
|
||||
private $app;
|
||||
private $tokens;
|
||||
|
||||
public function __construct(Application $app)
|
||||
public function __construct(\random $tokens)
|
||||
{
|
||||
$this->app = $app;
|
||||
$this->tokens = $tokens;
|
||||
}
|
||||
|
||||
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||
@@ -34,7 +34,7 @@ class PhraseaRecoverPasswordForm extends AbstractType
|
||||
$builder->add('token', 'hidden', [
|
||||
'required' => true,
|
||||
'constraints' => [
|
||||
new PasswordToken($this->app, $this->app['tokens'])
|
||||
new PasswordToken($this->tokens)
|
||||
]
|
||||
]);
|
||||
|
||||
|
@@ -12,6 +12,7 @@
|
||||
namespace Alchemy\Phrasea\Form\Login;
|
||||
|
||||
use Alchemy\Phrasea\Application;
|
||||
use Alchemy\Phrasea\Form\Constraint\NewEmail;
|
||||
use Alchemy\Phrasea\Utilities\String\Camelizer;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
@@ -40,7 +41,7 @@ class PhraseaRegisterForm extends AbstractType
|
||||
'constraints' => [
|
||||
new Assert\NotBlank(),
|
||||
new Assert\Email(),
|
||||
new \Alchemy\Phrasea\Form\Constraint\NewEmail($this->app),
|
||||
NewEmail::create($this->app),
|
||||
],
|
||||
]);
|
||||
|
||||
|
@@ -497,19 +497,18 @@ class API_OAuth2_Adapter extends OAuth2
|
||||
|
||||
/**
|
||||
*
|
||||
* @param usr_id $usr_id
|
||||
* @param User $user
|
||||
* @return API_OAuth2_Account
|
||||
*/
|
||||
public function updateAccount($usr_id)
|
||||
public function updateAccount(User $user)
|
||||
{
|
||||
if ($this->client === null)
|
||||
throw new logicalException("Client property must be set before update an account");
|
||||
|
||||
try {
|
||||
$user = $this->app['manipulator.user']->getRepository()->find($usr_id);
|
||||
$account = API_OAuth2_Account::load_with_user($this->app, $this->client, $user);
|
||||
} catch (\Exception $e) {
|
||||
$account = $this->createAccount($usr_id);
|
||||
$account = $this->createAccount($user->getId());
|
||||
}
|
||||
|
||||
return $account;
|
||||
@@ -795,7 +794,11 @@ class API_OAuth2_Adapter extends OAuth2
|
||||
return false;
|
||||
}
|
||||
|
||||
$account = $this->updateAccount($usr_id);
|
||||
if (null === $user = $this->app['manipulator.user']->getRepository()->find($usr_id)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$account = $this->updateAccount($user);
|
||||
|
||||
return [
|
||||
'redirect_uri' => $this->client->get_redirect_uri()
|
||||
|
@@ -285,7 +285,7 @@
|
||||
<p>{{ "Date" | trans }} : <span class="info">{{ app['date-formatter'].getPrettyString(file.getCreated()) }}</span></p>
|
||||
{% if file.getSession().getUser() is not none %}
|
||||
<p>
|
||||
{% set username = '<a href="#" class="username userTips" tooltipsrc="' ~ path('prod_tooltip_user', { 'usr_id' : file.getSession().getUser(app).getId() }) ~ '/">' ~ file.getSession().getUser().getDisplayName() ~ '</a>' %}
|
||||
{% set username = '<a href="#" class="username userTips" tooltipsrc="' ~ path('prod_tooltip_user', { 'usr_id' : file.getSession().getUser().getId() }) ~ '/">' ~ file.getSession().getUser().getDisplayName() ~ '</a>' %}
|
||||
{% trans with {'%username%' : username} %}Uploaded by : %username%{% endtrans %}
|
||||
</p>
|
||||
{% endif %}
|
||||
|
@@ -11,7 +11,7 @@ class SuggestionFinderTest extends \PhraseanetTestCase
|
||||
{
|
||||
$token = $this->getToken(self::$DI['user']->getEmail());
|
||||
|
||||
$finder = new SuggestionFinder(self::$DI['app']);
|
||||
$finder = new SuggestionFinder(self::$DI['app']['manipulator.user']->getRepository());
|
||||
$user = $finder->find($token);
|
||||
|
||||
$this->assertInstanceOf('Alchemy\Phrasea\Model\Entities\User', $user);
|
||||
@@ -22,7 +22,7 @@ class SuggestionFinderTest extends \PhraseanetTestCase
|
||||
{
|
||||
$token = $this->getToken(sprintf('%srandom%s@%srandom.com', uniqid(mt_rand(), true), uniqid(mt_rand(), true), uniqid(mt_rand(), true)));
|
||||
|
||||
$finder = new SuggestionFinder(self::$DI['app']);
|
||||
$finder = new SuggestionFinder(self::$DI['app']['manipulator.user']->getRepository());
|
||||
$user = $finder->find($token);
|
||||
|
||||
$this->assertNull($user);
|
||||
|
@@ -8,25 +8,25 @@ class NewEmailTest extends \PhraseanetTestCase
|
||||
{
|
||||
public function testAnUnknownAddressIsNotAlreadyRegistered()
|
||||
{
|
||||
$constraint = new NewEmail(self::$DI['app']);
|
||||
$constraint = NewEmail::create(self::$DI['app']);
|
||||
$this->assertFalse($constraint->isAlreadyRegistered('nonehere'));
|
||||
}
|
||||
|
||||
public function testARegisteredAddressIsAlreadyRegistered()
|
||||
{
|
||||
$constraint = new NewEmail(self::$DI['app']);
|
||||
$constraint = NewEmail::create(self::$DI['app']);
|
||||
$this->assertTrue($constraint->isAlreadyRegistered(self::$DI['user']->getEmail()));
|
||||
}
|
||||
|
||||
public function testNullIsNotAlreadyRegistered()
|
||||
{
|
||||
$constraint = new NewEmail(self::$DI['app']);
|
||||
$constraint = NewEmail::create(self::$DI['app']);
|
||||
$this->assertFalse($constraint->isAlreadyRegistered(null));
|
||||
}
|
||||
|
||||
public function testBlankIsNotAlreadyRegistered()
|
||||
{
|
||||
$constraint = new NewEmail(self::$DI['app']);
|
||||
$constraint = NewEmail::create(self::$DI['app']);
|
||||
$this->assertFalse($constraint->isAlreadyRegistered(''));
|
||||
}
|
||||
}
|
||||
|
@@ -8,25 +8,25 @@ class NewLoginTest extends \PhraseanetTestCase
|
||||
{
|
||||
public function testAnUnknownLoginIsNotAlreadyRegistered()
|
||||
{
|
||||
$constraint = new NewLogin(self::$DI['app']);
|
||||
$constraint = NewLogin::create(self::$DI['app']);
|
||||
$this->assertFalse($constraint->isAlreadyRegistered('nonehere@test.com'));
|
||||
}
|
||||
|
||||
public function testARegisteredLoginIsAlreadyRegistered()
|
||||
{
|
||||
$constraint = new NewLogin(self::$DI['app']);
|
||||
$constraint = NewLogin::create(self::$DI['app']);
|
||||
$this->assertTrue($constraint->isAlreadyRegistered(self::$DI['user']->getLogin()));
|
||||
}
|
||||
|
||||
public function testNullIsNotAlreadyRegistered()
|
||||
{
|
||||
$constraint = new NewLogin(self::$DI['app']);
|
||||
$constraint = NewLogin::create(self::$DI['app']);
|
||||
$this->assertFalse($constraint->isAlreadyRegistered(null));
|
||||
}
|
||||
|
||||
public function testBlankIsNotAlreadyRegistered()
|
||||
{
|
||||
$constraint = new NewLogin(self::$DI['app']);
|
||||
$constraint = NewLogin::create(self::$DI['app']);
|
||||
$this->assertFalse($constraint->isAlreadyRegistered(''));
|
||||
}
|
||||
}
|
||||
|
@@ -23,7 +23,7 @@ class PasswordTokenTest extends \PhraseanetTestCase
|
||||
->with($token)
|
||||
->will($this->throwException(new NotFoundHttpException('Token not found')));
|
||||
|
||||
$constraint = new PasswordToken(self::$DI['app'], $random);
|
||||
$constraint = new PasswordToken($random);
|
||||
$this->assertFalse($constraint->isValid($token));
|
||||
}
|
||||
|
||||
@@ -43,7 +43,7 @@ class PasswordTokenTest extends \PhraseanetTestCase
|
||||
->with($token)
|
||||
->will($this->returnValue(['usr_id' => mt_rand(), 'type' => \random::TYPE_PASSWORD]));
|
||||
|
||||
$constraint = new PasswordToken(self::$DI['app'], $random);
|
||||
$constraint = new PasswordToken($random);
|
||||
$this->assertTrue($constraint->isValid($token));
|
||||
}
|
||||
}
|
||||
|
@@ -9,6 +9,6 @@ class PhraseaRecoverPasswordFormTest extends FormTestCase
|
||||
{
|
||||
protected function getForm()
|
||||
{
|
||||
return new PhraseaRecoverPasswordForm(self::$DI['app']);
|
||||
return new PhraseaRecoverPasswordForm(self::$DI['app']['tokens']);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user