diff --git a/lib/Alchemy/Phrasea/Form/Login/PhraseaRegisterForm.php b/lib/Alchemy/Phrasea/Form/Login/PhraseaRegisterForm.php
index fcd7dfa987..2b27a203f8 100644
--- a/lib/Alchemy/Phrasea/Form/Login/PhraseaRegisterForm.php
+++ b/lib/Alchemy/Phrasea/Form/Login/PhraseaRegisterForm.php
@@ -58,14 +58,16 @@ class PhraseaRegisterForm extends AbstractType
),
));
- $builder->add('accept-tou', 'checkbox', array(
- 'label' => _('Terms of Use'),
- 'mapped' => false,
- "constraints" => array(
- new Assert\True(array(
- "message" => _("Please accept the Terms and conditions in order to register.")
- ))),
- ));
+ if ($this->app->hasTermsOfUse()) {
+ $builder->add('accept-tou', 'checkbox', array(
+ 'label' => _('Terms of Use'),
+ 'mapped' => false,
+ "constraints" => array(
+ new Assert\True(array(
+ "message" => _("Please accept the Terms and conditions in order to register.")
+ ))),
+ ));
+ }
$builder->add('provider-id', 'hidden');
diff --git a/templates/web/login/register-classic.html.twig b/templates/web/login/register-classic.html.twig
index 0e9f00b00a..c28092e371 100644
--- a/templates/web/login/register-classic.html.twig
+++ b/templates/web/login/register-classic.html.twig
@@ -59,17 +59,19 @@
{% endif %}
{% endfor %}
-
-
+ {% endif %}
{{ form_rest(form) }}
diff --git a/tests/Alchemy/Tests/Phrasea/Controller/Root/LoginTest.php b/tests/Alchemy/Tests/Phrasea/Controller/Root/LoginTest.php
index 88dcf7d6ec..0a0edb3d90 100644
--- a/tests/Alchemy/Tests/Phrasea/Controller/Root/LoginTest.php
+++ b/tests/Alchemy/Tests/Phrasea/Controller/Root/LoginTest.php
@@ -20,6 +20,8 @@ class LoginTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
public static $login;
public static $email;
+ private static $termsOfUse;
+
public function setUp()
{
parent::setUp();
@@ -45,6 +47,50 @@ class LoginTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
}
}
+ public function tearDown()
+ {
+ $this->resetTOU();
+ parent::tearDown();
+ }
+
+ public function testRegisterWithNoTou()
+ {
+ $this->logout(self::$DI['app']);
+ $this->disableTOU();
+ self::$DI['client']->followRedirects();
+ $crawler = self::$DI['client']->request('GET', '/login/register-classic');
+ $this->assertEquals(0, $crawler->filter('a[href="'.self::$DI['app']->path('login_cgus').'"]')->count());
+ }
+
+ public function testRegisterWithTou()
+ {
+ $this->logout(self::$DI['app']);
+ $this->enableTOU();
+ self::$DI['client']->followRedirects();
+ $crawler = self::$DI['client']->request('GET', '/login/register-classic');
+ $this->assertEquals(2, $crawler->filter('a[href="'.self::$DI['app']->path('login_cgus').'"]')->count());
+ }
+
+ public function testRegisterWithAutoSelect()
+ {
+ $this->logout(self::$DI['app']);
+ $gvAutoSelectDb = !! self::$DI['app']['phraseanet.registry']->get('GV_autoselectDB');
+ self::$DI['app']['phraseanet.registry']->set('GV_autoselectDB', false, \registry::TYPE_BOOLEAN);
+ $crawler = self::$DI['client']->request('GET', '/login/register-classic/');
+ $this->assertEquals(1, $crawler->filter('select[name="collections[]"]')->count());
+ self::$DI['app']['phraseanet.registry']->set('GV_autoselectDB', $gvAutoSelectDb, \registry::TYPE_BOOLEAN);
+ }
+
+ public function testRegisterWithNoAutoSelect()
+ {
+ $this->logout(self::$DI['app']);
+ $gvAutoSelectDb = !! self::$DI['app']['phraseanet.registry']->get('GV_autoselectDB');
+ self::$DI['app']['phraseanet.registry']->set('GV_autoselectDB', true, \registry::TYPE_BOOLEAN);
+ $crawler = self::$DI['client']->request('GET', '/login/register-classic/');
+ $this->assertEquals(0, $crawler->filter('select[name="collections[]"]')->count());
+ self::$DI['app']['phraseanet.registry']->set('GV_autoselectDB', $gvAutoSelectDb, \registry::TYPE_BOOLEAN);
+ }
+
public function testLoginAlreadyAthenticated()
{
self::$DI['client']->request('GET', '/login/');
@@ -70,9 +116,7 @@ class LoginTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
{
$this->logout(self::$DI['app']);
self::$DI['app']->addFlash($type, $message);
-
$crawler = self::$DI['client']->request('GET', '/login/');
-
$response = self::$DI['client']->getResponse();
$this->assertTrue($response->isOk());
$this->assertFlashMessage($crawler, $type, 1, $message);
@@ -86,7 +130,6 @@ class LoginTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
$this->logout(self::$DI['app']);
self::$DI['client']->request('GET', '/login/register-confirm/');
$response = self::$DI['client']->getResponse();
-
$this->assertTrue($response->isRedirect());
$this->assertFlashMessagePopulated(self::$DI['app'], 'error', 1);
$this->assertEquals('/login/', $response->headers->get('location'));
@@ -496,8 +539,9 @@ class LoginTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
/**
* @dataProvider provideInvalidRegistrationData
*/
- public function testPostRegisterbadArguments($parameters, $extraParameters, $errors)
+ public function testPostRegisterBadArguments($parameters, $extraParameters, $errors)
{
+ $this->enableTOU();
self::$DI['app']['registration.enabled'] = true;
self::$DI['app']['registration.fields'] = $extraParameters;
@@ -521,13 +565,13 @@ class LoginTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
}
$crawler = self::$DI['client']->request('POST', '/login/register-classic/', $parameters);
-
$this->assertFalse(self::$DI['client']->getResponse()->isRedirect());
$this->assertFormOrFlashError($crawler, $errors);
}
public function testPostRegisterWithoutParams()
{
+ $this->enableTOU();
$this->logout(self::$DI['app']);
$crawler = self::$DI['client']->request('POST', '/login/register-classic/');
@@ -781,6 +825,7 @@ class LoginTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
public function testPostRegisterWithProviderIdAndAlreadyBoundProvider()
{
+ $this->enableTOU();
self::$DI['app']['registration.fields'] = array();
$this->logout(self::$DI['app']);
@@ -831,6 +876,7 @@ class LoginTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
public function testPostRegisterWithUnknownProvider()
{
+ $this->enableTOU();
self::$DI['app']['registration.fields'] = array();
$this->logout(self::$DI['app']);
@@ -866,6 +912,7 @@ class LoginTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
public function testPostRegisterWithProviderNotAuthenticated()
{
+ $this->enableTOU();
self::$DI['app']['registration.fields'] = array();
$this->logout(self::$DI['app']);
@@ -908,6 +955,7 @@ class LoginTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
public function testPostRegisterWithProviderId()
{
+ $this->enableTOU();
self::$DI['app']['registration.fields'] = array();
$this->logout(self::$DI['app']);
@@ -981,6 +1029,7 @@ class LoginTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
*/
public function testPostRegister($parameters, $extraParameters)
{
+ $this->enableTOU();
self::$DI['app']['registration.fields'] = $extraParameters;
$this->logout(self::$DI['app']);
@@ -1006,7 +1055,7 @@ class LoginTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
}
}
- if ( self::$DI['app']['phraseanet.registry']->get('GV_autoselectDB')) {
+ if (self::$DI['app']['phraseanet.registry']->get('GV_autoselectDB')) {
unset($parameters['collections']);
}
@@ -1753,4 +1802,50 @@ class LoginTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
{
return \random::generatePassword() . '_email@email.com';
}
+
+ private function disableTOU()
+ {
+ if (null === self::$termsOfUse) {
+ self::$termsOfUse = array();
+ foreach (self::$DI['app']['phraseanet.appbox']->get_databoxes() as $databox) {
+ self::$termsOfUse[$databox->get_sbas_id()] = $databox->get_cgus();
+
+ foreach( self::$termsOfUse[$databox->get_sbas_id()]as $lng => $tou) {
+ $databox->update_cgus($lng, '', false);
+ }
+ }
+ }
+ }
+
+ private function enableTOU()
+ {
+ if (null === self::$termsOfUse) {
+ self::$termsOfUse = array();
+ foreach (self::$DI['app']['phraseanet.appbox']->get_databoxes() as $databox) {
+ self::$termsOfUse[$databox->get_sbas_id()] = $databox->get_cgus();
+
+ foreach( self::$termsOfUse[$databox->get_sbas_id()]as $lng => $tou) {
+ $databox->update_cgus($lng, 'something', false);
+ }
+ }
+ }
+ }
+
+ private function resetTOU()
+ {
+ if (null === self::$termsOfUse) {
+ return;
+ }
+ foreach (self::$DI['app']['phraseanet.appbox']->get_databoxes() as $databox) {
+ if (!isset(self::$termsOfUse[$databox->get_sbas_id()])) {
+ continue;
+ }
+ $tous = self::$termsOfUse[$databox->get_sbas_id()];
+ foreach ($tous as $lng => $tou) {
+ $databox->update_cgus($lng, $tou['value'], false);
+ }
+ }
+
+ self::$termsOfUse = null;
+ }
}
diff --git a/www/scripts/apps/login/home/register.js b/www/scripts/apps/login/home/register.js
index f1cf587ce6..eaea38ecd6 100644
--- a/www/scripts/apps/login/home/register.js
+++ b/www/scripts/apps/login/home/register.js
@@ -31,7 +31,8 @@ require([
}, function () {
Common.initialize();
- var rules = [
+ var rules = [];
+ var defaultRules = [
{
name: "email",
rules: "required",
@@ -85,7 +86,13 @@ require([
"message": i18n.t("validation_blank")
};
- rules.push(rule);
+ defaultRules.push(rule);
+ }
+ });
+
+ _.each(defaultRules, function (rule) {
+ // add rule if element exists
+ if ($("[name='" + rule.name + "']").length >= 1) {
}
});
diff --git a/www/scripts/apps/login/home/registerProvider.js b/www/scripts/apps/login/home/registerProvider.js
index ae64b6b8d6..9d66e7569c 100644
--- a/www/scripts/apps/login/home/registerProvider.js
+++ b/www/scripts/apps/login/home/registerProvider.js
@@ -30,7 +30,8 @@ require([
resGetPath: Common.languagePath,
useLocalStorage: true
}, function () {
- var rules = [
+ var rules = [];
+ var defaultRules = [
{
name: "email",
rules: "required",
@@ -84,6 +85,13 @@ require([
"message": i18n.t("validation_blank")
};
+ defaultRules.push(rule);
+ }
+ });
+
+ _.each(defaultRules, function (rule) {
+ // add rule if element exists
+ if ($("[name='" + rule.name + "']").length >= 1) {
rules.push(rule);
}
});