diff --git a/lib/Alchemy/Phrasea/Application.php b/lib/Alchemy/Phrasea/Application.php index 523357f006..02cd4501e8 100644 --- a/lib/Alchemy/Phrasea/Application.php +++ b/lib/Alchemy/Phrasea/Application.php @@ -574,11 +574,21 @@ class Application extends SilexApplication return $this['session']->getFlashBag()->get($type, $default); } + /** + * Adds a temporary unlock data for a account-locked user + * + * @param integer $usr_id + */ public function addUnlockLink($usr_id) { $this['session']->set('unlock_user_id', $usr_id); } + /** + * Returns the temporary unlock data + * + * @return null|integer + */ public function getUnlockLink() { if ($this['session']->has('unlock_user_id')) { diff --git a/lib/Alchemy/Phrasea/Application/Lightbox.php b/lib/Alchemy/Phrasea/Application/Lightbox.php index 0fbacc780d..6fbf3fdc59 100644 --- a/lib/Alchemy/Phrasea/Application/Lightbox.php +++ b/lib/Alchemy/Phrasea/Application/Lightbox.php @@ -34,7 +34,9 @@ class Lightbox implements ControllerProviderInterface } if (false === $usr_id = $app['authentication.token-validator']->isValid($request->query->get('LOG'))) { - return $app->redirect("/login/?error=" . urlencode($e->getMessage())); + $app->addFlash('error', _('The URL you used is out of date, please login')); + + return $app->redirect($app->path('homepage')); } $app['authentication']->openAccount(\User_Adapter::getInstance($usr_id, $app)); diff --git a/lib/Alchemy/Phrasea/Authentication/Provider/ProviderInterface.php b/lib/Alchemy/Phrasea/Authentication/Provider/ProviderInterface.php index 5043663b79..40a8c3d032 100644 --- a/lib/Alchemy/Phrasea/Authentication/Provider/ProviderInterface.php +++ b/lib/Alchemy/Phrasea/Authentication/Provider/ProviderInterface.php @@ -46,7 +46,6 @@ interface ProviderInterface */ public function authenticate(); - /** * This method is called on provider callback, whenever the auth was * successful or failure. diff --git a/lib/Alchemy/Phrasea/Authentication/Token/TokenValidator.php b/lib/Alchemy/Phrasea/Authentication/Token/TokenValidator.php index 2ee6641b69..1aa84108e9 100644 --- a/lib/Alchemy/Phrasea/Authentication/Token/TokenValidator.php +++ b/lib/Alchemy/Phrasea/Authentication/Token/TokenValidator.php @@ -22,6 +22,12 @@ class TokenValidator $this->app = $app; } + /** + * Returns true if the token is valid + * + * @param type $token + * @return boolean + */ public function isValid($token) { try { diff --git a/lib/Alchemy/Phrasea/Controller/Root/Root.php b/lib/Alchemy/Phrasea/Controller/Root/Root.php index a709c18f08..ea4940ad17 100644 --- a/lib/Alchemy/Phrasea/Controller/Root/Root.php +++ b/lib/Alchemy/Phrasea/Controller/Root/Root.php @@ -27,7 +27,6 @@ class Root implements ControllerProviderInterface ->get('/language/{locale}/', $this->call('setLocale')) ->bind('set_locale'); - $controllers ->get('/', $this->call('getRoot')) ->bind('root'); diff --git a/lib/Alchemy/Phrasea/Core/Provider/AuthenticationManagerServiceProvider.php b/lib/Alchemy/Phrasea/Core/Provider/AuthenticationManagerServiceProvider.php index bda9a29f40..1253437bb4 100644 --- a/lib/Alchemy/Phrasea/Core/Provider/AuthenticationManagerServiceProvider.php +++ b/lib/Alchemy/Phrasea/Core/Provider/AuthenticationManagerServiceProvider.php @@ -41,7 +41,6 @@ class AuthenticationManagerServiceProvider implements ServiceProviderInterface return new CookieManager($app['auth.password-encoder'], $app['EM'], $app['browser']); }); - $app['authentication.suggestion-finder'] = $app->share(function (Application $app) { return new SuggestionFinder($app); }); diff --git a/tests/Alchemy/Tests/Phrasea/Core/Provider/RegistrationServiceProviderTest.php b/tests/Alchemy/Tests/Phrasea/Core/Provider/RegistrationServiceProviderTest.php new file mode 100644 index 0000000000..65b60fe311 --- /dev/null +++ b/tests/Alchemy/Tests/Phrasea/Core/Provider/RegistrationServiceProviderTest.php @@ -0,0 +1,34 @@ +register(new RegistrationServiceProvider()); + + self::$DI['app']['phraseanet.configuration'] = $this->getMockBuilder('Alchemy\Phrasea\Core\Configuration') + ->disableOriginalConstructor() + ->getMock(); + + self::$DI['app']['phraseanet.configuration']->expects($this->once()) + ->method('has') + ->with('registration-fields') + ->will($this->returnValue(true)); + self::$DI['app']['phraseanet.configuration']->expects($this->once()) + ->method('get') + ->with('registration-fields') + ->will($this->returnValue(array('plop'))); + + $this->assertEquals(array('plop'), self::$DI['app']['registration.fields']); + $this->assertEquals(array('plop'), self::$DI['app']['registration.fields']); + + $this->assertInternalType('array', self::$DI['app']['registration.optional-fields']); + } +} diff --git a/tests/Alchemy/Tests/Phrasea/Form/Login/PhraseaRegisterFormTest.php b/tests/Alchemy/Tests/Phrasea/Form/Login/PhraseaRegisterFormTest.php index 441b752f29..331d75da26 100644 --- a/tests/Alchemy/Tests/Phrasea/Form/Login/PhraseaRegisterFormTest.php +++ b/tests/Alchemy/Tests/Phrasea/Form/Login/PhraseaRegisterFormTest.php @@ -4,6 +4,7 @@ namespace Alchemy\Tests\Phrasea\Form\Login; use Alchemy\Phrasea\Form\Login\PhraseaRegisterForm;; use Alchemy\Tests\Phrasea\Form\FormTestCase; +use Alchemy\Phrasea\Utilities\String\Camelizer; class PhraseaRegisterFormTest extends FormTestCase { @@ -22,6 +23,58 @@ class PhraseaRegisterFormTest extends FormTestCase ) ); - return new PhraseaRegisterForm(self::$DI['app'], $available, $params, new \Alchemy\Phrasea\Utilities\String\Camelizer()); + return new PhraseaRegisterForm(self::$DI['app'], $available, $params, new Camelizer()); + } + + public function testFormDoesRegisterValidFields() + { + $available = array( + 'parameter' => array( + 'type' => 'text', + 'label' => 'Yollah !', + ), + 'parameter2' => array( + 'type' => 'text', + 'label' => 'Yollah !', + ) + ); + $params = array( + array( + 'name' => 'parameter', + 'required' => true + ), + array( + 'name' => 'parameter2', + 'required' => true + ) + ); + + $form = new PhraseaRegisterForm(self::$DI['app'], $available, $params, new Camelizer()); + + $this->assertCount(8, self::$DI['app']->form($form)->createView()->vars['form']->children); + } + + public function testFormDoesNotRegisterNonValidFields() + { + $available = array( + 'parameter' => array( + 'type' => 'text', + 'label' => 'Yollah !', + ) + ); + $params = array( + array( + 'name' => 'parameter', + 'required' => true + ), + array( + 'name' => 'parameter2', + 'required' => true + ) + ); + + $form = new PhraseaRegisterForm(self::$DI['app'], $available, $params, new Camelizer()); + + $this->assertCount(7, self::$DI['app']->form($form)->createView()->vars['form']->children); } }