Address PR comments

This commit is contained in:
Romain Neutron
2013-05-03 16:52:07 +02:00
parent 70b4912427
commit 71d0d83cd8
8 changed files with 107 additions and 5 deletions

View File

@@ -574,11 +574,21 @@ class Application extends SilexApplication
return $this['session']->getFlashBag()->get($type, $default); 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) public function addUnlockLink($usr_id)
{ {
$this['session']->set('unlock_user_id', $usr_id); $this['session']->set('unlock_user_id', $usr_id);
} }
/**
* Returns the temporary unlock data
*
* @return null|integer
*/
public function getUnlockLink() public function getUnlockLink()
{ {
if ($this['session']->has('unlock_user_id')) { if ($this['session']->has('unlock_user_id')) {

View File

@@ -34,7 +34,9 @@ class Lightbox implements ControllerProviderInterface
} }
if (false === $usr_id = $app['authentication.token-validator']->isValid($request->query->get('LOG'))) { 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)); $app['authentication']->openAccount(\User_Adapter::getInstance($usr_id, $app));

View File

@@ -46,7 +46,6 @@ interface ProviderInterface
*/ */
public function authenticate(); public function authenticate();
/** /**
* This method is called on provider callback, whenever the auth was * This method is called on provider callback, whenever the auth was
* successful or failure. * successful or failure.

View File

@@ -22,6 +22,12 @@ class TokenValidator
$this->app = $app; $this->app = $app;
} }
/**
* Returns true if the token is valid
*
* @param type $token
* @return boolean
*/
public function isValid($token) public function isValid($token)
{ {
try { try {

View File

@@ -27,7 +27,6 @@ class Root implements ControllerProviderInterface
->get('/language/{locale}/', $this->call('setLocale')) ->get('/language/{locale}/', $this->call('setLocale'))
->bind('set_locale'); ->bind('set_locale');
$controllers $controllers
->get('/', $this->call('getRoot')) ->get('/', $this->call('getRoot'))
->bind('root'); ->bind('root');

View File

@@ -41,7 +41,6 @@ class AuthenticationManagerServiceProvider implements ServiceProviderInterface
return new CookieManager($app['auth.password-encoder'], $app['EM'], $app['browser']); return new CookieManager($app['auth.password-encoder'], $app['EM'], $app['browser']);
}); });
$app['authentication.suggestion-finder'] = $app->share(function (Application $app) { $app['authentication.suggestion-finder'] = $app->share(function (Application $app) {
return new SuggestionFinder($app); return new SuggestionFinder($app);
}); });

View File

@@ -0,0 +1,34 @@
<?php
namespace Alchemy\Tests\Phrasea\Core\Provider;
use Alchemy\Phrasea\Core\Provider\RegistrationServiceProvider;
/**
* @covers Alchemy\Phrasea\Core\Provider\RegistrationServiceProvider
*/
class RegistrationServiceProvidertest extends \PhraseanetPHPUnitAbstract
{
public function testSameInstanceShouldBereturnedEveryTime()
{
self::$DI['app']->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']);
}
}

View File

@@ -4,6 +4,7 @@ namespace Alchemy\Tests\Phrasea\Form\Login;
use Alchemy\Phrasea\Form\Login\PhraseaRegisterForm;; use Alchemy\Phrasea\Form\Login\PhraseaRegisterForm;;
use Alchemy\Tests\Phrasea\Form\FormTestCase; use Alchemy\Tests\Phrasea\Form\FormTestCase;
use Alchemy\Phrasea\Utilities\String\Camelizer;
class PhraseaRegisterFormTest extends FormTestCase 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);
} }
} }