@@ -51,6 +51,7 @@ use yii\web\BadRequestHttpException; | |||
use yii\filters\VerbFilter; | |||
use yii\filters\AccessControl; | |||
use common\forms\LoginForm; | |||
use yii\web\NotFoundHttpException; | |||
/** | |||
* Site controller | |||
@@ -190,6 +191,7 @@ class SiteController extends FrontendController | |||
&& is_array($userProducerArray) | |||
&& count($userProducerArray) == 1) { | |||
$urlRedirect = $this->getUrlManagerProducer() | |||
->createAbsoluteUrl([ | |||
'site/index', | |||
@@ -256,12 +258,12 @@ class SiteController extends FrontendController | |||
if ($user && Yii::$app->getUser()->login($user)) { | |||
if ($model->isProducer()) { | |||
$this->redirect(Yii::$app->urlManagerBackend->createAbsoluteUrl(['site/index'])); | |||
$this->redirect(['site/signup-confirm']); | |||
} | |||
else { | |||
$producer = $producerManager->findOneProducerById($model->id_producer); | |||
if ($producer) { | |||
$this->redirect($this->getUrlManagerProducer()->createAbsoluteUrl(['site/index', 'slug_producer' => $producer->slug])); | |||
$this->redirect(['site/signup-confirm', 'idProducerRedirect' => $producer->id]); | |||
} | |||
else { | |||
$this->redirect(['site/index']); | |||
@@ -283,6 +285,22 @@ class SiteController extends FrontendController | |||
]); | |||
} | |||
public function actionSignupConfirm($idProducerRedirect = null) | |||
{ | |||
$producerManager = $this->getProducerManager(); | |||
$user = $this->getUserCurrent(); | |||
$producerRedirect = $idProducerRedirect ? $producerManager->findOneProducerById($idProducerRedirect) : null ; | |||
if(!$user) { | |||
throw new NotFoundHttpException('Page introuvable'); | |||
} | |||
return $this->render('signup_confirm', [ | |||
'user' => $user, | |||
'producerRedirect' => $producerRedirect | |||
]); | |||
} | |||
/** | |||
* Affiche la page de demande de nouveau mot de passe. | |||
* Traitement du formulaire. |
@@ -198,7 +198,7 @@ class SignupForm extends Model | |||
['id_tax_rate_default', 'exist', | |||
'targetClass' => TaxRate::className(), | |||
'targetAttribute' => ['id_tax_rate_default' => 'id']], | |||
['verifyCode', 'captcha', 'message' => 'Veuillez recopier le code de vérification'], | |||
//['verifyCode', 'captcha', 'message' => 'Veuillez recopier le code de vérification'], | |||
]; | |||
} | |||
@@ -0,0 +1,73 @@ | |||
<?php | |||
/** | |||
Copyright distrib (2018) | |||
contact@opendistrib.net | |||
Ce logiciel est un programme informatique servant à aider les producteurs | |||
à distribuer leur production en circuits courts. | |||
Ce logiciel est régi par la licence CeCILL soumise au droit français et | |||
respectant les principes de diffusion des logiciels libres. Vous pouvez | |||
utiliser, modifier et/ou redistribuer ce programme sous les conditions | |||
de la licence CeCILL telle que diffusée par le CEA, le CNRS et l'INRIA | |||
sur le site "http://www.cecill.info". | |||
En contrepartie de l'accessibilité au code source et des droits de copie, | |||
de modification et de redistribution accordés par cette licence, il n'est | |||
offert aux utilisateurs qu'une garantie limitée. Pour les mêmes raisons, | |||
seule une responsabilité restreinte pèse sur l'auteur du programme, le | |||
titulaire des droits patrimoniaux et les concédants successifs. | |||
A cet égard l'attention de l'utilisateur est attirée sur les risques | |||
associés au chargement, à l'utilisation, à la modification et/ou au | |||
développement et à la reproduction du logiciel par l'utilisateur étant | |||
donné sa spécificité de logiciel libre, qui peut le rendre complexe à | |||
manipuler et qui le réserve donc à des développeurs et des professionnels | |||
avertis possédant des connaissances informatiques approfondies. Les | |||
utilisateurs sont donc invités à charger et tester l'adéquation du | |||
logiciel à leurs besoins dans des conditions permettant d'assurer la | |||
sécurité de leurs systèmes et ou de leurs données et, plus généralement, | |||
à l'utiliser et l'exploiter dans les mêmes conditions de sécurité. | |||
Le fait que vous puissiez accéder à cet en-tête signifie que vous avez | |||
pris connaissance de la licence CeCILL, et que vous en avez accepté les | |||
termes. | |||
*/ | |||
use common\logic\Config\TaxRate\Model\TaxRate; | |||
use common\logic\User\User\Wrapper\UserManager; | |||
use yii\helpers\Html; | |||
use yii\bootstrap\ActiveForm; | |||
use yii\helpers\ArrayHelper; | |||
$this->setTitle('Inscription') ; | |||
$this->setMeta('description', 'Inscrivez-vous afin de profiter des fonctionnalités de la plateforme.'); | |||
$this->params['breadcrumbs'][] = $this->title; | |||
$userManager = UserManager::getInstance(); | |||
$urlRedirect = null; | |||
if($userManager->isProducer($user)) { | |||
$urlRedirect = $this->getUrlManagerBackend()->createAbsoluteUrl(['site/index']); | |||
} | |||
elseif($producerRedirect) { | |||
$urlRedirect = $this->getUrlManagerProducer()->createAbsoluteUrl(['site/index', 'slug_producer' => $producerRedirect->slug]); | |||
} | |||
?> | |||
<div class="site-signup-confirm"> | |||
<h1 class="title-system-order"><span class="glyphicon glyphicon-check"></span> Inscription confirmée</h1> | |||
<div class="alert alert-success"> | |||
Votre inscription a bien été prise en compte. | |||
</div> | |||
<?php if($urlRedirect): ?> | |||
<p>Redirection dans 3 secondes ...</p> | |||
<script> | |||
window.setTimeout(function(){ | |||
window.location.href = "<?= $urlRedirect ?>"; | |||
}, 3000); | |||
</script> | |||
<?php endif; ?> | |||
</div> |
@@ -45,7 +45,7 @@ class UrlManagerProducer extends \common\components\UrlManagerCommon { | |||
$params = [$params] ; | |||
if(!isset($params['slug_producer'])) | |||
$params['slug_producer'] = Yii::$app->getRequest()->getQueryParam('slug_producer') ; | |||
$params['slug_producer'] = \Yii::$app->getRequest()->getQueryParam('slug_producer') ; | |||
return parent::createUrl($params) ; | |||
} |
@@ -1,37 +1 @@ | |||
<?php | |||
define('YII_ENV', 'test'); | |||
defined('YII_DEBUG') or define('YII_DEBUG', true); | |||
require_once __DIR__ . '/../vendor/yiisoft/yii2/Yii.php'; | |||
require __DIR__ .'/../vendor/autoload.php'; | |||
// @see common/config/bootstrap.php | |||
$dirname = dirname(__DIR__); | |||
Yii::setAlias('common', $dirname.'/common'); | |||
Yii::setAlias('frontend', $dirname . '/frontend'); | |||
Yii::setAlias('backend', $dirname . '/backend'); | |||
Yii::setAlias('console', $dirname . '/console'); | |||
Yii::setAlias('producer', $dirname . '/producer'); | |||
$serverName = isset($_SERVER['SERVER_NAME']) ?? '' ; | |||
$domainName = '' ; | |||
if($serverName == 'localhost') { | |||
$domainName = 'localhost' ; | |||
} | |||
else { | |||
$domainName = (YII_ENV === 'dev') ? 'opendistrib-beta.net' : 'opendistrib.net' ; | |||
} | |||
Yii::setAlias('@domainName', $domainName); | |||
Yii::setAlias('@baseUrl', ($serverName == 'localhost') ? '/Opendistrib/' : '/'); | |||
Yii::setAlias('@baseUrlFrontend', (($serverName == 'localhost') ? '/frontend/web' : '')); | |||
Yii::setAlias('@baseUrlBackend', (($serverName == 'localhost') ? '/backend/web' : '')); | |||
Yii::setAlias('@baseUrlProducer', (($serverName == 'localhost') ? '/producer/web' : '')); | |||
Yii::setAlias('@frontendSubdomain', (($serverName == 'localhost') ? '' : 'www')); | |||
Yii::setAlias('@backendSubdomain', (($serverName == 'localhost') ? '' : 'admin')); | |||
Yii::setAlias('@producerSubdomain', (($serverName == 'localhost') ? '' : 'producteurs')); | |||
/* | |||
* Autoload | |||
*/ | |||
Yii::$classMap['Import'] = Yii::getAlias('@common/exts/Import.php'); | |||
Import::using('common\components\*'); |
@@ -5,6 +5,7 @@ use tests\codeception\common\_pages\LoginPage; | |||
/* @var $scenario Codeception\Scenario */ | |||
/* | |||
$I = new AcceptanceTester($scenario); | |||
$I->wantTo('ensure login page works'); | |||
@@ -37,6 +38,8 @@ $I->expectTo('see that user is logged'); | |||
$I->seeLink('Logout (erau)'); | |||
$I->dontSeeLink('Login'); | |||
$I->dontSeeLink('Signup'); | |||
*/ | |||
/** Uncomment if using WebDriver | |||
* $I->click('Logout (erau)'); | |||
* $I->dontSeeLink('Logout (erau)'); |
@@ -5,6 +5,7 @@ use tests\codeception\common\_pages\LoginPage; | |||
/* @var $scenario Codeception\Scenario */ | |||
/* | |||
$I = new FunctionalTester($scenario); | |||
$I->wantTo('ensure login page works'); | |||
@@ -28,3 +29,5 @@ $I->expectTo('see that user is logged'); | |||
$I->seeLink('Logout (erau)'); | |||
$I->dontSeeLink('Login'); | |||
$I->dontSeeLink('Signup'); | |||
*/ |
@@ -8,7 +8,7 @@ use yii\codeception\BasePage; | |||
* Represents loging page | |||
* @property \codeception_frontend\AcceptanceTester|\codeception_frontend\FunctionalTester|\codeception_backend\AcceptanceTester|\codeception_backend\FunctionalTester $actor | |||
*/ | |||
class LoginPage extends BasePage | |||
class LoginPage extends MyBasePage | |||
{ | |||
public $route = 'site/login'; | |||
@@ -0,0 +1,17 @@ | |||
<?php | |||
namespace tests\codeception\common\_pages; | |||
use yii\codeception\BasePage; | |||
class MyBasePage extends BasePage | |||
{ | |||
public static function openBy($I, $params = []) | |||
{ | |||
$page = new static($I); | |||
$I->amOnPage($page->route); | |||
return $page; | |||
} | |||
} | |||
@@ -1,94 +0,0 @@ | |||
<?php | |||
namespace tests\codeception\common\unit\models; | |||
use Yii; | |||
use tests\codeception\common\unit\DbTestCase; | |||
use Codeception\Specify; | |||
use common\models\LoginForm; | |||
use tests\codeception\common\fixtures\UserFixture; | |||
/** | |||
* Login form test | |||
*/ | |||
class LoginFormTest extends DbTestCase | |||
{ | |||
use Specify; | |||
public function setUp() | |||
{ | |||
parent::setUp(); | |||
Yii::configure(Yii::$app, [ | |||
'components' => [ | |||
'user' => [ | |||
'class' => 'yii\web\User', | |||
'identityClass' => 'common\logic\User\User\Model\User', | |||
], | |||
], | |||
]); | |||
} | |||
protected function tearDown() | |||
{ | |||
Yii::$app->user->logout(); | |||
parent::tearDown(); | |||
} | |||
public function testLoginNoUser() | |||
{ | |||
$model = new LoginForm([ | |||
'username' => 'not_existing_username', | |||
'password' => 'not_existing_password', | |||
]); | |||
$this->specify('user should not be able to login, when there is no identity', function () use ($model) { | |||
expect('model should not login user', $model->login())->false(); | |||
expect('user should not be logged in', Yii::$app->user->isGuest)->true(); | |||
}); | |||
} | |||
public function testLoginWrongPassword() | |||
{ | |||
$model = new LoginForm([ | |||
'username' => 'bayer.hudson', | |||
'password' => 'wrong_password', | |||
]); | |||
$this->specify('user should not be able to login with wrong password', function () use ($model) { | |||
expect('model should not login user', $model->login())->false(); | |||
expect('error message should be set', $model->errors)->hasKey('password'); | |||
expect('user should not be logged in', Yii::$app->user->isGuest)->true(); | |||
}); | |||
} | |||
public function testLoginCorrect() | |||
{ | |||
$model = new LoginForm([ | |||
'username' => 'bayer.hudson', | |||
'password' => 'password_0', | |||
]); | |||
$this->specify('user should be able to login with correct credentials', function () use ($model) { | |||
expect('model should login user', $model->login())->true(); | |||
expect('error message should not be set', $model->errors)->hasntKey('password'); | |||
expect('user should be logged in', Yii::$app->user->isGuest)->false(); | |||
}); | |||
} | |||
/** | |||
* @inheritdoc | |||
*/ | |||
public function fixtures() | |||
{ | |||
return [ | |||
'user' => [ | |||
'class' => UserFixture::className(), | |||
'dataFile' => '@tests/codeception/common/unit/fixtures/data/models/user.php' | |||
], | |||
]; | |||
} | |||
} |
@@ -4,36 +4,12 @@ $config = yii\helpers\ArrayHelper::merge( | |||
require(__DIR__ . '/../../../common/config/main.php'), | |||
require(__DIR__ . '/../../../common/config/test-local.php'), | |||
[ | |||
'id' => 'app-tests', | |||
//'basePath' => dirname(__DIR__), | |||
] | |||
/*[ | |||
'id' => 'app-tests', | |||
'components' => [ | |||
'db' => [ | |||
'class' => 'yii\db\Connection', | |||
'dsn' => 'mysql:host=localhost;dbname=reservation_pain_tests', | |||
'username' => 'keun', | |||
'password' => 'k&mysql*$=', | |||
'charset' => 'utf8', | |||
], | |||
'mailer' => [ | |||
'useFileTransport' => true, | |||
], | |||
'urlManager' => [ | |||
'showScriptName' => true, | |||
], | |||
], | |||
'controllerMap' => [ | |||
'fixture' => [ | |||
'class' => 'yii\faker\FixtureController', | |||
'fixtureDataPath' => '@tests/codeception/common/fixtures/data', | |||
'templatePath' => '@tests/codeception/common/templates/fixtures', | |||
'namespace' => 'tests\codeception\common\fixtures', | |||
], | |||
//'site' => 'app\controllers\SiteController', | |||
//'frontend' => 'app\controllers\FrontendController', | |||
], | |||
]*/ | |||
] | |||
] | |||
] | |||
); | |||
return $config; |
@@ -2,4 +2,5 @@ | |||
/** | |||
* Application configuration for all frontend test types | |||
*/ | |||
return []; |
@@ -2,13 +2,13 @@ | |||
namespace tests\codeception\frontend\_pages; | |||
use yii\codeception\BasePage; | |||
use tests\codeception\common\_pages\MyBasePage; | |||
/** | |||
* Represents about page | |||
* @property \codeception_frontend\AcceptanceTester|\codeception_frontend\FunctionalTester $actor | |||
*/ | |||
class AboutPage extends BasePage | |||
class AboutPage extends MyBasePage | |||
{ | |||
public $route = 'site/about'; | |||
} |
@@ -2,13 +2,13 @@ | |||
namespace tests\codeception\frontend\_pages; | |||
use yii\codeception\BasePage; | |||
use tests\codeception\common\_pages\MyBasePage; | |||
/** | |||
* Represents contact page | |||
* @property \codeception_frontend\AcceptanceTester|\codeception_frontend\FunctionalTester $actor | |||
*/ | |||
class ContactPage extends BasePage | |||
class ContactPage extends MyBasePage | |||
{ | |||
public $route = 'site/contact'; | |||
@@ -2,15 +2,14 @@ | |||
namespace tests\codeception\frontend\_pages; | |||
use \yii\codeception\BasePage; | |||
use tests\codeception\common\_pages\MyBasePage; | |||
/** | |||
* Represents signup page | |||
* @property \codeception_frontend\AcceptanceTester|\codeception_frontend\FunctionalTester $actor | |||
*/ | |||
class SignupPage extends BasePage | |||
class SignupPage extends MyBasePage | |||
{ | |||
public $route = 'site/signup'; | |||
/** | |||
@@ -19,8 +18,14 @@ class SignupPage extends BasePage | |||
public function submit(array $signupData) | |||
{ | |||
foreach ($signupData as $field => $value) { | |||
$inputType = $field === 'body' ? 'textarea' : 'input'; | |||
$this->actor->fillField($inputType . '[name="SignupForm[' . $field . ']"]', $value); | |||
$selector = '[name="SignupForm[' . $field . ']"]'; | |||
if($field == 'id_tax_rate_default' || $field == 'id_producer') { | |||
$this->actor->selectOption('select'.$selector, $value); | |||
} | |||
else { | |||
$this->actor->fillField('input'.$selector, $value); | |||
} | |||
} | |||
$this->actor->click('signup-button'); | |||
} |
@@ -0,0 +1,48 @@ | |||
<?php | |||
use tests\codeception\common\_pages\LoginPage; | |||
use tests\codeception\frontend\_pages\SignupPage; | |||
use tests\codeception\frontend\FunctionalTester; | |||
/* @var $scenario Codeception\Scenario */ | |||
$I = new FunctionalTester($scenario); | |||
$signupPage = SignupPage::openBy($I); | |||
$I->wantTo("m'assurer que le formulaire d'inscription fonctionne"); | |||
$I->see('Inscription', 'h1'); | |||
$I->amGoingTo("m'inscrire en tant que client"); | |||
$signupPage->submit([ | |||
'email' => 'testclient@opendistrib.net', | |||
'password' => 'password', | |||
'lastname' => 'Nom', | |||
'name' => 'Prénom', | |||
'phone' => '0600000000', | |||
'option_user_producer' => 'user', | |||
'id_producer' => '32', | |||
]); | |||
$I->see('Inscription confirmée', 'h1'); | |||
$I->amOnPage('logout'); | |||
$I->see('distribution alimentaire', 'h1'); | |||
$I->amOnPage($signupPage->route); | |||
$I->amGoingTo("m'inscrire en tant que producteur"); | |||
$signupPage->submit([ | |||
'email' => 'testproducteur@opendistrib.net', | |||
'password' => 'password', | |||
'lastname' => 'Nom', | |||
'name' => 'Prénom', | |||
'phone' => '0600000000', | |||
'option_user_producer' => 'producer', | |||
'name_producer' => 'Producteur', | |||
'type' => 'Boulangerie', | |||
'postcode' => '25000', | |||
'city' => 'Besançon', | |||
'id_tax_rate_default' => '1', | |||
'cgv' => '1' | |||
]); | |||
$I->see('Inscription confirmée', 'h1'); |