use yii\filters\VerbFilter; | use yii\filters\VerbFilter; | ||||
use yii\filters\AccessControl; | use yii\filters\AccessControl; | ||||
use common\forms\LoginForm; | use common\forms\LoginForm; | ||||
use yii\web\NotFoundHttpException; | |||||
/** | /** | ||||
* Site controller | * Site controller | ||||
&& is_array($userProducerArray) | && is_array($userProducerArray) | ||||
&& count($userProducerArray) == 1) { | && count($userProducerArray) == 1) { | ||||
$urlRedirect = $this->getUrlManagerProducer() | $urlRedirect = $this->getUrlManagerProducer() | ||||
->createAbsoluteUrl([ | ->createAbsoluteUrl([ | ||||
'site/index', | 'site/index', | ||||
if ($user && Yii::$app->getUser()->login($user)) { | if ($user && Yii::$app->getUser()->login($user)) { | ||||
if ($model->isProducer()) { | if ($model->isProducer()) { | ||||
$this->redirect(Yii::$app->urlManagerBackend->createAbsoluteUrl(['site/index'])); | |||||
$this->redirect(['site/signup-confirm']); | |||||
} | } | ||||
else { | else { | ||||
$producer = $producerManager->findOneProducerById($model->id_producer); | $producer = $producerManager->findOneProducerById($model->id_producer); | ||||
if ($producer) { | if ($producer) { | ||||
$this->redirect($this->getUrlManagerProducer()->createAbsoluteUrl(['site/index', 'slug_producer' => $producer->slug])); | |||||
$this->redirect(['site/signup-confirm', 'idProducerRedirect' => $producer->id]); | |||||
} | } | ||||
else { | else { | ||||
$this->redirect(['site/index']); | $this->redirect(['site/index']); | ||||
]); | ]); | ||||
} | } | ||||
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. | * Affiche la page de demande de nouveau mot de passe. | ||||
* Traitement du formulaire. | * Traitement du formulaire. |
['id_tax_rate_default', 'exist', | ['id_tax_rate_default', 'exist', | ||||
'targetClass' => TaxRate::className(), | 'targetClass' => TaxRate::className(), | ||||
'targetAttribute' => ['id_tax_rate_default' => 'id']], | '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'], | |||||
]; | ]; | ||||
} | } | ||||
<?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> |
$params = [$params] ; | $params = [$params] ; | ||||
if(!isset($params['slug_producer'])) | 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) ; | return parent::createUrl($params) ; | ||||
} | } |
<?php | <?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\*'); |
/* @var $scenario Codeception\Scenario */ | /* @var $scenario Codeception\Scenario */ | ||||
/* | |||||
$I = new AcceptanceTester($scenario); | $I = new AcceptanceTester($scenario); | ||||
$I->wantTo('ensure login page works'); | $I->wantTo('ensure login page works'); | ||||
$I->seeLink('Logout (erau)'); | $I->seeLink('Logout (erau)'); | ||||
$I->dontSeeLink('Login'); | $I->dontSeeLink('Login'); | ||||
$I->dontSeeLink('Signup'); | $I->dontSeeLink('Signup'); | ||||
*/ | |||||
/** Uncomment if using WebDriver | /** Uncomment if using WebDriver | ||||
* $I->click('Logout (erau)'); | * $I->click('Logout (erau)'); | ||||
* $I->dontSeeLink('Logout (erau)'); | * $I->dontSeeLink('Logout (erau)'); |
/* @var $scenario Codeception\Scenario */ | /* @var $scenario Codeception\Scenario */ | ||||
/* | |||||
$I = new FunctionalTester($scenario); | $I = new FunctionalTester($scenario); | ||||
$I->wantTo('ensure login page works'); | $I->wantTo('ensure login page works'); | ||||
$I->seeLink('Logout (erau)'); | $I->seeLink('Logout (erau)'); | ||||
$I->dontSeeLink('Login'); | $I->dontSeeLink('Login'); | ||||
$I->dontSeeLink('Signup'); | $I->dontSeeLink('Signup'); | ||||
*/ |
* Represents loging page | * Represents loging page | ||||
* @property \codeception_frontend\AcceptanceTester|\codeception_frontend\FunctionalTester|\codeception_backend\AcceptanceTester|\codeception_backend\FunctionalTester $actor | * @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'; | public $route = 'site/login'; | ||||
<?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; | |||||
} | |||||
} | |||||
<?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' | |||||
], | |||||
]; | |||||
} | |||||
} |
require(__DIR__ . '/../../../common/config/main.php'), | require(__DIR__ . '/../../../common/config/main.php'), | ||||
require(__DIR__ . '/../../../common/config/test-local.php'), | require(__DIR__ . '/../../../common/config/test-local.php'), | ||||
[ | [ | ||||
'id' => 'app-tests', | |||||
//'basePath' => dirname(__DIR__), | |||||
] | |||||
/*[ | |||||
'id' => 'app-tests', | 'id' => 'app-tests', | ||||
'components' => [ | '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' => [ | 'urlManager' => [ | ||||
'showScriptName' => true, | '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; | return $config; |
/** | /** | ||||
* Application configuration for all frontend test types | * Application configuration for all frontend test types | ||||
*/ | */ | ||||
return []; | return []; |
namespace tests\codeception\frontend\_pages; | namespace tests\codeception\frontend\_pages; | ||||
use yii\codeception\BasePage; | |||||
use tests\codeception\common\_pages\MyBasePage; | |||||
/** | /** | ||||
* Represents about page | * Represents about page | ||||
* @property \codeception_frontend\AcceptanceTester|\codeception_frontend\FunctionalTester $actor | * @property \codeception_frontend\AcceptanceTester|\codeception_frontend\FunctionalTester $actor | ||||
*/ | */ | ||||
class AboutPage extends BasePage | |||||
class AboutPage extends MyBasePage | |||||
{ | { | ||||
public $route = 'site/about'; | public $route = 'site/about'; | ||||
} | } |
namespace tests\codeception\frontend\_pages; | namespace tests\codeception\frontend\_pages; | ||||
use yii\codeception\BasePage; | |||||
use tests\codeception\common\_pages\MyBasePage; | |||||
/** | /** | ||||
* Represents contact page | * Represents contact page | ||||
* @property \codeception_frontend\AcceptanceTester|\codeception_frontend\FunctionalTester $actor | * @property \codeception_frontend\AcceptanceTester|\codeception_frontend\FunctionalTester $actor | ||||
*/ | */ | ||||
class ContactPage extends BasePage | |||||
class ContactPage extends MyBasePage | |||||
{ | { | ||||
public $route = 'site/contact'; | public $route = 'site/contact'; | ||||
namespace tests\codeception\frontend\_pages; | namespace tests\codeception\frontend\_pages; | ||||
use \yii\codeception\BasePage; | |||||
use tests\codeception\common\_pages\MyBasePage; | |||||
/** | /** | ||||
* Represents signup page | * Represents signup page | ||||
* @property \codeception_frontend\AcceptanceTester|\codeception_frontend\FunctionalTester $actor | * @property \codeception_frontend\AcceptanceTester|\codeception_frontend\FunctionalTester $actor | ||||
*/ | */ | ||||
class SignupPage extends BasePage | |||||
class SignupPage extends MyBasePage | |||||
{ | { | ||||
public $route = 'site/signup'; | public $route = 'site/signup'; | ||||
/** | /** | ||||
public function submit(array $signupData) | public function submit(array $signupData) | ||||
{ | { | ||||
foreach ($signupData as $field => $value) { | 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'); | $this->actor->click('signup-button'); | ||||
} | } |
<?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'); |