Commit 418b7fab5a7aa0fdcc789e100a201aebd946661c
0 parents
first commit
Showing
156 changed files
with
4237 additions
and
0 deletions
Show diff stats
Too many changes.
To preserve performance only 100 of 156 files are displayed.
1 | +++ a/LICENSE.md | ||
1 | +The Yii framework is free software. It is released under the terms of | ||
2 | +the following BSD License. | ||
3 | + | ||
4 | +Copyright © 2008 by Yii Software LLC (http://www.yiisoft.com) | ||
5 | +All rights reserved. | ||
6 | + | ||
7 | +Redistribution and use in source and binary forms, with or without | ||
8 | +modification, are permitted provided that the following conditions | ||
9 | +are met: | ||
10 | + | ||
11 | + * Redistributions of source code must retain the above copyright | ||
12 | + notice, this list of conditions and the following disclaimer. | ||
13 | + * Redistributions in binary form must reproduce the above copyright | ||
14 | + notice, this list of conditions and the following disclaimer in | ||
15 | + the documentation and/or other materials provided with the | ||
16 | + distribution. | ||
17 | + * Neither the name of Yii Software LLC nor the names of its | ||
18 | + contributors may be used to endorse or promote products derived | ||
19 | + from this software without specific prior written permission. | ||
20 | + | ||
21 | +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
22 | +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
23 | +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS | ||
24 | +FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE | ||
25 | +COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, | ||
26 | +INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, | ||
27 | +BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
28 | +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | ||
29 | +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
30 | +LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN | ||
31 | +ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
32 | +POSSIBILITY OF SUCH DAMAGE. |
1 | +++ a/README.md | ||
1 | +Yii 2 Advanced Project Template | ||
2 | +=============================== | ||
3 | + | ||
4 | +Yii 2 Advanced Project Template is a skeleton [Yii 2](http://www.yiiframework.com/) application best for | ||
5 | +developing complex Web applications with multiple tiers. | ||
6 | + | ||
7 | +The template includes three tiers: front end, back end, and console, each of which | ||
8 | +is a separate Yii application. | ||
9 | + | ||
10 | +The template is designed to work in a team development environment. It supports | ||
11 | +deploying the application in different environments. | ||
12 | + | ||
13 | +Documentation is at [docs/guide/README.md](docs/guide/README.md). | ||
14 | + | ||
15 | +[](https://packagist.org/packages/yiisoft/yii2-app-advanced) | ||
16 | +[](https://packagist.org/packages/yiisoft/yii2-app-advanced) | ||
17 | +[](https://travis-ci.org/yiisoft/yii2-app-advanced) | ||
18 | + | ||
19 | +DIRECTORY STRUCTURE | ||
20 | +------------------- | ||
21 | + | ||
22 | +``` | ||
23 | +common | ||
24 | + config/ contains shared configurations | ||
25 | + mail/ contains view files for e-mails | ||
26 | + models/ contains model classes used in both backend and frontend | ||
27 | + tests/ contains tests for common classes | ||
28 | +console | ||
29 | + config/ contains console configurations | ||
30 | + controllers/ contains console controllers (commands) | ||
31 | + migrations/ contains database migrations | ||
32 | + models/ contains console-specific model classes | ||
33 | + runtime/ contains files generated during runtime | ||
34 | +backend | ||
35 | + assets/ contains application assets such as JavaScript and CSS | ||
36 | + config/ contains backend configurations | ||
37 | + controllers/ contains Web controller classes | ||
38 | + models/ contains backend-specific model classes | ||
39 | + runtime/ contains files generated during runtime | ||
40 | + tests/ contains tests for backend application | ||
41 | + views/ contains view files for the Web application | ||
42 | + web/ contains the entry script and Web resources | ||
43 | +frontend | ||
44 | + assets/ contains application assets such as JavaScript and CSS | ||
45 | + config/ contains frontend configurations | ||
46 | + controllers/ contains Web controller classes | ||
47 | + models/ contains frontend-specific model classes | ||
48 | + runtime/ contains files generated during runtime | ||
49 | + tests/ contains tests for frontend application | ||
50 | + views/ contains view files for the Web application | ||
51 | + web/ contains the entry script and Web resources | ||
52 | + widgets/ contains frontend widgets | ||
53 | +vendor/ contains dependent 3rd-party packages | ||
54 | +environments/ contains environment-based overrides | ||
55 | +``` |
1 | +++ a/Vagrantfile | ||
1 | +require 'yaml' | ||
2 | +require 'fileutils' | ||
3 | + | ||
4 | +domains = { | ||
5 | + frontend: 'y2aa-frontend.dev', | ||
6 | + backend: 'y2aa-backend.dev' | ||
7 | +} | ||
8 | + | ||
9 | +config = { | ||
10 | + local: './vagrant/config/vagrant-local.yml', | ||
11 | + example: './vagrant/config/vagrant-local.example.yml' | ||
12 | +} | ||
13 | + | ||
14 | +# copy config from example if local config not exists | ||
15 | +FileUtils.cp config[:example], config[:local] unless File.exist?(config[:local]) | ||
16 | +# read config | ||
17 | +options = YAML.load_file config[:local] | ||
18 | + | ||
19 | +# check github token | ||
20 | +if options['github_token'].nil? || options['github_token'].to_s.length != 40 | ||
21 | + puts "You must place REAL GitHub token into configuration:\n/yii2-app-advancded/vagrant/config/vagrant-local.yml" | ||
22 | + exit | ||
23 | +end | ||
24 | + | ||
25 | +# vagrant configurate | ||
26 | +Vagrant.configure(2) do |config| | ||
27 | + # select the box | ||
28 | + config.vm.box = 'ubuntu/trusty64' | ||
29 | + | ||
30 | + # should we ask about box updates? | ||
31 | + config.vm.box_check_update = options['box_check_update'] | ||
32 | + | ||
33 | + config.vm.provider 'virtualbox' do |vb| | ||
34 | + # machine cpus count | ||
35 | + vb.cpus = options['cpus'] | ||
36 | + # machine memory size | ||
37 | + vb.memory = options['memory'] | ||
38 | + # machine name (for VirtualBox UI) | ||
39 | + vb.name = options['machine_name'] | ||
40 | + end | ||
41 | + | ||
42 | + # machine name (for vagrant console) | ||
43 | + config.vm.define options['machine_name'] | ||
44 | + | ||
45 | + # machine name (for guest machine console) | ||
46 | + config.vm.hostname = options['machine_name'] | ||
47 | + | ||
48 | + # network settings | ||
49 | + config.vm.network 'private_network', ip: options['ip'] | ||
50 | + | ||
51 | + # sync: folder 'yii2-app-advanced' (host machine) -> folder '/app' (guest machine) | ||
52 | + config.vm.synced_folder './', '/app', owner: 'vagrant', group: 'vagrant' | ||
53 | + | ||
54 | + # disable folder '/vagrant' (guest machine) | ||
55 | + config.vm.synced_folder '.', '/vagrant', disabled: true | ||
56 | + | ||
57 | + # hosts settings (host machine) | ||
58 | + config.vm.provision :hostmanager | ||
59 | + config.hostmanager.enabled = true | ||
60 | + config.hostmanager.manage_host = true | ||
61 | + config.hostmanager.ignore_private_ip = false | ||
62 | + config.hostmanager.include_offline = true | ||
63 | + config.hostmanager.aliases = domains.values | ||
64 | + | ||
65 | + # provisioners | ||
66 | + config.vm.provision 'shell', path: './vagrant/provision/once-as-root.sh', args: [options['timezone']] | ||
67 | + config.vm.provision 'shell', path: './vagrant/provision/once-as-vagrant.sh', args: [options['github_token']], privileged: false | ||
68 | + config.vm.provision 'shell', path: './vagrant/provision/always-as-root.sh', run: 'always' | ||
69 | + | ||
70 | + # post-install message (vagrant console) | ||
71 | + config.vm.post_up_message = "Frontend URL: http://#{domains[:frontend]}\nBackend URL: http://#{domains[:backend]}" | ||
72 | +end |
1 | +++ a/backend/assets/AppAsset.php | ||
1 | +<?php | ||
2 | + | ||
3 | +namespace backend\assets; | ||
4 | + | ||
5 | +use yii\web\AssetBundle; | ||
6 | + | ||
7 | +/** | ||
8 | + * Main backend application asset bundle. | ||
9 | + */ | ||
10 | +class AppAsset extends AssetBundle | ||
11 | +{ | ||
12 | + public $basePath = '@webroot'; | ||
13 | + public $baseUrl = '@web'; | ||
14 | + public $css = [ | ||
15 | + 'css/site.css', | ||
16 | + ]; | ||
17 | + public $js = [ | ||
18 | + ]; | ||
19 | + public $depends = [ | ||
20 | + 'yii\web\YiiAsset', | ||
21 | + 'yii\bootstrap\BootstrapAsset', | ||
22 | + ]; | ||
23 | +} |
1 | +++ a/backend/codeception.yml | ||
1 | +namespace: backend\tests | ||
2 | +actor: Tester | ||
3 | +paths: | ||
4 | + tests: tests | ||
5 | + log: tests/_output | ||
6 | + data: tests/_data | ||
7 | + helpers: tests/_support | ||
8 | +settings: | ||
9 | + bootstrap: _bootstrap.php | ||
10 | + colors: true | ||
11 | + memory_limit: 1024M | ||
12 | +modules: | ||
13 | + config: | ||
14 | + Yii2: | ||
15 | + configFile: 'config/test-local.php' |
1 | +++ a/backend/config/main.php | ||
1 | +<?php | ||
2 | +$params = array_merge( | ||
3 | + require(__DIR__ . '/../../common/config/params.php'), | ||
4 | + require(__DIR__ . '/../../common/config/params-local.php'), | ||
5 | + require(__DIR__ . '/params.php'), | ||
6 | + require(__DIR__ . '/params-local.php') | ||
7 | +); | ||
8 | + | ||
9 | +return [ | ||
10 | + 'id' => 'app-backend', | ||
11 | + 'basePath' => dirname(__DIR__), | ||
12 | + 'controllerNamespace' => 'backend\controllers', | ||
13 | + 'bootstrap' => ['log'], | ||
14 | + 'modules' => [], | ||
15 | + 'components' => [ | ||
16 | + 'request' => [ | ||
17 | + 'csrfParam' => '_csrf-backend', | ||
18 | + ], | ||
19 | + 'user' => [ | ||
20 | + 'identityClass' => 'common\models\User', | ||
21 | + 'enableAutoLogin' => true, | ||
22 | + 'identityCookie' => ['name' => '_identity-backend', 'httpOnly' => true], | ||
23 | + ], | ||
24 | + 'session' => [ | ||
25 | + // this is the name of the session cookie used for login on the backend | ||
26 | + 'name' => 'advanced-backend', | ||
27 | + ], | ||
28 | + 'log' => [ | ||
29 | + 'traceLevel' => YII_DEBUG ? 3 : 0, | ||
30 | + 'targets' => [ | ||
31 | + [ | ||
32 | + 'class' => 'yii\log\FileTarget', | ||
33 | + 'levels' => ['error', 'warning'], | ||
34 | + ], | ||
35 | + ], | ||
36 | + ], | ||
37 | + 'errorHandler' => [ | ||
38 | + 'errorAction' => 'site/error', | ||
39 | + ], | ||
40 | + /* | ||
41 | + 'urlManager' => [ | ||
42 | + 'enablePrettyUrl' => true, | ||
43 | + 'showScriptName' => false, | ||
44 | + 'rules' => [ | ||
45 | + ], | ||
46 | + ], | ||
47 | + */ | ||
48 | + ], | ||
49 | + 'params' => $params, | ||
50 | +]; |
1 | +++ a/backend/controllers/SiteController.php | ||
1 | +<?php | ||
2 | +namespace backend\controllers; | ||
3 | + | ||
4 | +use Yii; | ||
5 | +use yii\web\Controller; | ||
6 | +use yii\filters\VerbFilter; | ||
7 | +use yii\filters\AccessControl; | ||
8 | +use common\models\LoginForm; | ||
9 | + | ||
10 | +/** | ||
11 | + * Site controller | ||
12 | + */ | ||
13 | +class SiteController extends Controller | ||
14 | +{ | ||
15 | + /** | ||
16 | + * @inheritdoc | ||
17 | + */ | ||
18 | + public function behaviors() | ||
19 | + { | ||
20 | + return [ | ||
21 | + 'access' => [ | ||
22 | + 'class' => AccessControl::className(), | ||
23 | + 'rules' => [ | ||
24 | + [ | ||
25 | + 'actions' => ['login', 'error'], | ||
26 | + 'allow' => true, | ||
27 | + ], | ||
28 | + [ | ||
29 | + 'actions' => ['logout', 'index'], | ||
30 | + 'allow' => true, | ||
31 | + 'roles' => ['@'], | ||
32 | + ], | ||
33 | + ], | ||
34 | + ], | ||
35 | + 'verbs' => [ | ||
36 | + 'class' => VerbFilter::className(), | ||
37 | + 'actions' => [ | ||
38 | + 'logout' => ['post'], | ||
39 | + ], | ||
40 | + ], | ||
41 | + ]; | ||
42 | + } | ||
43 | + | ||
44 | + /** | ||
45 | + * @inheritdoc | ||
46 | + */ | ||
47 | + public function actions() | ||
48 | + { | ||
49 | + return [ | ||
50 | + 'error' => [ | ||
51 | + 'class' => 'yii\web\ErrorAction', | ||
52 | + ], | ||
53 | + ]; | ||
54 | + } | ||
55 | + | ||
56 | + /** | ||
57 | + * Displays homepage. | ||
58 | + * | ||
59 | + * @return string | ||
60 | + */ | ||
61 | + public function actionIndex() | ||
62 | + { | ||
63 | + return $this->render('index'); | ||
64 | + } | ||
65 | + | ||
66 | + /** | ||
67 | + * Login action. | ||
68 | + * | ||
69 | + * @return string | ||
70 | + */ | ||
71 | + public function actionLogin() | ||
72 | + { | ||
73 | + if (!Yii::$app->user->isGuest) { | ||
74 | + return $this->goHome(); | ||
75 | + } | ||
76 | + | ||
77 | + $model = new LoginForm(); | ||
78 | + if ($model->load(Yii::$app->request->post()) && $model->login()) { | ||
79 | + return $this->goBack(); | ||
80 | + } else { | ||
81 | + return $this->render('login', [ | ||
82 | + 'model' => $model, | ||
83 | + ]); | ||
84 | + } | ||
85 | + } | ||
86 | + | ||
87 | + /** | ||
88 | + * Logout action. | ||
89 | + * | ||
90 | + * @return string | ||
91 | + */ | ||
92 | + public function actionLogout() | ||
93 | + { | ||
94 | + Yii::$app->user->logout(); | ||
95 | + | ||
96 | + return $this->goHome(); | ||
97 | + } | ||
98 | +} |
1 | +++ a/backend/tests/_bootstrap.php | ||
1 | +<?php | ||
2 | +defined('YII_DEBUG') or define('YII_DEBUG', true); | ||
3 | +defined('YII_ENV') or define('YII_ENV', 'test'); | ||
4 | +defined('YII_APP_BASE_PATH') or define('YII_APP_BASE_PATH', __DIR__.'/../../'); | ||
5 | + | ||
6 | +require_once(YII_APP_BASE_PATH . '/vendor/autoload.php'); | ||
7 | +require_once(YII_APP_BASE_PATH . '/vendor/yiisoft/yii2/Yii.php'); | ||
8 | +require_once(YII_APP_BASE_PATH . '/common/config/bootstrap.php'); | ||
9 | +require_once(__DIR__ . '/../config/bootstrap.php'); |
1 | +++ a/backend/tests/_data/.gitignore |
1 | +++ a/backend/tests/_data/login_data.php | ||
1 | +<?php | ||
2 | +return [ | ||
3 | + [ | ||
4 | + 'username' => 'erau', | ||
5 | + 'auth_key' => 'tUu1qHcde0diwUol3xeI-18MuHkkprQI', | ||
6 | + // password_0 | ||
7 | + 'password_hash' => '$2y$13$nJ1WDlBaGcbCdbNC5.5l4.sgy.OMEKCqtDQOdQ2OWpgiKRWYyzzne', | ||
8 | + 'password_reset_token' => 'RkD_Jw0_8HEedzLk7MM-ZKEFfYR7VbMr_1392559490', | ||
9 | + 'created_at' => '1392559490', | ||
10 | + 'updated_at' => '1392559490', | ||
11 | + 'email' => 'sfriesen@jenkins.info', | ||
12 | + ], | ||
13 | +]; |
1 | +++ a/backend/tests/_support/FunctionalTester.php | ||
1 | +<?php | ||
2 | +namespace backend\tests; | ||
3 | + | ||
4 | +/** | ||
5 | + * Inherited Methods | ||
6 | + * @method void wantToTest($text) | ||
7 | + * @method void wantTo($text) | ||
8 | + * @method void execute($callable) | ||
9 | + * @method void expectTo($prediction) | ||
10 | + * @method void expect($prediction) | ||
11 | + * @method void amGoingTo($argumentation) | ||
12 | + * @method void am($role) | ||
13 | + * @method void lookForwardTo($achieveValue) | ||
14 | + * @method void comment($description) | ||
15 | + * @method \Codeception\Lib\Friend haveFriend($name, $actorClass = NULL) | ||
16 | + * | ||
17 | + * @SuppressWarnings(PHPMD) | ||
18 | + */ | ||
19 | +class FunctionalTester extends \Codeception\Actor | ||
20 | +{ | ||
21 | + use _generated\FunctionalTesterActions; | ||
22 | + /** | ||
23 | + * Define custom actions here | ||
24 | + */ | ||
25 | +} |
1 | +++ a/backend/tests/_support/UnitTester.php | ||
1 | +<?php | ||
2 | +namespace backend\tests; | ||
3 | + | ||
4 | +/** | ||
5 | + * Inherited Methods | ||
6 | + * @method void wantToTest($text) | ||
7 | + * @method void wantTo($text) | ||
8 | + * @method void execute($callable) | ||
9 | + * @method void expectTo($prediction) | ||
10 | + * @method void expect($prediction) | ||
11 | + * @method void amGoingTo($argumentation) | ||
12 | + * @method void am($role) | ||
13 | + * @method void lookForwardTo($achieveValue) | ||
14 | + * @method void comment($description) | ||
15 | + * @method \Codeception\Lib\Friend haveFriend($name, $actorClass = NULL) | ||
16 | + * | ||
17 | + * @SuppressWarnings(PHPMD) | ||
18 | + */ | ||
19 | +class UnitTester extends \Codeception\Actor | ||
20 | +{ | ||
21 | + use _generated\UnitTesterActions; | ||
22 | + /** | ||
23 | + * Define custom actions here | ||
24 | + */ | ||
25 | +} |
1 | +++ a/backend/tests/functional/LoginCest.php | ||
1 | +<?php | ||
2 | + | ||
3 | +namespace backend\tests\functional; | ||
4 | + | ||
5 | +use \backend\tests\FunctionalTester; | ||
6 | +use common\fixtures\User as UserFixture; | ||
7 | + | ||
8 | +/** | ||
9 | + * Class LoginCest | ||
10 | + */ | ||
11 | +class LoginCest | ||
12 | +{ | ||
13 | + public function _before(FunctionalTester $I) | ||
14 | + { | ||
15 | + $I->haveFixtures([ | ||
16 | + 'user' => [ | ||
17 | + 'class' => UserFixture::className(), | ||
18 | + 'dataFile' => codecept_data_dir() . 'login_data.php' | ||
19 | + ] | ||
20 | + ]); | ||
21 | + } | ||
22 | + /** | ||
23 | + * @param FunctionalTester $I | ||
24 | + */ | ||
25 | + public function loginUser(FunctionalTester $I) | ||
26 | + { | ||
27 | + $I->amOnPage('/site/login'); | ||
28 | + $I->fillField('Username', 'erau'); | ||
29 | + $I->fillField('Password', 'password_0'); | ||
30 | + $I->click('login-button'); | ||
31 | + | ||
32 | + $I->see('Logout (erau)', 'form button[type=submit]'); | ||
33 | + $I->dontSeeLink('Login'); | ||
34 | + $I->dontSeeLink('Signup'); | ||
35 | + } | ||
36 | +} |
1 | +++ a/backend/views/layouts/main.php | ||
1 | +<?php | ||
2 | + | ||
3 | +/* @var $this \yii\web\View */ | ||
4 | +/* @var $content string */ | ||
5 | + | ||
6 | +use backend\assets\AppAsset; | ||
7 | +use yii\helpers\Html; | ||
8 | +use yii\bootstrap\Nav; | ||
9 | +use yii\bootstrap\NavBar; | ||
10 | +use yii\widgets\Breadcrumbs; | ||
11 | +use common\widgets\Alert; | ||
12 | + | ||
13 | +AppAsset::register($this); | ||
14 | +?> | ||
15 | +<?php $this->beginPage() ?> | ||
16 | +<!DOCTYPE html> | ||
17 | +<html lang="<?= Yii::$app->language ?>"> | ||
18 | +<head> | ||
19 | + <meta charset="<?= Yii::$app->charset ?>"> | ||
20 | + <meta name="viewport" content="width=device-width, initial-scale=1"> | ||
21 | + <?= Html::csrfMetaTags() ?> | ||
22 | + <title><?= Html::encode($this->title) ?></title> | ||
23 | + <?php $this->head() ?> | ||
24 | +</head> | ||
25 | +<body> | ||
26 | +<?php $this->beginBody() ?> | ||
27 | + | ||
28 | +<div class="wrap"> | ||
29 | + <?php | ||
30 | + NavBar::begin([ | ||
31 | + 'brandLabel' => 'My Company', | ||
32 | + 'brandUrl' => Yii::$app->homeUrl, | ||
33 | + 'options' => [ | ||
34 | + 'class' => 'navbar-inverse navbar-fixed-top', | ||
35 | + ], | ||
36 | + ]); | ||
37 | + $menuItems = [ | ||
38 | + ['label' => 'Home', 'url' => ['/site/index']], | ||
39 | + ]; | ||
40 | + if (Yii::$app->user->isGuest) { | ||
41 | + $menuItems[] = ['label' => 'Login', 'url' => ['/site/login']]; | ||
42 | + } else { | ||
43 | + $menuItems[] = '<li>' | ||
44 | + . Html::beginForm(['/site/logout'], 'post') | ||
45 | + . Html::submitButton( | ||
46 | + 'Logout (' . Yii::$app->user->identity->username . ')', | ||
47 | + ['class' => 'btn btn-link logout'] | ||
48 | + ) | ||
49 | + . Html::endForm() | ||
50 | + . '</li>'; | ||
51 | + } | ||
52 | + echo Nav::widget([ | ||
53 | + 'options' => ['class' => 'navbar-nav navbar-right'], | ||
54 | + 'items' => $menuItems, | ||
55 | + ]); | ||
56 | + NavBar::end(); | ||
57 | + ?> | ||
58 | + | ||
59 | + <div class="container"> | ||
60 | + <?= Breadcrumbs::widget([ | ||
61 | + 'links' => isset($this->params['breadcrumbs']) ? $this->params['breadcrumbs'] : [], | ||
62 | + ]) ?> | ||
63 | + <?= Alert::widget() ?> | ||
64 | + <?= $content ?> | ||
65 | + </div> | ||
66 | +</div> | ||
67 | + | ||
68 | +<footer class="footer"> | ||
69 | + <div class="container"> | ||
70 | + <p class="pull-left">© My Company <?= date('Y') ?></p> | ||
71 | + | ||
72 | + <p class="pull-right"><?= Yii::powered() ?></p> | ||
73 | + </div> | ||
74 | +</footer> | ||
75 | + | ||
76 | +<?php $this->endBody() ?> | ||
77 | +</body> | ||
78 | +</html> | ||
79 | +<?php $this->endPage() ?> |
1 | +++ a/backend/views/site/error.php | ||
1 | +<?php | ||
2 | + | ||
3 | +/* @var $this yii\web\View */ | ||
4 | +/* @var $name string */ | ||
5 | +/* @var $message string */ | ||
6 | +/* @var $exception Exception */ | ||
7 | + | ||
8 | +use yii\helpers\Html; | ||
9 | + | ||
10 | +$this->title = $name; | ||
11 | +?> | ||
12 | +<div class="site-error"> | ||
13 | + | ||
14 | + <h1><?= Html::encode($this->title) ?></h1> | ||
15 | + | ||
16 | + <div class="alert alert-danger"> | ||
17 | + <?= nl2br(Html::encode($message)) ?> | ||
18 | + </div> | ||
19 | + | ||
20 | + <p> | ||
21 | + The above error occurred while the Web server was processing your request. | ||
22 | + </p> | ||
23 | + <p> | ||
24 | + Please contact us if you think this is a server error. Thank you. | ||
25 | + </p> | ||
26 | + | ||
27 | +</div> |
1 | +++ a/backend/views/site/index.php | ||
1 | +<?php | ||
2 | + | ||
3 | +/* @var $this yii\web\View */ | ||
4 | + | ||
5 | +$this->title = 'My Yii Application'; | ||
6 | +?> | ||
7 | +<div class="site-index"> | ||
8 | + | ||
9 | + <div class="jumbotron"> | ||
10 | + <h1>Congratulations!</h1> | ||
11 | + | ||
12 | + <p class="lead">You have successfully created your Yii-powered application.</p> | ||
13 | + | ||
14 | + <p><a class="btn btn-lg btn-success" href="http://www.yiiframework.com">Get started with Yii</a></p> | ||
15 | + </div> | ||
16 | + | ||
17 | + <div class="body-content"> | ||
18 | + | ||
19 | + <div class="row"> | ||
20 | + <div class="col-lg-4"> | ||
21 | + <h2>Heading</h2> | ||
22 | + | ||
23 | + <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et | ||
24 | + dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip | ||
25 | + ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu | ||
26 | + fugiat nulla pariatur.</p> | ||
27 | + | ||
28 | + <p><a class="btn btn-default" href="http://www.yiiframework.com/doc/">Yii Documentation »</a></p> | ||
29 | + </div> | ||
30 | + <div class="col-lg-4"> | ||
31 | + <h2>Heading</h2> | ||
32 | + | ||
33 | + <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et | ||
34 | + dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip | ||
35 | + ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu | ||
36 | + fugiat nulla pariatur.</p> | ||
37 | + | ||
38 | + <p><a class="btn btn-default" href="http://www.yiiframework.com/forum/">Yii Forum »</a></p> | ||
39 | + </div> | ||
40 | + <div class="col-lg-4"> | ||
41 | + <h2>Heading</h2> | ||
42 | + | ||
43 | + <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et | ||
44 | + dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip | ||
45 | + ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu | ||
46 | + fugiat nulla pariatur.</p> | ||
47 | + | ||
48 | + <p><a class="btn btn-default" href="http://www.yiiframework.com/extensions/">Yii Extensions »</a></p> | ||
49 | + </div> | ||
50 | + </div> | ||
51 | + | ||
52 | + </div> | ||
53 | +</div> |
1 | +++ a/backend/views/site/login.php | ||
1 | +<?php | ||
2 | + | ||
3 | +/* @var $this yii\web\View */ | ||
4 | +/* @var $form yii\bootstrap\ActiveForm */ | ||
5 | +/* @var $model \common\models\LoginForm */ | ||
6 | + | ||
7 | +use yii\helpers\Html; | ||
8 | +use yii\bootstrap\ActiveForm; | ||
9 | + | ||
10 | +$this->title = 'Login'; | ||
11 | +$this->params['breadcrumbs'][] = $this->title; | ||
12 | +?> | ||
13 | +<div class="site-login"> | ||
14 | + <h1><?= Html::encode($this->title) ?></h1> | ||
15 | + | ||
16 | + <p>Please fill out the following fields to login:</p> | ||
17 | + | ||
18 | + <div class="row"> | ||
19 | + <div class="col-lg-5"> | ||
20 | + <?php $form = ActiveForm::begin(['id' => 'login-form']); ?> | ||
21 | + | ||
22 | + <?= $form->field($model, 'username')->textInput(['autofocus' => true]) ?> | ||
23 | + | ||
24 | + <?= $form->field($model, 'password')->passwordInput() ?> | ||
25 | + | ||
26 | + <?= $form->field($model, 'rememberMe')->checkbox() ?> | ||
27 | + | ||
28 | + <div class="form-group"> | ||
29 | + <?= Html::submitButton('Login', ['class' => 'btn btn-primary', 'name' => 'login-button']) ?> | ||
30 | + </div> | ||
31 | + | ||
32 | + <?php ActiveForm::end(); ?> | ||
33 | + </div> | ||
34 | + </div> | ||
35 | +</div> |
1 | +++ a/backend/web/css/site.css | ||
1 | +html, | ||
2 | +body { | ||
3 | + height: 100%; | ||
4 | +} | ||
5 | + | ||
6 | +.wrap { | ||
7 | + min-height: 100%; | ||
8 | + height: auto; | ||
9 | + margin: 0 auto -60px; | ||
10 | + padding: 0 0 60px; | ||
11 | +} | ||
12 | + | ||
13 | +.wrap > .container { | ||
14 | + padding: 70px 15px 20px; | ||
15 | +} | ||
16 | + | ||
17 | +.footer { | ||
18 | + height: 60px; | ||
19 | + background-color: #f5f5f5; | ||
20 | + border-top: 1px solid #ddd; | ||
21 | + padding-top: 20px; | ||
22 | +} | ||
23 | + | ||
24 | +.jumbotron { | ||
25 | + text-align: center; | ||
26 | + background-color: transparent; | ||
27 | +} | ||
28 | + | ||
29 | +.jumbotron .btn { | ||
30 | + font-size: 21px; | ||
31 | + padding: 14px 24px; | ||
32 | +} | ||
33 | + | ||
34 | +.not-set { | ||
35 | + color: #c55; | ||
36 | + font-style: italic; | ||
37 | +} | ||
38 | + | ||
39 | +/* add sorting icons to gridview sort links */ | ||
40 | +a.asc:after, a.desc:after { | ||
41 | + position: relative; | ||
42 | + top: 1px; | ||
43 | + display: inline-block; | ||
44 | + font-family: 'Glyphicons Halflings'; | ||
45 | + font-style: normal; | ||
46 | + font-weight: normal; | ||
47 | + line-height: 1; | ||
48 | + padding-left: 5px; | ||
49 | +} | ||
50 | + | ||
51 | +a.asc:after { | ||
52 | + content: /*"\e113"*/ "\e151"; | ||
53 | +} | ||
54 | + | ||
55 | +a.desc:after { | ||
56 | + content: /*"\e114"*/ "\e152"; | ||
57 | +} | ||
58 | + | ||
59 | +.sort-numerical a.asc:after { | ||
60 | + content: "\e153"; | ||
61 | +} | ||
62 | + | ||
63 | +.sort-numerical a.desc:after { | ||
64 | + content: "\e154"; | ||
65 | +} | ||
66 | + | ||
67 | +.sort-ordinal a.asc:after { | ||
68 | + content: "\e155"; | ||
69 | +} | ||
70 | + | ||
71 | +.sort-ordinal a.desc:after { | ||
72 | + content: "\e156"; | ||
73 | +} | ||
74 | + | ||
75 | +.grid-view td { | ||
76 | + white-space: nowrap; | ||
77 | +} | ||
78 | + | ||
79 | +.grid-view .filters input, | ||
80 | +.grid-view .filters select { | ||
81 | + min-width: 50px; | ||
82 | +} | ||
83 | + | ||
84 | +.hint-block { | ||
85 | + display: block; | ||
86 | + margin-top: 5px; | ||
87 | + color: #999; | ||
88 | +} | ||
89 | + | ||
90 | +.error-summary { | ||
91 | + color: #a94442; | ||
92 | + background: #fdf7f7; | ||
93 | + border-left: 3px solid #eed3d7; | ||
94 | + padding: 10px 20px; | ||
95 | + margin: 0 0 15px 0; | ||
96 | +} | ||
97 | + | ||
98 | +/* align the logout "link" (button in form) of the navbar */ | ||
99 | +.nav li > form > button.logout { | ||
100 | + padding: 15px; | ||
101 | + border: none; | ||
102 | +} | ||
103 | + | ||
104 | +@media(max-width:767px) { | ||
105 | + .nav li > form > button.logout { | ||
106 | + display:block; | ||
107 | + text-align: left; | ||
108 | + width: 100%; | ||
109 | + padding: 10px 15px; | ||
110 | + } | ||
111 | +} | ||
112 | + | ||
113 | +.nav > li > form > button.logout:focus, | ||
114 | +.nav > li > form > button.logout:hover { | ||
115 | + text-decoration: none; | ||
116 | +} | ||
117 | + | ||
118 | +.nav > li > form > button.logout:focus { | ||
119 | + outline: none; | ||
120 | +} |
No preview for this file type
1 | +++ a/common/codeception.yml | ||
1 | +namespace: common\tests | ||
2 | +actor: Tester | ||
3 | +paths: | ||
4 | + tests: tests | ||
5 | + log: tests/_output | ||
6 | + data: tests/_data | ||
7 | + helpers: tests/_support | ||
8 | +settings: | ||
9 | + bootstrap: _bootstrap.php | ||
10 | + colors: true | ||
11 | + memory_limit: 1024M | ||
12 | +modules: | ||
13 | + config: | ||
14 | + Yii2: | ||
15 | + configFile: 'config/test-local.php' |
1 | +++ a/common/config/bootstrap.php | ||
1 | +<?php | ||
2 | +Yii::setAlias('@common', dirname(__DIR__)); | ||
3 | +Yii::setAlias('@frontend', dirname(dirname(__DIR__)) . '/frontend'); | ||
4 | +Yii::setAlias('@backend', dirname(dirname(__DIR__)) . '/backend'); | ||
5 | +Yii::setAlias('@console', dirname(dirname(__DIR__)) . '/console'); |
1 | +++ a/common/mail/layouts/html.php | ||
1 | +<?php | ||
2 | +use yii\helpers\Html; | ||
3 | + | ||
4 | +/* @var $this \yii\web\View view component instance */ | ||
5 | +/* @var $message \yii\mail\MessageInterface the message being composed */ | ||
6 | +/* @var $content string main view render result */ | ||
7 | +?> | ||
8 | +<?php $this->beginPage() ?> | ||
9 | +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> | ||
10 | +<html xmlns="http://www.w3.org/1999/xhtml"> | ||
11 | +<head> | ||
12 | + <meta http-equiv="Content-Type" content="text/html; charset=<?= Yii::$app->charset ?>" /> | ||
13 | + <title><?= Html::encode($this->title) ?></title> | ||
14 | + <?php $this->head() ?> | ||
15 | +</head> | ||
16 | +<body> | ||
17 | + <?php $this->beginBody() ?> | ||
18 | + <?= $content ?> | ||
19 | + <?php $this->endBody() ?> | ||
20 | +</body> | ||
21 | +</html> | ||
22 | +<?php $this->endPage() ?> |
1 | +++ a/common/mail/layouts/text.php | ||
1 | +<?php | ||
2 | + | ||
3 | +use yii\helpers\Html; | ||
4 | + | ||
5 | +/** @var \yii\web\View $this view component instance */ | ||
6 | +/** @var \yii\mail\MessageInterface $message the message being composed */ | ||
7 | +/** @var string $content main view render result */ | ||
8 | +?> | ||
9 | + | ||
10 | +<?php $this->beginPage() ?> | ||
11 | +<?php $this->beginBody() ?> | ||
12 | +<?= $content ?> | ||
13 | +<?php $this->endBody() ?> | ||
14 | +<?php $this->endPage() ?> |
1 | +++ a/common/mail/passwordResetToken-html.php | ||
1 | +<?php | ||
2 | +use yii\helpers\Html; | ||
3 | + | ||
4 | +/* @var $this yii\web\View */ | ||
5 | +/* @var $user common\models\User */ | ||
6 | + | ||
7 | +$resetLink = Yii::$app->urlManager->createAbsoluteUrl(['site/reset-password', 'token' => $user->password_reset_token]); | ||
8 | +?> | ||
9 | +<div class="password-reset"> | ||
10 | + <p>Hello <?= Html::encode($user->username) ?>,</p> | ||
11 | + | ||
12 | + <p>Follow the link below to reset your password:</p> | ||
13 | + | ||
14 | + <p><?= Html::a(Html::encode($resetLink), $resetLink) ?></p> | ||
15 | +</div> |
1 | +++ a/common/mail/passwordResetToken-text.php | ||
1 | +<?php | ||
2 | + | ||
3 | +/* @var $this yii\web\View */ | ||
4 | +/* @var $user common\models\User */ | ||
5 | + | ||
6 | +$resetLink = Yii::$app->urlManager->createAbsoluteUrl(['site/reset-password', 'token' => $user->password_reset_token]); | ||
7 | +?> | ||
8 | +Hello <?= $user->username ?>, | ||
9 | + | ||
10 | +Follow the link below to reset your password: | ||
11 | + | ||
12 | +<?= $resetLink ?> |
1 | +++ a/common/models/LoginForm.php | ||
1 | +<?php | ||
2 | +namespace common\models; | ||
3 | + | ||
4 | +use Yii; | ||
5 | +use yii\base\Model; | ||
6 | + | ||
7 | +/** | ||
8 | + * Login form | ||
9 | + */ | ||
10 | +class LoginForm extends Model | ||
11 | +{ | ||
12 | + public $username; | ||
13 | + public $password; | ||
14 | + public $rememberMe = true; | ||
15 | + | ||
16 | + private $_user; | ||
17 | + | ||
18 | + | ||
19 | + /** | ||
20 | + * @inheritdoc | ||
21 | + */ | ||
22 | + public function rules() | ||
23 | + { | ||
24 | + return [ | ||
25 | + // username and password are both required | ||
26 | + [['username', 'password'], 'required'], | ||
27 | + // rememberMe must be a boolean value | ||
28 | + ['rememberMe', 'boolean'], | ||
29 | + // password is validated by validatePassword() | ||
30 | + ['password', 'validatePassword'], | ||
31 | + ]; | ||
32 | + } | ||
33 | + | ||
34 | + /** | ||
35 | + * Validates the password. | ||
36 | + * This method serves as the inline validation for password. | ||
37 | + * | ||
38 | + * @param string $attribute the attribute currently being validated | ||
39 | + * @param array $params the additional name-value pairs given in the rule | ||
40 | + */ | ||
41 | + public function validatePassword($attribute, $params) | ||
42 | + { | ||
43 | + if (!$this->hasErrors()) { | ||
44 | + $user = $this->getUser(); | ||
45 | + if (!$user || !$user->validatePassword($this->password)) { | ||
46 | + $this->addError($attribute, 'Incorrect username or password.'); | ||
47 | + } | ||
48 | + } | ||
49 | + } | ||
50 | + | ||
51 | + /** | ||
52 | + * Logs in a user using the provided username and password. | ||
53 | + * | ||
54 | + * @return bool whether the user is logged in successfully | ||
55 | + */ | ||
56 | + public function login() | ||
57 | + { | ||
58 | + if ($this->validate()) { | ||
59 | + return Yii::$app->user->login($this->getUser(), $this->rememberMe ? 3600 * 24 * 30 : 0); | ||
60 | + } else { | ||
61 | + return false; | ||
62 | + } | ||
63 | + } | ||
64 | + | ||
65 | + /** | ||
66 | + * Finds user by [[username]] | ||
67 | + * | ||
68 | + * @return User|null | ||
69 | + */ | ||
70 | + protected function getUser() | ||
71 | + { | ||
72 | + if ($this->_user === null) { | ||
73 | + $this->_user = User::findByUsername($this->username); | ||
74 | + } | ||
75 | + | ||
76 | + return $this->_user; | ||
77 | + } | ||
78 | +} |
1 | +++ a/common/models/User.php | ||
1 | +<?php | ||
2 | +namespace common\models; | ||
3 | + | ||
4 | +use Yii; | ||
5 | +use yii\base\NotSupportedException; | ||
6 | +use yii\behaviors\TimestampBehavior; | ||
7 | +use yii\db\ActiveRecord; | ||
8 | +use yii\web\IdentityInterface; | ||
9 | + | ||
10 | +/** | ||
11 | + * User model | ||
12 | + * | ||
13 | + * @property integer $id | ||
14 | + * @property string $username | ||
15 | + * @property string $password_hash | ||
16 | + * @property string $password_reset_token | ||
17 | + * @property string $email | ||
18 | + * @property string $auth_key | ||
19 | + * @property integer $status | ||
20 | + * @property integer $created_at | ||
21 | + * @property integer $updated_at | ||
22 | + * @property string $password write-only password | ||
23 | + */ | ||
24 | +class User extends ActiveRecord implements IdentityInterface | ||
25 | +{ | ||
26 | + const STATUS_DELETED = 0; | ||
27 | + const STATUS_ACTIVE = 10; | ||
28 | + | ||
29 | + | ||
30 | + /** | ||
31 | + * @inheritdoc | ||
32 | + */ | ||
33 | + public static function tableName() | ||
34 | + { | ||
35 | + return '{{%user}}'; | ||
36 | + } | ||
37 | + | ||
38 | + /** | ||
39 | + * @inheritdoc | ||
40 | + */ | ||
41 | + public function behaviors() | ||
42 | + { | ||
43 | + return [ | ||
44 | + TimestampBehavior::className(), | ||
45 | + ]; | ||
46 | + } | ||
47 | + | ||
48 | + /** | ||
49 | + * @inheritdoc | ||
50 | + */ | ||
51 | + public function rules() | ||
52 | + { | ||
53 | + return [ | ||
54 | + ['status', 'default', 'value' => self::STATUS_ACTIVE], | ||
55 | + ['status', 'in', 'range' => [self::STATUS_ACTIVE, self::STATUS_DELETED]], | ||
56 | + ]; | ||
57 | + } | ||
58 | + | ||
59 | + /** | ||
60 | + * @inheritdoc | ||
61 | + */ | ||
62 | + public static function findIdentity($id) | ||
63 | + { | ||
64 | + return static::findOne(['id' => $id, 'status' => self::STATUS_ACTIVE]); | ||
65 | + } | ||
66 | + | ||
67 | + /** | ||
68 | + * @inheritdoc | ||
69 | + */ | ||
70 | + public static function findIdentityByAccessToken($token, $type = null) | ||
71 | + { | ||
72 | + throw new NotSupportedException('"findIdentityByAccessToken" is not implemented.'); | ||
73 | + } | ||
74 | + | ||
75 | + /** | ||
76 | + * Finds user by username | ||
77 | + * | ||
78 | + * @param string $username | ||
79 | + * @return static|null | ||
80 | + */ | ||
81 | + public static function findByUsername($username) | ||
82 | + { | ||
83 | + return static::findOne(['username' => $username, 'status' => self::STATUS_ACTIVE]); | ||
84 | + } | ||
85 | + | ||
86 | + /** | ||
87 | + * Finds user by password reset token | ||
88 | + * | ||
89 | + * @param string $token password reset token | ||
90 | + * @return static|null | ||
91 | + */ | ||
92 | + public static function findByPasswordResetToken($token) | ||
93 | + { | ||
94 | + if (!static::isPasswordResetTokenValid($token)) { | ||
95 | + return null; | ||
96 | + } | ||
97 | + | ||
98 | + return static::findOne([ | ||
99 | + 'password_reset_token' => $token, | ||
100 | + 'status' => self::STATUS_ACTIVE, | ||
101 | + ]); | ||
102 | + } | ||
103 | + | ||
104 | + /** | ||
105 | + * Finds out if password reset token is valid | ||
106 | + * | ||
107 | + * @param string $token password reset token | ||
108 | + * @return bool | ||
109 | + */ | ||
110 | + public static function isPasswordResetTokenValid($token) | ||
111 | + { | ||
112 | + if (empty($token)) { | ||
113 | + return false; | ||
114 | + } | ||
115 | + | ||
116 | + $timestamp = (int) substr($token, strrpos($token, '_') + 1); | ||
117 | + $expire = Yii::$app->params['user.passwordResetTokenExpire']; | ||
118 | + return $timestamp + $expire >= time(); | ||
119 | + } | ||
120 | + | ||
121 | + /** | ||
122 | + * @inheritdoc | ||
123 | + */ | ||
124 | + public function getId() | ||
125 | + { | ||
126 | + return $this->getPrimaryKey(); | ||
127 | + } | ||
128 | + | ||
129 | + /** | ||
130 | + * @inheritdoc | ||
131 | + */ | ||
132 | + public function getAuthKey() | ||
133 | + { | ||
134 | + return $this->auth_key; | ||
135 | + } | ||
136 | + | ||
137 | + /** | ||
138 | + * @inheritdoc | ||
139 | + */ | ||
140 | + public function validateAuthKey($authKey) | ||
141 | + { | ||
142 | + return $this->getAuthKey() === $authKey; | ||
143 | + } | ||
144 | + | ||
145 | + /** | ||
146 | + * Validates password | ||
147 | + * | ||
148 | + * @param string $password password to validate | ||
149 | + * @return bool if password provided is valid for current user | ||
150 | + */ | ||
151 | + public function validatePassword($password) | ||
152 | + { | ||
153 | + return Yii::$app->security->validatePassword($password, $this->password_hash); | ||
154 | + } | ||
155 | + | ||
156 | + /** | ||
157 | + * Generates password hash from password and sets it to the model | ||
158 | + * | ||
159 | + * @param string $password | ||
160 | + */ | ||
161 | + public function setPassword($password) | ||
162 | + { | ||
163 | + $this->password_hash = Yii::$app->security->generatePasswordHash($password); | ||
164 | + } | ||
165 | + | ||
166 | + /** | ||
167 | + * Generates "remember me" authentication key | ||
168 | + */ | ||
169 | + public function generateAuthKey() | ||
170 | + { | ||
171 | + $this->auth_key = Yii::$app->security->generateRandomString(); | ||
172 | + } | ||
173 | + | ||
174 | + /** | ||
175 | + * Generates new password reset token | ||
176 | + */ | ||
177 | + public function generatePasswordResetToken() | ||
178 | + { | ||
179 | + $this->password_reset_token = Yii::$app->security->generateRandomString() . '_' . time(); | ||
180 | + } | ||
181 | + | ||
182 | + /** | ||
183 | + * Removes password reset token | ||
184 | + */ | ||
185 | + public function removePasswordResetToken() | ||
186 | + { | ||
187 | + $this->password_reset_token = null; | ||
188 | + } | ||
189 | +} |
1 | +++ a/common/tests/_bootstrap.php | ||
1 | +<?php | ||
2 | +defined('YII_DEBUG') or define('YII_DEBUG', true); | ||
3 | +defined('YII_ENV') or define('YII_ENV', 'test'); | ||
4 | +defined('YII_APP_BASE_PATH') or define('YII_APP_BASE_PATH', __DIR__.'/../../'); | ||
5 | + | ||
6 | +require_once(__DIR__ . '/../../vendor/autoload.php'); | ||
7 | +require_once(__DIR__ . '/../../vendor/yiisoft/yii2/Yii.php'); | ||
8 | +require(__DIR__ . '/../config/bootstrap.php'); | ||
9 | + |
1 | +++ a/common/tests/_data/user.php | ||
1 | +<?php | ||
2 | + | ||
3 | +return [ | ||
4 | + [ | ||
5 | + 'username' => 'bayer.hudson', | ||
6 | + 'auth_key' => 'HP187Mvq7Mmm3CTU80dLkGmni_FUH_lR', | ||
7 | + //password_0 | ||
8 | + 'password_hash' => '$2y$13$EjaPFBnZOQsHdGuHI.xvhuDp1fHpo8hKRSk6yshqa9c5EG8s3C3lO', | ||
9 | + 'password_reset_token' => 'ExzkCOaYc1L8IOBs4wdTGGbgNiG3Wz1I_1402312317', | ||
10 | + 'created_at' => '1402312317', | ||
11 | + 'updated_at' => '1402312317', | ||
12 | + 'email' => 'nicole.paucek@schultz.info', | ||
13 | + ], | ||
14 | +]; |
1 | +++ a/common/tests/_support/UnitTester.php | ||
1 | +<?php | ||
2 | +namespace common\tests; | ||
3 | + | ||
4 | +/** | ||
5 | + * Inherited Methods | ||
6 | + * @method void wantToTest($text) | ||
7 | + * @method void wantTo($text) | ||
8 | + * @method void execute($callable) | ||
9 | + * @method void expectTo($prediction) | ||
10 | + * @method void expect($prediction) | ||
11 | + * @method void amGoingTo($argumentation) | ||
12 | + * @method void am($role) | ||
13 | + * @method void lookForwardTo($achieveValue) | ||
14 | + * @method void comment($description) | ||
15 | + * @method \Codeception\Lib\Friend haveFriend($name, $actorClass = NULL) | ||
16 | + * | ||
17 | + * @SuppressWarnings(PHPMD) | ||
18 | + */ | ||
19 | +class UnitTester extends \Codeception\Actor | ||
20 | +{ | ||
21 | + use _generated\UnitTesterActions; | ||
22 | + /** | ||
23 | + * Define custom actions here | ||
24 | + */ | ||
25 | +} |
1 | +++ a/common/tests/unit/models/LoginFormTest.php | ||
1 | +<?php | ||
2 | + | ||
3 | +namespace common\tests\unit\models; | ||
4 | + | ||
5 | +use Yii; | ||
6 | +use common\models\LoginForm; | ||
7 | +use common\fixtures\User as UserFixture; | ||
8 | + | ||
9 | +/** | ||
10 | + * Login form test | ||
11 | + */ | ||
12 | +class LoginFormTest extends \Codeception\Test\Unit | ||
13 | +{ | ||
14 | + /** | ||
15 | + * @var \frontend\tests\UnitTester | ||
16 | + */ | ||
17 | + protected $tester; | ||
18 | + | ||
19 | + | ||
20 | + public function _before() | ||
21 | + { | ||
22 | + $this->tester->haveFixtures([ | ||
23 | + 'user' => [ | ||
24 | + 'class' => UserFixture::className(), | ||
25 | + 'dataFile' => codecept_data_dir() . 'user.php' | ||
26 | + ] | ||
27 | + ]); | ||
28 | + } | ||
29 | + | ||
30 | + public function testLoginNoUser() | ||
31 | + { | ||
32 | + $model = new LoginForm([ | ||
33 | + 'username' => 'not_existing_username', | ||
34 | + 'password' => 'not_existing_password', | ||
35 | + ]); | ||
36 | + | ||
37 | + expect('model should not login user', $model->login())->false(); | ||
38 | + expect('user should not be logged in', Yii::$app->user->isGuest)->true(); | ||
39 | + } | ||
40 | + | ||
41 | + public function testLoginWrongPassword() | ||
42 | + { | ||
43 | + $model = new LoginForm([ | ||
44 | + 'username' => 'bayer.hudson', | ||
45 | + 'password' => 'wrong_password', | ||
46 | + ]); | ||
47 | + | ||
48 | + expect('model should not login user', $model->login())->false(); | ||
49 | + expect('error message should be set', $model->errors)->hasKey('password'); | ||
50 | + expect('user should not be logged in', Yii::$app->user->isGuest)->true(); | ||
51 | + } | ||
52 | + | ||
53 | + public function testLoginCorrect() | ||
54 | + { | ||
55 | + $model = new LoginForm([ | ||
56 | + 'username' => 'bayer.hudson', | ||
57 | + 'password' => 'password_0', | ||
58 | + ]); | ||
59 | + | ||
60 | + expect('model should login user', $model->login())->true(); | ||
61 | + expect('error message should not be set', $model->errors)->hasntKey('password'); | ||
62 | + expect('user should be logged in', Yii::$app->user->isGuest)->false(); | ||
63 | + } | ||
64 | +} |
1 | +++ a/common/widgets/Alert.php | ||
1 | +<?php | ||
2 | +namespace common\widgets; | ||
3 | + | ||
4 | +use Yii; | ||
5 | + | ||
6 | +/** | ||
7 | + * Alert widget renders a message from session flash. All flash messages are displayed | ||
8 | + * in the sequence they were assigned using setFlash. You can set message as following: | ||
9 | + * | ||
10 | + * ```php | ||
11 | + * Yii::$app->session->setFlash('error', 'This is the message'); | ||
12 | + * Yii::$app->session->setFlash('success', 'This is the message'); | ||
13 | + * Yii::$app->session->setFlash('info', 'This is the message'); | ||
14 | + * ``` | ||
15 | + * | ||
16 | + * Multiple messages could be set as follows: | ||
17 | + * | ||
18 | + * ```php | ||
19 | + * Yii::$app->session->setFlash('error', ['Error 1', 'Error 2']); | ||
20 | + * ``` | ||
21 | + * | ||
22 | + * @author Kartik Visweswaran <kartikv2@gmail.com> | ||
23 | + * @author Alexander Makarov <sam@rmcreative.ru> | ||
24 | + */ | ||
25 | +class Alert extends \yii\bootstrap\Widget | ||
26 | +{ | ||
27 | + /** | ||
28 | + * @var array the alert types configuration for the flash messages. | ||
29 | + * This array is setup as $key => $value, where: | ||
30 | + * - $key is the name of the session flash variable | ||
31 | + * - $value is the bootstrap alert type (i.e. danger, success, info, warning) | ||
32 | + */ | ||
33 | + public $alertTypes = [ | ||
34 | + 'error' => 'alert-danger', | ||
35 | + 'danger' => 'alert-danger', | ||
36 | + 'success' => 'alert-success', | ||
37 | + 'info' => 'alert-info', | ||
38 | + 'warning' => 'alert-warning' | ||
39 | + ]; | ||
40 | + /** | ||
41 | + * @var array the options for rendering the close button tag. | ||
42 | + */ | ||
43 | + public $closeButton = []; | ||
44 | + | ||
45 | + | ||
46 | + public function init() | ||
47 | + { | ||
48 | + parent::init(); | ||
49 | + | ||
50 | + $session = Yii::$app->session; | ||
51 | + $flashes = $session->getAllFlashes(); | ||
52 | + $appendCss = isset($this->options['class']) ? ' ' . $this->options['class'] : ''; | ||
53 | + | ||
54 | + foreach ($flashes as $type => $data) { | ||
55 | + if (isset($this->alertTypes[$type])) { | ||
56 | + $data = (array) $data; | ||
57 | + foreach ($data as $i => $message) { | ||
58 | + /* initialize css class for each alert box */ | ||
59 | + $this->options['class'] = $this->alertTypes[$type] . $appendCss; | ||
60 | + | ||
61 | + /* assign unique id to each alert box */ | ||
62 | + $this->options['id'] = $this->getId() . '-' . $type . '-' . $i; | ||
63 | + | ||
64 | + echo \yii\bootstrap\Alert::widget([ | ||
65 | + 'body' => $message, | ||
66 | + 'closeButton' => $this->closeButton, | ||
67 | + 'options' => $this->options, | ||
68 | + ]); | ||
69 | + } | ||
70 | + | ||
71 | + $session->removeFlash($type); | ||
72 | + } | ||
73 | + } | ||
74 | + } | ||
75 | +} |
1 | +++ a/composer.json | ||
1 | +{ | ||
2 | + "name": "yiisoft/yii2-app-advanced", | ||
3 | + "description": "Yii 2 Advanced Project Template", | ||
4 | + "keywords": ["yii2", "framework", "advanced", "project template"], | ||
5 | + "homepage": "http://www.yiiframework.com/", | ||
6 | + "type": "project", | ||
7 | + "license": "BSD-3-Clause", | ||
8 | + "support": { | ||
9 | + "issues": "https://github.com/yiisoft/yii2/issues?state=open", | ||
10 | + "forum": "http://www.yiiframework.com/forum/", | ||
11 | + "wiki": "http://www.yiiframework.com/wiki/", | ||
12 | + "irc": "irc://irc.freenode.net/yii", | ||
13 | + "source": "https://github.com/yiisoft/yii2" | ||
14 | + }, | ||
15 | + "minimum-stability": "stable", | ||
16 | + "require": { | ||
17 | + "php": ">=5.4.0", | ||
18 | + "yiisoft/yii2": "~2.0.6", | ||
19 | + "yiisoft/yii2-bootstrap": "~2.0.0", | ||
20 | + "yiisoft/yii2-swiftmailer": "~2.0.0" | ||
21 | + }, | ||
22 | + "require-dev": { | ||
23 | + "yiisoft/yii2-debug": "~2.0.0", | ||
24 | + "yiisoft/yii2-gii": "~2.0.0", | ||
25 | + "yiisoft/yii2-faker": "~2.0.0", | ||
26 | + | ||
27 | + "codeception/base": "^2.2.3", | ||
28 | + "codeception/verify": "~0.3.1" | ||
29 | + }, | ||
30 | + "config": { | ||
31 | + "process-timeout": 1800 | ||
32 | + }, | ||
33 | + "extra": { | ||
34 | + "asset-installer-paths": { | ||
35 | + "npm-asset-library": "vendor/npm", | ||
36 | + "bower-asset-library": "vendor/bower" | ||
37 | + } | ||
38 | + }, | ||
39 | + "scripts": { | ||
40 | + "post-install-cmd": "php init --env=Development --overwrite=n" | ||
41 | + } | ||
42 | +} |
1 | +++ a/console/config/main.php | ||
1 | +<?php | ||
2 | +$params = array_merge( | ||
3 | + require(__DIR__ . '/../../common/config/params.php'), | ||
4 | + require(__DIR__ . '/../../common/config/params-local.php'), | ||
5 | + require(__DIR__ . '/params.php'), | ||
6 | + require(__DIR__ . '/params-local.php') | ||
7 | +); | ||
8 | + | ||
9 | +return [ | ||
10 | + 'id' => 'app-console', | ||
11 | + 'basePath' => dirname(__DIR__), | ||
12 | + 'bootstrap' => ['log'], | ||
13 | + 'controllerNamespace' => 'console\controllers', | ||
14 | + 'components' => [ | ||
15 | + 'log' => [ | ||
16 | + 'targets' => [ | ||
17 | + [ | ||
18 | + 'class' => 'yii\log\FileTarget', | ||
19 | + 'levels' => ['error', 'warning'], | ||
20 | + ], | ||
21 | + ], | ||
22 | + ], | ||
23 | + ], | ||
24 | + 'params' => $params, | ||
25 | +]; |
1 | +++ a/console/controllers/.gitkeep |
1 | +++ a/console/migrations/m130524_201442_init.php | ||
1 | +<?php | ||
2 | + | ||
3 | +use yii\db\Migration; | ||
4 | + | ||
5 | +class m130524_201442_init extends Migration | ||
6 | +{ | ||
7 | + public function up() | ||
8 | + { | ||
9 | + $tableOptions = null; | ||
10 | + if ($this->db->driverName === 'mysql') { | ||
11 | + // http://stackoverflow.com/questions/766809/whats-the-difference-between-utf8-general-ci-and-utf8-unicode-ci | ||
12 | + $tableOptions = 'CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE=InnoDB'; | ||
13 | + } | ||
14 | + | ||
15 | + $this->createTable('{{%user}}', [ | ||
16 | + 'id' => $this->primaryKey(), | ||
17 | + 'username' => $this->string()->notNull()->unique(), | ||
18 | + 'auth_key' => $this->string(32)->notNull(), | ||
19 | + 'password_hash' => $this->string()->notNull(), | ||
20 | + 'password_reset_token' => $this->string()->unique(), | ||
21 | + 'email' => $this->string()->notNull()->unique(), | ||
22 | + | ||
23 | + 'status' => $this->smallInteger()->notNull()->defaultValue(10), | ||
24 | + 'created_at' => $this->integer()->notNull(), | ||
25 | + 'updated_at' => $this->integer()->notNull(), | ||
26 | + ], $tableOptions); | ||
27 | + } | ||
28 | + | ||
29 | + public function down() | ||
30 | + { | ||
31 | + $this->dropTable('{{%user}}'); | ||
32 | + } | ||
33 | +} |
1 | +++ a/environments/dev/backend/config/main-local.php | ||
1 | +<?php | ||
2 | + | ||
3 | +$config = [ | ||
4 | + 'components' => [ | ||
5 | + 'request' => [ | ||
6 | + // !!! insert a secret key in the following (if it is empty) - this is required by cookie validation | ||
7 | + 'cookieValidationKey' => '', | ||
8 | + ], | ||
9 | + ], | ||
10 | +]; | ||
11 | + | ||
12 | +if (!YII_ENV_TEST) { | ||
13 | + // configuration adjustments for 'dev' environment | ||
14 | + $config['bootstrap'][] = 'debug'; | ||
15 | + $config['modules']['debug'] = [ | ||
16 | + 'class' => 'yii\debug\Module', | ||
17 | + ]; | ||
18 | + | ||
19 | + $config['bootstrap'][] = 'gii'; | ||
20 | + $config['modules']['gii'] = [ | ||
21 | + 'class' => 'yii\gii\Module', | ||
22 | + ]; | ||
23 | +} | ||
24 | + | ||
25 | +return $config; |
1 | +++ a/environments/dev/backend/web/index-test.php | ||
1 | +<?php | ||
2 | + | ||
3 | +// NOTE: Make sure this file is not accessible when deployed to production | ||
4 | +if (!in_array(@$_SERVER['REMOTE_ADDR'], ['127.0.0.1', '::1'])) { | ||
5 | + die('You are not allowed to access this file.'); | ||
6 | +} | ||
7 | + | ||
8 | +defined('YII_DEBUG') or define('YII_DEBUG', true); | ||
9 | +defined('YII_ENV') or define('YII_ENV', 'test'); | ||
10 | + | ||
11 | +require(__DIR__ . '/../../vendor/autoload.php'); | ||
12 | +require(__DIR__ . '/../../vendor/yiisoft/yii2/Yii.php'); | ||
13 | +require(__DIR__ . '/../../common/config/bootstrap.php'); | ||
14 | +require(__DIR__ . '/../config/bootstrap.php'); | ||
15 | + | ||
16 | +$config = require(__DIR__ . '/../config/test-local.php'); | ||
17 | + | ||
18 | +(new yii\web\Application($config))->run(); |
1 | +++ a/environments/dev/backend/web/index.php | ||
1 | +<?php | ||
2 | +defined('YII_DEBUG') or define('YII_DEBUG', true); | ||
3 | +defined('YII_ENV') or define('YII_ENV', 'dev'); | ||
4 | + | ||
5 | +require(__DIR__ . '/../../vendor/autoload.php'); | ||
6 | +require(__DIR__ . '/../../vendor/yiisoft/yii2/Yii.php'); | ||
7 | +require(__DIR__ . '/../../common/config/bootstrap.php'); | ||
8 | +require(__DIR__ . '/../config/bootstrap.php'); | ||
9 | + | ||
10 | +$config = yii\helpers\ArrayHelper::merge( | ||
11 | + require(__DIR__ . '/../../common/config/main.php'), | ||
12 | + require(__DIR__ . '/../../common/config/main-local.php'), | ||
13 | + require(__DIR__ . '/../config/main.php'), | ||
14 | + require(__DIR__ . '/../config/main-local.php') | ||
15 | +); | ||
16 | + | ||
17 | +(new yii\web\Application($config))->run(); |
1 | +++ a/environments/dev/common/config/main-local.php | ||
1 | +<?php | ||
2 | +return [ | ||
3 | + 'components' => [ | ||
4 | + 'db' => [ | ||
5 | + 'class' => 'yii\db\Connection', | ||
6 | + 'dsn' => 'mysql:host=localhost;dbname=yii2advanced', | ||
7 | + 'username' => 'root', | ||
8 | + 'password' => '', | ||
9 | + 'charset' => 'utf8', | ||
10 | + ], | ||
11 | + 'mailer' => [ | ||
12 | + 'class' => 'yii\swiftmailer\Mailer', | ||
13 | + 'viewPath' => '@common/mail', | ||
14 | + // send all mails to a file by default. You have to set | ||
15 | + // 'useFileTransport' to false and configure a transport | ||
16 | + // for the mailer to send real emails. | ||
17 | + 'useFileTransport' => true, | ||
18 | + ], | ||
19 | + ], | ||
20 | +]; |
1 | +++ a/environments/dev/common/config/test-local.php | ||
1 | +<?php | ||
2 | +return yii\helpers\ArrayHelper::merge( | ||
3 | + require(__DIR__ . '/main.php'), | ||
4 | + require(__DIR__ . '/main-local.php'), | ||
5 | + require(__DIR__ . '/test.php'), | ||
6 | + [ | ||
7 | + 'components' => [ | ||
8 | + 'db' => [ | ||
9 | + 'dsn' => 'mysql:host=localhost;dbname=yii2advanced_test', | ||
10 | + ] | ||
11 | + ], | ||
12 | + ] | ||
13 | +); |
1 | +++ a/environments/dev/frontend/config/main-local.php | ||
1 | +<?php | ||
2 | + | ||
3 | +$config = [ | ||
4 | + 'components' => [ | ||
5 | + 'request' => [ | ||
6 | + // !!! insert a secret key in the following (if it is empty) - this is required by cookie validation | ||
7 | + 'cookieValidationKey' => '', | ||
8 | + ], | ||
9 | + ], | ||
10 | +]; | ||
11 | + | ||
12 | +if (!YII_ENV_TEST) { | ||
13 | + // configuration adjustments for 'dev' environment | ||
14 | + $config['bootstrap'][] = 'debug'; | ||
15 | + $config['modules']['debug'] = [ | ||
16 | + 'class' => 'yii\debug\Module', | ||
17 | + ]; | ||
18 | + | ||
19 | + $config['bootstrap'][] = 'gii'; | ||
20 | + $config['modules']['gii'] = [ | ||
21 | + 'class' => 'yii\gii\Module', | ||
22 | + ]; | ||
23 | +} | ||
24 | + | ||
25 | +return $config; |
1 | +++ a/environments/dev/frontend/config/test-local.php | ||
1 | +<?php | ||
2 | +return yii\helpers\ArrayHelper::merge( | ||
3 | + require(__DIR__ . '/../../common/config/test-local.php'), | ||
4 | + require(__DIR__ . '/main.php'), | ||
5 | + require(__DIR__ . '/main-local.php'), | ||
6 | + require(__DIR__ . '/test.php'), | ||
7 | + [ | ||
8 | + ] | ||
9 | +); |
1 | +++ a/environments/dev/frontend/web/index-test.php | ||
1 | +<?php | ||
2 | + | ||
3 | +// NOTE: Make sure this file is not accessible when deployed to production | ||
4 | +if (!in_array(@$_SERVER['REMOTE_ADDR'], ['127.0.0.1', '::1'])) { | ||
5 | + die('You are not allowed to access this file.'); | ||
6 | +} | ||
7 | + | ||
8 | +defined('YII_DEBUG') or define('YII_DEBUG', true); | ||
9 | +defined('YII_ENV') or define('YII_ENV', 'test'); | ||
10 | + | ||
11 | +require(__DIR__ . '/../../vendor/autoload.php'); | ||
12 | +require(__DIR__ . '/../../vendor/yiisoft/yii2/Yii.php'); | ||
13 | +require(__DIR__ . '/../../common/config/bootstrap.php'); | ||
14 | +require(__DIR__ . '/../config/bootstrap.php'); | ||
15 | + | ||
16 | +$config = require(__DIR__ . '/../config/test-local.php'); | ||
17 | + | ||
18 | +(new yii\web\Application($config))->run(); |
1 | +++ a/environments/dev/frontend/web/index.php | ||
1 | +<?php | ||
2 | +defined('YII_DEBUG') or define('YII_DEBUG', true); | ||
3 | +defined('YII_ENV') or define('YII_ENV', 'dev'); | ||
4 | + | ||
5 | +require(__DIR__ . '/../../vendor/autoload.php'); | ||
6 | +require(__DIR__ . '/../../vendor/yiisoft/yii2/Yii.php'); | ||
7 | +require(__DIR__ . '/../../common/config/bootstrap.php'); | ||
8 | +require(__DIR__ . '/../config/bootstrap.php'); | ||
9 | + | ||
10 | +$config = yii\helpers\ArrayHelper::merge( | ||
11 | + require(__DIR__ . '/../../common/config/main.php'), | ||
12 | + require(__DIR__ . '/../../common/config/main-local.php'), | ||
13 | + require(__DIR__ . '/../config/main.php'), | ||
14 | + require(__DIR__ . '/../config/main-local.php') | ||
15 | +); | ||
16 | + | ||
17 | +(new yii\web\Application($config))->run(); |
1 | +++ a/environments/dev/yii | ||
1 | +#!/usr/bin/env php | ||
2 | +<?php | ||
3 | +/** | ||
4 | + * Yii console bootstrap file. | ||
5 | + * | ||
6 | + * @link http://www.yiiframework.com/ | ||
7 | + * @copyright Copyright (c) 2008 Yii Software LLC | ||
8 | + * @license http://www.yiiframework.com/license/ | ||
9 | + */ | ||
10 | + | ||
11 | +defined('YII_DEBUG') or define('YII_DEBUG', true); | ||
12 | +defined('YII_ENV') or define('YII_ENV', 'dev'); | ||
13 | + | ||
14 | +require(__DIR__ . '/vendor/autoload.php'); | ||
15 | +require(__DIR__ . '/vendor/yiisoft/yii2/Yii.php'); | ||
16 | +require(__DIR__ . '/common/config/bootstrap.php'); | ||
17 | +require(__DIR__ . '/console/config/bootstrap.php'); | ||
18 | + | ||
19 | +$config = yii\helpers\ArrayHelper::merge( | ||
20 | + require(__DIR__ . '/common/config/main.php'), | ||
21 | + require(__DIR__ . '/common/config/main-local.php'), | ||
22 | + require(__DIR__ . '/console/config/main.php'), | ||
23 | + require(__DIR__ . '/console/config/main-local.php') | ||
24 | +); | ||
25 | + | ||
26 | +$application = new yii\console\Application($config); | ||
27 | +$exitCode = $application->run(); | ||
28 | +exit($exitCode); |
1 | +++ a/environments/dev/yii_test | ||
1 | +#!/usr/bin/env php | ||
2 | +<?php | ||
3 | +/** | ||
4 | + * Yii console bootstrap file. | ||
5 | + * | ||
6 | + * @link http://www.yiiframework.com/ | ||
7 | + * @copyright Copyright (c) 2008 Yii Software LLC | ||
8 | + * @license http://www.yiiframework.com/license/ | ||
9 | + */ | ||
10 | + | ||
11 | +defined('YII_DEBUG') or define('YII_DEBUG', true); | ||
12 | +defined('YII_ENV') or define('YII_ENV', 'test'); | ||
13 | + | ||
14 | +require(__DIR__ . '/vendor/autoload.php'); | ||
15 | +require(__DIR__ . '/vendor/yiisoft/yii2/Yii.php'); | ||
16 | +require(__DIR__ . '/common/config/bootstrap.php'); | ||
17 | +require(__DIR__ . '/console/config/bootstrap.php'); | ||
18 | + | ||
19 | +$config = yii\helpers\ArrayHelper::merge( | ||
20 | + require(__DIR__ . '/common/config/test-local.php'), | ||
21 | + require(__DIR__ . '/console/config/main.php'), | ||
22 | + require(__DIR__ . '/console/config/main-local.php') | ||
23 | +); | ||
24 | + | ||
25 | +$application = new yii\console\Application($config); | ||
26 | +$exitCode = $application->run(); | ||
27 | +exit($exitCode); |
1 | +++ a/environments/dev/yii_test.bat | ||
1 | +@echo off | ||
2 | + | ||
3 | +rem ------------------------------------------------------------- | ||
4 | +rem Yii command line bootstrap script for Windows. | ||
5 | +rem | ||
6 | +rem @author Qiang Xue <qiang.xue@gmail.com> | ||
7 | +rem @link http://www.yiiframework.com/ | ||
8 | +rem @copyright Copyright (c) 2008 Yii Software LLC | ||
9 | +rem @license http://www.yiiframework.com/license/ | ||
10 | +rem ------------------------------------------------------------- | ||
11 | + | ||
12 | +@setlocal | ||
13 | + | ||
14 | +set YII_PATH=%~dp0 | ||
15 | + | ||
16 | +if "%PHP_COMMAND%" == "" set PHP_COMMAND=php.exe | ||
17 | + | ||
18 | +"%PHP_COMMAND%" "%YII_PATH%yii_test" %* | ||
19 | + | ||
20 | +@endlocal |
1 | +++ a/environments/index.php | ||
1 | +<?php | ||
2 | +/** | ||
3 | + * The manifest of files that are local to specific environment. | ||
4 | + * This file returns a list of environments that the application | ||
5 | + * may be installed under. The returned data must be in the following | ||
6 | + * format: | ||
7 | + * | ||
8 | + * ```php | ||
9 | + * return [ | ||
10 | + * 'environment name' => [ | ||
11 | + * 'path' => 'directory storing the local files', | ||
12 | + * 'skipFiles' => [ | ||
13 | + * // list of files that should only copied once and skipped if they already exist | ||
14 | + * ], | ||
15 | + * 'setWritable' => [ | ||
16 | + * // list of directories that should be set writable | ||
17 | + * ], | ||
18 | + * 'setExecutable' => [ | ||
19 | + * // list of files that should be set executable | ||
20 | + * ], | ||
21 | + * 'setCookieValidationKey' => [ | ||
22 | + * // list of config files that need to be inserted with automatically generated cookie validation keys | ||
23 | + * ], | ||
24 | + * 'createSymlink' => [ | ||
25 | + * // list of symlinks to be created. Keys are symlinks, and values are the targets. | ||
26 | + * ], | ||
27 | + * ], | ||
28 | + * ]; | ||
29 | + * ``` | ||
30 | + */ | ||
31 | +return [ | ||
32 | + 'Development' => [ | ||
33 | + 'path' => 'dev', | ||
34 | + 'setWritable' => [ | ||
35 | + 'backend/runtime', | ||
36 | + 'backend/web/assets', | ||
37 | + 'frontend/runtime', | ||
38 | + 'frontend/web/assets', | ||
39 | + ], | ||
40 | + 'setExecutable' => [ | ||
41 | + 'yii', | ||
42 | + 'yii_test', | ||
43 | + ], | ||
44 | + 'setCookieValidationKey' => [ | ||
45 | + 'backend/config/main-local.php', | ||
46 | + 'frontend/config/main-local.php', | ||
47 | + ], | ||
48 | + ], | ||
49 | + 'Production' => [ | ||
50 | + 'path' => 'prod', | ||
51 | + 'setWritable' => [ | ||
52 | + 'backend/runtime', | ||
53 | + 'backend/web/assets', | ||
54 | + 'frontend/runtime', | ||
55 | + 'frontend/web/assets', | ||
56 | + ], | ||
57 | + 'setExecutable' => [ | ||
58 | + 'yii', | ||
59 | + ], | ||
60 | + 'setCookieValidationKey' => [ | ||
61 | + 'backend/config/main-local.php', | ||
62 | + 'frontend/config/main-local.php', | ||
63 | + ], | ||
64 | + ], | ||
65 | +]; |
1 | +++ a/environments/prod/backend/web/index.php | ||
1 | +<?php | ||
2 | +defined('YII_DEBUG') or define('YII_DEBUG', false); | ||
3 | +defined('YII_ENV') or define('YII_ENV', 'prod'); | ||
4 | + | ||
5 | +require(__DIR__ . '/../../vendor/autoload.php'); | ||
6 | +require(__DIR__ . '/../../vendor/yiisoft/yii2/Yii.php'); | ||
7 | +require(__DIR__ . '/../../common/config/bootstrap.php'); | ||
8 | +require(__DIR__ . '/../config/bootstrap.php'); | ||
9 | + | ||
10 | +$config = yii\helpers\ArrayHelper::merge( | ||
11 | + require(__DIR__ . '/../../common/config/main.php'), | ||
12 | + require(__DIR__ . '/../../common/config/main-local.php'), | ||
13 | + require(__DIR__ . '/../config/main.php'), | ||
14 | + require(__DIR__ . '/../config/main-local.php') | ||
15 | +); | ||
16 | + | ||
17 | +(new yii\web\Application($config))->run(); |
1 | +++ a/environments/prod/common/config/main-local.php | ||
1 | +<?php | ||
2 | +return [ | ||
3 | + 'components' => [ | ||
4 | + 'db' => [ | ||
5 | + 'class' => 'yii\db\Connection', | ||
6 | + 'dsn' => 'mysql:host=localhost;dbname=yii2advanced', | ||
7 | + 'username' => 'root', | ||
8 | + 'password' => '', | ||
9 | + 'charset' => 'utf8', | ||
10 | + ], | ||
11 | + 'mailer' => [ | ||
12 | + 'class' => 'yii\swiftmailer\Mailer', | ||
13 | + 'viewPath' => '@common/mail', | ||
14 | + ], | ||
15 | + ], | ||
16 | +]; |
1 | +++ a/environments/prod/frontend/web/index.php | ||
1 | +<?php | ||
2 | +defined('YII_DEBUG') or define('YII_DEBUG', false); | ||
3 | +defined('YII_ENV') or define('YII_ENV', 'prod'); | ||
4 | + | ||
5 | +require(__DIR__ . '/../../vendor/autoload.php'); | ||
6 | +require(__DIR__ . '/../../vendor/yiisoft/yii2/Yii.php'); | ||
7 | +require(__DIR__ . '/../../common/config/bootstrap.php'); | ||
8 | +require(__DIR__ . '/../config/bootstrap.php'); | ||
9 | + | ||
10 | +$config = yii\helpers\ArrayHelper::merge( | ||
11 | + require(__DIR__ . '/../../common/config/main.php'), | ||
12 | + require(__DIR__ . '/../../common/config/main-local.php'), | ||
13 | + require(__DIR__ . '/../config/main.php'), | ||
14 | + require(__DIR__ . '/../config/main-local.php') | ||
15 | +); | ||
16 | + | ||
17 | +(new yii\web\Application($config))->run(); |
1 | +++ a/environments/prod/yii | ||
1 | +#!/usr/bin/env php | ||
2 | +<?php | ||
3 | +/** | ||
4 | + * Yii console bootstrap file. | ||
5 | + * | ||
6 | + * @link http://www.yiiframework.com/ | ||
7 | + * @copyright Copyright (c) 2008 Yii Software LLC | ||
8 | + * @license http://www.yiiframework.com/license/ | ||
9 | + */ | ||
10 | + | ||
11 | +defined('YII_DEBUG') or define('YII_DEBUG', false); | ||
12 | +defined('YII_ENV') or define('YII_ENV', 'prod'); | ||
13 | + | ||
14 | +require(__DIR__ . '/vendor/autoload.php'); | ||
15 | +require(__DIR__ . '/vendor/yiisoft/yii2/Yii.php'); | ||
16 | +require(__DIR__ . '/common/config/bootstrap.php'); | ||
17 | +require(__DIR__ . '/console/config/bootstrap.php'); | ||
18 | + | ||
19 | +$config = yii\helpers\ArrayHelper::merge( | ||
20 | + require(__DIR__ . '/common/config/main.php'), | ||
21 | + require(__DIR__ . '/common/config/main-local.php'), | ||
22 | + require(__DIR__ . '/console/config/main.php'), | ||
23 | + require(__DIR__ . '/console/config/main-local.php') | ||
24 | +); | ||
25 | + | ||
26 | +$application = new yii\console\Application($config); | ||
27 | +$exitCode = $application->run(); | ||
28 | +exit($exitCode); |
1 | +++ a/frontend/assets/AppAsset.php | ||
1 | +<?php | ||
2 | + | ||
3 | +namespace frontend\assets; | ||
4 | + | ||
5 | +use yii\web\AssetBundle; | ||
6 | + | ||
7 | +/** | ||
8 | + * Main frontend application asset bundle. | ||
9 | + */ | ||
10 | +class AppAsset extends AssetBundle | ||
11 | +{ | ||
12 | + public $basePath = '@webroot'; | ||
13 | + public $baseUrl = '@web'; | ||
14 | + public $css = [ | ||
15 | + 'css/site.css', | ||
16 | + ]; | ||
17 | + public $js = [ | ||
18 | + ]; | ||
19 | + public $depends = [ | ||
20 | + 'yii\web\YiiAsset', | ||
21 | + 'yii\bootstrap\BootstrapAsset', | ||
22 | + ]; | ||
23 | +} |
1 | +++ a/frontend/codeception.yml | ||
1 | +namespace: frontend\tests | ||
2 | +actor: Tester | ||
3 | +paths: | ||
4 | + tests: tests | ||
5 | + log: tests/_output | ||
6 | + data: tests/_data | ||
7 | + helpers: tests/_support | ||
8 | +settings: | ||
9 | + bootstrap: _bootstrap.php | ||
10 | + colors: true | ||
11 | + memory_limit: 1024M | ||
12 | +modules: | ||
13 | + config: | ||
14 | + Yii2: | ||
15 | + configFile: 'config/test-local.php' |
1 | +++ a/frontend/config/main.php | ||
1 | +<?php | ||
2 | +$params = array_merge( | ||
3 | + require(__DIR__ . '/../../common/config/params.php'), | ||
4 | + require(__DIR__ . '/../../common/config/params-local.php'), | ||
5 | + require(__DIR__ . '/params.php'), | ||
6 | + require(__DIR__ . '/params-local.php') | ||
7 | +); | ||
8 | + | ||
9 | +return [ | ||
10 | + 'id' => 'app-frontend', | ||
11 | + 'basePath' => dirname(__DIR__), | ||
12 | + 'bootstrap' => ['log'], | ||
13 | + 'controllerNamespace' => 'frontend\controllers', | ||
14 | + 'components' => [ | ||
15 | + 'request' => [ | ||
16 | + 'csrfParam' => '_csrf-frontend', | ||
17 | + ], | ||
18 | + 'user' => [ | ||
19 | + 'identityClass' => 'common\models\User', | ||
20 | + 'enableAutoLogin' => true, | ||
21 | + 'identityCookie' => ['name' => '_identity-frontend', 'httpOnly' => true], | ||
22 | + ], | ||
23 | + 'session' => [ | ||
24 | + // this is the name of the session cookie used for login on the frontend | ||
25 | + 'name' => 'advanced-frontend', | ||
26 | + ], | ||
27 | + 'log' => [ | ||
28 | + 'traceLevel' => YII_DEBUG ? 3 : 0, | ||
29 | + 'targets' => [ | ||
30 | + [ | ||
31 | + 'class' => 'yii\log\FileTarget', | ||
32 | + 'levels' => ['error', 'warning'], | ||
33 | + ], | ||
34 | + ], | ||
35 | + ], | ||
36 | + 'errorHandler' => [ | ||
37 | + 'errorAction' => 'site/error', | ||
38 | + ], | ||
39 | + /* | ||
40 | + 'urlManager' => [ | ||
41 | + 'enablePrettyUrl' => true, | ||
42 | + 'showScriptName' => false, | ||
43 | + 'rules' => [ | ||
44 | + ], | ||
45 | + ], | ||
46 | + */ | ||
47 | + ], | ||
48 | + 'params' => $params, | ||
49 | +]; |