├── api
├── README.MD
├── runtime
│ └── .gitignore
├── web
│ ├── assets
│ │ └── .gitignore
│ ├── robots.txt
│ ├── favicon.ico
│ ├── .htaccess
│ ├── index-test.php
│ ├── index.php
│ └── css
│ │ └── site.css
├── config
│ ├── .gitignore
│ ├── params.php
│ └── main.php
└── modules
│ └── v1
│ ├── Module.php
│ ├── controllers
│ └── CountryController.php
│ └── models
│ └── Country.php
├── console
├── controllers
│ └── .gitkeep
├── models
│ └── .gitkeep
├── runtime
│ └── .gitignore
├── tests
│ ├── unit
│ │ ├── fixtures
│ │ │ └── data
│ │ │ │ └── .gitkeep
│ │ ├── _bootstrap.php
│ │ ├── TestCase.php
│ │ ├── DbTestCase.php
│ │ ├── _config.php
│ │ ├── yii.bat
│ │ ├── yii
│ │ └── _console.php
│ ├── _log
│ │ └── .gitignore
│ ├── _data
│ │ └── dump.sql
│ ├── .gitignore
│ ├── unit.suite.yml
│ ├── _config.php
│ ├── _console.php
│ └── _bootstrap.php
├── config
│ ├── .gitignore
│ ├── params.php
│ └── main.php
├── codeception.yml
└── migrations
│ ├── m150812_015333_create_country_table.php
│ ├── m150812_020403_populate_country.php
│ └── m130524_201442_init.php
├── backend
├── models
│ └── .gitkeep
├── runtime
│ └── .gitignore
├── tests
│ ├── unit
│ │ ├── fixtures
│ │ │ └── data
│ │ │ │ └── .gitkeep
│ │ ├── _bootstrap.php
│ │ ├── TestCase.php
│ │ ├── DbTestCase.php
│ │ ├── _config.php
│ │ ├── yii.bat
│ │ ├── yii
│ │ └── _console.php
│ ├── _log
│ │ └── .gitignore
│ ├── _data
│ │ └── dump.sql
│ ├── acceptance
│ │ ├── _bootstrap.php
│ │ ├── _console.php
│ │ ├── _config.php
│ │ ├── yii.bat
│ │ ├── yii
│ │ └── LoginCept.php
│ ├── functional
│ │ ├── _bootstrap.php
│ │ ├── _console.php
│ │ ├── yii.bat
│ │ ├── yii
│ │ ├── _config.php
│ │ └── LoginCept.php
│ ├── .gitignore
│ ├── unit.suite.yml
│ ├── _config.php
│ ├── functional.suite.yml
│ ├── _console.php
│ ├── _bootstrap.php
│ └── acceptance.suite.yml
├── web
│ ├── assets
│ │ └── .gitignore
│ ├── .gitignore
│ ├── robots.txt
│ ├── favicon.ico
│ └── css
│ │ └── site.css
├── config
│ ├── .gitignore
│ ├── params.php
│ └── main.php
├── codeception.yml
├── assets
│ └── AppAsset.php
├── views
│ ├── site
│ │ ├── error.php
│ │ ├── login.php
│ │ └── index.php
│ └── layouts
│ │ └── main.php
└── controllers
│ └── SiteController.php
├── frontend
├── runtime
│ └── .gitignore
├── web
│ ├── assets
│ │ └── .gitignore
│ ├── robots.txt
│ ├── .gitignore
│ ├── favicon.ico
│ └── css
│ │ └── site.css
├── tests
│ ├── _log
│ │ └── .gitignore
│ ├── _data
│ │ └── dump.sql
│ ├── unit
│ │ ├── _bootstrap.php
│ │ ├── TestCase.php
│ │ ├── DbTestCase.php
│ │ ├── _config.php
│ │ ├── yii.bat
│ │ ├── yii
│ │ ├── _console.php
│ │ ├── fixtures
│ │ │ └── data
│ │ │ │ └── models
│ │ │ │ └── user.php
│ │ └── models
│ │ │ ├── ResetPasswordFormTest.php
│ │ │ ├── SignupFormTest.php
│ │ │ ├── ContactFormTest.php
│ │ │ └── PasswordResetRequestFormTest.php
│ ├── acceptance
│ │ ├── _bootstrap.php
│ │ ├── AboutCept.php
│ │ ├── HomeCept.php
│ │ ├── _console.php
│ │ ├── _config.php
│ │ ├── yii.bat
│ │ ├── yii
│ │ ├── LoginCept.php
│ │ ├── ContactCept.php
│ │ └── SignupCest.php
│ ├── functional
│ │ ├── _bootstrap.php
│ │ ├── AboutCept.php
│ │ ├── HomeCept.php
│ │ ├── _console.php
│ │ ├── yii.bat
│ │ ├── yii
│ │ ├── _config.php
│ │ ├── LoginCept.php
│ │ ├── ContactCept.php
│ │ └── SignupCest.php
│ ├── .gitignore
│ ├── unit.suite.yml
│ ├── _pages
│ │ ├── AboutPage.php
│ │ ├── ContactPage.php
│ │ └── SignupPage.php
│ ├── _config.php
│ ├── functional.suite.yml
│ ├── _console.php
│ ├── _bootstrap.php
│ └── acceptance.suite.yml
├── config
│ ├── .gitignore
│ ├── params.php
│ └── main.php
├── views
│ ├── site
│ │ ├── about.php
│ │ ├── error.php
│ │ ├── resetPassword.php
│ │ ├── requestPasswordResetToken.php
│ │ ├── signup.php
│ │ ├── login.php
│ │ ├── contact.php
│ │ └── index.php
│ └── layouts
│ │ └── main.php
├── codeception.yml
├── assets
│ └── AppAsset.php
├── models
│ ├── ContactForm.php
│ ├── SignupForm.php
│ ├── PasswordResetRequestForm.php
│ └── ResetPasswordForm.php
├── widgets
│ └── Alert.php
└── controllers
│ └── SiteController.php
├── common
├── tests
│ ├── _log
│ │ └── .gitignore
│ ├── _data
│ │ └── dump.sql
│ ├── unit
│ │ ├── _bootstrap.php
│ │ ├── TestCase.php
│ │ ├── DbTestCase.php
│ │ ├── _config.php
│ │ ├── fixtures
│ │ │ └── data
│ │ │ │ └── models
│ │ │ │ └── user.php
│ │ ├── yii.bat
│ │ ├── yii
│ │ ├── _console.php
│ │ └── models
│ │ │ └── LoginFormTest.php
│ ├── .gitignore
│ ├── unit.suite.yml
│ ├── fixtures
│ │ ├── UserFixture.php
│ │ └── data
│ │ │ └── init_login.php
│ ├── _config.php
│ ├── _pages
│ │ └── LoginPage.php
│ ├── _console.php
│ ├── _bootstrap.php
│ ├── templates
│ │ └── fixtures
│ │ │ └── user.php
│ └── _helpers
│ │ └── FixtureHelper.php
├── config
│ ├── .gitignore
│ ├── params.php
│ ├── main.php
│ └── aliases.php
├── mail
│ ├── passwordResetToken.php
│ └── layouts
│ │ └── html.php
├── codeception.yml
└── models
│ ├── LoginForm.php
│ └── User.php
├── environments
├── dev
│ ├── api
│ │ ├── config
│ │ │ ├── params-local.php
│ │ │ └── main-local.php
│ │ └── web
│ │ │ ├── index-test.php
│ │ │ └── index.php
│ ├── backend
│ │ ├── config
│ │ │ ├── params-local.php
│ │ │ └── main-local.php
│ │ └── web
│ │ │ ├── index-test.php
│ │ │ └── index.php
│ ├── common
│ │ └── config
│ │ │ ├── params-local.php
│ │ │ └── main-local.php
│ ├── console
│ │ └── config
│ │ │ ├── main-local.php
│ │ │ └── params-local.php
│ ├── frontend
│ │ ├── config
│ │ │ ├── params-local.php
│ │ │ └── main-local.php
│ │ └── web
│ │ │ ├── index-test.php
│ │ │ └── index.php
│ └── yii
├── prod
│ ├── api
│ │ ├── config
│ │ │ ├── params-local.php
│ │ │ └── main-local.php
│ │ └── web
│ │ │ └── index.php
│ ├── common
│ │ └── config
│ │ │ ├── params-local.php
│ │ │ └── main-local.php
│ ├── console
│ │ └── config
│ │ │ ├── main-local.php
│ │ │ └── params-local.php
│ ├── frontend
│ │ ├── config
│ │ │ ├── main-local.php
│ │ │ └── params-local.php
│ │ └── web
│ │ │ └── index.php
│ ├── backend
│ │ ├── config
│ │ │ ├── params-local.php
│ │ │ └── main-local.php
│ │ └── web
│ │ │ └── index.php
│ └── yii
└── index.php
├── .gitignore
├── init.bat
├── yii.bat
├── README.md
├── composer.json
├── LICENSE.md
├── requirements.php
└── init
/api/README.MD:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/console/controllers/.gitkeep:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/backend/models/.gitkeep:
--------------------------------------------------------------------------------
1 | *
2 |
--------------------------------------------------------------------------------
/console/models/.gitkeep:
--------------------------------------------------------------------------------
1 | *
2 |
--------------------------------------------------------------------------------
/api/runtime/.gitignore:
--------------------------------------------------------------------------------
1 | *
2 | !.gitignore
--------------------------------------------------------------------------------
/api/web/assets/.gitignore:
--------------------------------------------------------------------------------
1 | *
2 | !.gitignore
--------------------------------------------------------------------------------
/backend/runtime/.gitignore:
--------------------------------------------------------------------------------
1 | *
2 | !.gitignore
--------------------------------------------------------------------------------
/backend/tests/unit/fixtures/data/.gitkeep:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/console/runtime/.gitignore:
--------------------------------------------------------------------------------
1 | *
2 | !.gitignore
--------------------------------------------------------------------------------
/console/tests/unit/fixtures/data/.gitkeep:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/backend/web/assets/.gitignore:
--------------------------------------------------------------------------------
1 | *
2 | !.gitignore
--------------------------------------------------------------------------------
/frontend/runtime/.gitignore:
--------------------------------------------------------------------------------
1 | *
2 | !.gitignore
--------------------------------------------------------------------------------
/frontend/web/assets/.gitignore:
--------------------------------------------------------------------------------
1 | *
2 | !.gitignore
--------------------------------------------------------------------------------
/api/web/robots.txt:
--------------------------------------------------------------------------------
1 | User-Agent: *
2 | Disallow: /
3 |
--------------------------------------------------------------------------------
/backend/tests/_log/.gitignore:
--------------------------------------------------------------------------------
1 | *
2 | !.gitignore
3 |
--------------------------------------------------------------------------------
/common/tests/_log/.gitignore:
--------------------------------------------------------------------------------
1 | *
2 | !.gitignore
3 |
--------------------------------------------------------------------------------
/console/tests/_log/.gitignore:
--------------------------------------------------------------------------------
1 | *
2 | !.gitignore
3 |
--------------------------------------------------------------------------------
/frontend/tests/_log/.gitignore:
--------------------------------------------------------------------------------
1 | *
2 | !.gitignore
3 |
--------------------------------------------------------------------------------
/frontend/web/robots.txt:
--------------------------------------------------------------------------------
1 | User-agent: *
2 | Disallow:
--------------------------------------------------------------------------------
/api/config/.gitignore:
--------------------------------------------------------------------------------
1 | main-local.php
2 | params-local.php
--------------------------------------------------------------------------------
/backend/web/.gitignore:
--------------------------------------------------------------------------------
1 | /index.php
2 | /index-test.php
3 |
--------------------------------------------------------------------------------
/backend/web/robots.txt:
--------------------------------------------------------------------------------
1 | User-Agent: *
2 | Disallow: /
3 |
--------------------------------------------------------------------------------
/frontend/web/.gitignore:
--------------------------------------------------------------------------------
1 | /index.php
2 | /index-test.php
3 |
--------------------------------------------------------------------------------
/backend/config/.gitignore:
--------------------------------------------------------------------------------
1 | main-local.php
2 | params-local.php
--------------------------------------------------------------------------------
/common/config/.gitignore:
--------------------------------------------------------------------------------
1 | main-local.php
2 | params-local.php
--------------------------------------------------------------------------------
/console/config/.gitignore:
--------------------------------------------------------------------------------
1 | main-local.php
2 | params-local.php
--------------------------------------------------------------------------------
/frontend/config/.gitignore:
--------------------------------------------------------------------------------
1 | main-local.php
2 | params-local.php
--------------------------------------------------------------------------------
/environments/dev/api/config/params-local.php:
--------------------------------------------------------------------------------
1 | 'admin@example.com',
4 | ];
5 |
--------------------------------------------------------------------------------
/api/web/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/deerawan/yii2-advanced-api/HEAD/api/web/favicon.ico
--------------------------------------------------------------------------------
/backend/config/params.php:
--------------------------------------------------------------------------------
1 | 'admin@example.com',
4 | ];
5 |
--------------------------------------------------------------------------------
/console/config/params.php:
--------------------------------------------------------------------------------
1 | 'admin@example.com',
4 | ];
5 |
--------------------------------------------------------------------------------
/frontend/config/params.php:
--------------------------------------------------------------------------------
1 | 'admin@example.com',
4 | ];
5 |
--------------------------------------------------------------------------------
/backend/web/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/deerawan/yii2-advanced-api/HEAD/backend/web/favicon.ico
--------------------------------------------------------------------------------
/common/tests/unit/_bootstrap.php:
--------------------------------------------------------------------------------
1 | 'admin@example.com',
4 | 'supportEmail' => 'support@example.com',
5 | 'user.passwordResetTokenExpire' => 3600,
6 | ];
7 |
--------------------------------------------------------------------------------
/backend/tests/unit.suite.yml:
--------------------------------------------------------------------------------
1 | # Codeception Test Suite Configuration
2 |
3 | # suite for unit (internal) tests.
4 | # RUN `build` COMMAND AFTER ADDING/REMOVING MODULES.
5 |
6 | class_name: CodeGuy
7 |
--------------------------------------------------------------------------------
/common/tests/unit.suite.yml:
--------------------------------------------------------------------------------
1 | # Codeception Test Suite Configuration
2 |
3 | # suite for unit (internal) tests.
4 | # RUN `build` COMMAND AFTER ADDING/REMOVING MODULES.
5 |
6 | class_name: CodeGuy
7 |
--------------------------------------------------------------------------------
/console/tests/unit.suite.yml:
--------------------------------------------------------------------------------
1 | # Codeception Test Suite Configuration
2 |
3 | # suite for unit (internal) tests.
4 | # RUN `build` COMMAND AFTER ADDING/REMOVING MODULES.
5 |
6 | class_name: CodeGuy
7 |
--------------------------------------------------------------------------------
/frontend/tests/unit.suite.yml:
--------------------------------------------------------------------------------
1 | # Codeception Test Suite Configuration
2 |
3 | # suite for unit (internal) tests.
4 | # RUN `build` COMMAND AFTER ADDING/REMOVING MODULES.
5 |
6 | class_name: CodeGuy
7 |
--------------------------------------------------------------------------------
/backend/tests/unit/TestCase.php:
--------------------------------------------------------------------------------
1 | wantTo('ensure that about works');
7 | AboutPage::openBy($I);
8 | $I->see('About', 'h1');
9 |
--------------------------------------------------------------------------------
/frontend/tests/functional/AboutCept.php:
--------------------------------------------------------------------------------
1 | wantTo('ensure that about works');
7 | AboutPage::openBy($I);
8 | $I->see('About', 'h1');
9 |
--------------------------------------------------------------------------------
/common/tests/fixtures/UserFixture.php:
--------------------------------------------------------------------------------
1 | dirname(dirname(__DIR__)) . '/vendor',
4 | 'components' => [
5 | 'cache' => [
6 | 'class' => 'yii\caching\FileCache',
7 | ]
8 | ],
9 | ];
10 |
--------------------------------------------------------------------------------
/api/modules/v1/Module.php:
--------------------------------------------------------------------------------
1 | wantTo('ensure that home page works');
5 | $I->amOnPage(Yii::$app->homeUrl);
6 | $I->see('My Company');
7 | $I->seeLink('About');
8 | $I->click('About');
9 | $I->see('This is the About page.');
10 |
--------------------------------------------------------------------------------
/frontend/tests/functional/HomeCept.php:
--------------------------------------------------------------------------------
1 | wantTo('ensure that home page works');
5 | $I->amOnPage(Yii::$app->homeUrl);
6 | $I->see('My Company');
7 | $I->seeLink('About');
8 | $I->click('About');
9 | $I->see('This is the About page.');
10 |
--------------------------------------------------------------------------------
/common/tests/_config.php:
--------------------------------------------------------------------------------
1 | [
7 | 'mailer' => [
8 | 'useFileTransport' => true,
9 | ],
10 | 'urlManager' => [
11 | 'showScriptName' => true,
12 | ],
13 | ],
14 | ];
15 |
--------------------------------------------------------------------------------
/backend/tests/_config.php:
--------------------------------------------------------------------------------
1 | [
7 | 'mailer' => [
8 | 'useFileTransport' => true,
9 | ],
10 | 'urlManager' => [
11 | 'showScriptName' => true,
12 | ],
13 | ],
14 | ];
15 |
--------------------------------------------------------------------------------
/common/config/aliases.php:
--------------------------------------------------------------------------------
1 | [
7 | 'mailer' => [
8 | 'useFileTransport' => true,
9 | ],
10 | 'urlManager' => [
11 | 'showScriptName' => true,
12 | ],
13 | ],
14 | ];
15 |
--------------------------------------------------------------------------------
/frontend/tests/_config.php:
--------------------------------------------------------------------------------
1 | [
7 | 'mailer' => [
8 | 'useFileTransport' => true,
9 | ],
10 | 'urlManager' => [
11 | 'showScriptName' => true,
12 | ],
13 | ],
14 | ];
15 |
--------------------------------------------------------------------------------
/api/modules/v1/controllers/CountryController.php:
--------------------------------------------------------------------------------
1 |
11 | */
12 | class CountryController extends ActiveController
13 | {
14 | public $modelClass = 'api\modules\v1\models\Country';
15 | }
16 |
17 |
18 |
--------------------------------------------------------------------------------
/environments/dev/api/config/main-local.php:
--------------------------------------------------------------------------------
1 | title = 'About';
6 | $this->params['breadcrumbs'][] = $this->title;
7 | ?>
8 |
9 |
= Html::encode($this->title) ?>
10 |
11 |
This is the About page. You may modify the following file to customize its content:
12 |
13 |
= __FILE__ ?>
14 |
15 |
--------------------------------------------------------------------------------
/common/mail/passwordResetToken.php:
--------------------------------------------------------------------------------
1 | urlManager->createAbsoluteUrl(['site/reset-password', 'token' => $user->password_reset_token]);
8 | ?>
9 |
10 | Hello = Html::encode($user->username) ?>,
11 |
12 | Follow the link below to reset your password:
13 |
14 | = Html::a(Html::encode($resetLink), $resetLink) ?>
15 |
--------------------------------------------------------------------------------
/backend/codeception.yml:
--------------------------------------------------------------------------------
1 | actor: Tester
2 | paths:
3 | tests: tests
4 | log: tests/_log
5 | data: tests/_data
6 | helpers: tests/_helpers
7 | settings:
8 | bootstrap: _bootstrap.php
9 | suite_class: \PHPUnit_Framework_TestSuite
10 | colors: true
11 | memory_limit: 1024M
12 | log: true
13 | modules:
14 | config:
15 | Db:
16 | dsn: ''
17 | user: ''
18 | password: ''
19 | dump: tests/_data/dump.sql
20 |
--------------------------------------------------------------------------------
/common/codeception.yml:
--------------------------------------------------------------------------------
1 | actor: Tester
2 | paths:
3 | tests: tests
4 | log: tests/_log
5 | data: tests/_data
6 | helpers: tests/_helpers
7 | settings:
8 | bootstrap: _bootstrap.php
9 | suite_class: \PHPUnit_Framework_TestSuite
10 | colors: true
11 | memory_limit: 1024M
12 | log: true
13 | modules:
14 | config:
15 | Db:
16 | dsn: ''
17 | user: ''
18 | password: ''
19 | dump: tests/_data/dump.sql
20 |
--------------------------------------------------------------------------------
/console/codeception.yml:
--------------------------------------------------------------------------------
1 | actor: Tester
2 | paths:
3 | tests: tests
4 | log: tests/_log
5 | data: tests/_data
6 | helpers: tests/_helpers
7 | settings:
8 | bootstrap: _bootstrap.php
9 | suite_class: \PHPUnit_Framework_TestSuite
10 | colors: true
11 | memory_limit: 1024M
12 | log: true
13 | modules:
14 | config:
15 | Db:
16 | dsn: ''
17 | user: ''
18 | password: ''
19 | dump: tests/_data/dump.sql
20 |
--------------------------------------------------------------------------------
/frontend/codeception.yml:
--------------------------------------------------------------------------------
1 | actor: Tester
2 | paths:
3 | tests: tests
4 | log: tests/_log
5 | data: tests/_data
6 | helpers: tests/_helpers
7 | settings:
8 | bootstrap: _bootstrap.php
9 | suite_class: \PHPUnit_Framework_TestSuite
10 | colors: true
11 | memory_limit: 1024M
12 | log: true
13 | modules:
14 | config:
15 | Db:
16 | dsn: ''
17 | user: ''
18 | password: ''
19 | dump: tests/_data/dump.sql
20 |
--------------------------------------------------------------------------------
/environments/prod/api/config/main-local.php:
--------------------------------------------------------------------------------
1 | [
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 | ];
--------------------------------------------------------------------------------
/environments/prod/backend/config/main-local.php:
--------------------------------------------------------------------------------
1 | [
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 | ];
--------------------------------------------------------------------------------
/environments/prod/common/config/main-local.php:
--------------------------------------------------------------------------------
1 | [
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 | ];
17 |
--------------------------------------------------------------------------------
/common/tests/unit/_config.php:
--------------------------------------------------------------------------------
1 | [
9 | 'db' => [
10 | 'dsn' => 'mysql:host=localhost;dbname=yii2_advanced_unit',
11 | ],
12 | ],
13 | 'id' => 'app-common',
14 | 'basePath' => dirname(__DIR__),
15 | ]
16 | );
17 |
--------------------------------------------------------------------------------
/common/tests/fixtures/data/init_login.php:
--------------------------------------------------------------------------------
1 | 'erau',
6 | 'auth_key' => 'tUu1qHcde0diwUol3xeI-18MuHkkprQI',
7 | // password_0
8 | 'password_hash' => '$2y$13$nJ1WDlBaGcbCdbNC5.5l4.sgy.OMEKCqtDQOdQ2OWpgiKRWYyzzne',
9 | 'password_reset_token' => 'RkD_Jw0_8HEedzLk7MM-ZKEFfYR7VbMr_1392559490',
10 | 'created_at' => '1392559490',
11 | 'updated_at' => '1392559490',
12 | 'email' => 'sfriesen@jenkins.info',
13 | ],
14 | ];
15 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # yii console command
2 | /yii
3 |
4 | # phpstorm project files
5 | .idea
6 |
7 | # netbeans project files
8 | nbproject
9 |
10 | # zend studio for eclipse project files
11 | .buildpath
12 | .project
13 | .settings
14 |
15 | # windows thumbnail cache
16 | Thumbs.db
17 |
18 | # composer vendor dir
19 | /vendor
20 |
21 | # composer itself is not needed
22 | composer.phar
23 |
24 | # Mac DS_Store Files
25 | .DS_Store
26 |
27 | # phpunit itself is not needed
28 | phpunit.phar
29 | # local phpunit config
30 | /phpunit.xml
31 |
--------------------------------------------------------------------------------
/common/tests/unit/fixtures/data/models/user.php:
--------------------------------------------------------------------------------
1 | '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 | ];
15 |
--------------------------------------------------------------------------------
/backend/tests/functional.suite.yml:
--------------------------------------------------------------------------------
1 | # Codeception Test Suite Configuration
2 |
3 | # suite for functional (integration) tests.
4 | # emulate web requests and make application process them.
5 | # (tip: better to use with frameworks).
6 |
7 | # RUN `build` COMMAND AFTER ADDING/REMOVING MODULES.
8 | #basic/web/index.php
9 | class_name: TestGuy
10 | modules:
11 | enabled:
12 | - Filesystem
13 | - Yii2
14 | - common\tests\_helpers\FixtureHelper
15 | config:
16 | Yii2:
17 | configFile: 'tests/functional/_config.php'
18 |
--------------------------------------------------------------------------------
/frontend/tests/functional.suite.yml:
--------------------------------------------------------------------------------
1 | # Codeception Test Suite Configuration
2 |
3 | # suite for functional (integration) tests.
4 | # emulate web requests and make application process them.
5 | # (tip: better to use with frameworks).
6 |
7 | # RUN `build` COMMAND AFTER ADDING/REMOVING MODULES.
8 | #basic/web/index.php
9 | class_name: TestGuy
10 | modules:
11 | enabled:
12 | - Filesystem
13 | - Yii2
14 | - common\tests\_helpers\FixtureHelper
15 | config:
16 | Yii2:
17 | configFile: 'tests/functional/_config.php'
18 |
--------------------------------------------------------------------------------
/backend/tests/acceptance/_console.php:
--------------------------------------------------------------------------------
1 | [
10 | 'db' => [
11 | 'dsn' => 'mysql:host=localhost;dbname=yii2_advanced_acceptance',
12 | ],
13 | ],
14 | ]
15 | );
16 |
--------------------------------------------------------------------------------
/backend/tests/functional/_console.php:
--------------------------------------------------------------------------------
1 | [
10 | 'db' => [
11 | 'dsn' => 'mysql:host=localhost;dbname=yii2_advanced_functional',
12 | ],
13 | ],
14 | ]
15 | );
16 |
--------------------------------------------------------------------------------
/frontend/tests/acceptance/_console.php:
--------------------------------------------------------------------------------
1 | [
10 | 'db' => [
11 | 'dsn' => 'mysql:host=localhost;dbname=yii2_advanced_acceptance',
12 | ],
13 | ],
14 | ]
15 | );
16 |
--------------------------------------------------------------------------------
/frontend/tests/functional/_console.php:
--------------------------------------------------------------------------------
1 | [
10 | 'db' => [
11 | 'dsn' => 'mysql:host=localhost;dbname=yii2_advanced_functional',
12 | ],
13 | ],
14 | ]
15 | );
16 |
--------------------------------------------------------------------------------
/backend/tests/unit/_config.php:
--------------------------------------------------------------------------------
1 | [
11 | 'db' => [
12 | 'dsn' => 'mysql:host=localhost;dbname=yii2_advanced_unit',
13 | ],
14 | ],
15 | ]
16 | );
17 |
--------------------------------------------------------------------------------
/console/tests/unit/_config.php:
--------------------------------------------------------------------------------
1 | [
11 | 'db' => [
12 | 'dsn' => 'mysql:host=localhost;dbname=yii2_advanced_unit',
13 | ],
14 | ],
15 | ]
16 | );
17 |
--------------------------------------------------------------------------------
/frontend/tests/unit/_config.php:
--------------------------------------------------------------------------------
1 | [
11 | 'db' => [
12 | 'dsn' => 'mysql:host=localhost;dbname=yii2_advanced_unit',
13 | ],
14 | ],
15 | ]
16 | );
17 |
--------------------------------------------------------------------------------
/backend/tests/acceptance/_config.php:
--------------------------------------------------------------------------------
1 | [
11 | 'db' => [
12 | 'dsn' => 'mysql:host=localhost;dbname=yii2_advanced_acceptance',
13 | ],
14 | ],
15 | ]
16 | );
17 |
--------------------------------------------------------------------------------
/frontend/tests/acceptance/_config.php:
--------------------------------------------------------------------------------
1 | [
11 | 'db' => [
12 | 'dsn' => 'mysql:host=localhost;dbname=yii2_advanced_acceptance',
13 | ],
14 | ],
15 | ]
16 | );
17 |
--------------------------------------------------------------------------------
/common/tests/_pages/LoginPage.php:
--------------------------------------------------------------------------------
1 | guy->fillField('input[name="LoginForm[username]"]', $username);
18 | $this->guy->fillField('input[name="LoginForm[password]"]', $password);
19 | $this->guy->click('login-button');
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/init.bat:
--------------------------------------------------------------------------------
1 | @echo off
2 |
3 | rem -------------------------------------------------------------
4 | rem Yii command line init script for Windows.
5 | rem
6 | rem @author Qiang Xue
7 | rem @link http://www.yiiframework.com/
8 | rem @copyright Copyright © 2012 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%init" %*
19 |
20 | @endlocal
21 |
--------------------------------------------------------------------------------
/yii.bat:
--------------------------------------------------------------------------------
1 | @echo off
2 |
3 | rem -------------------------------------------------------------
4 | rem Yii command line bootstrap script for Windows.
5 | rem
6 | rem @author Qiang Xue
7 | rem @link http://www.yiiframework.com/
8 | rem @copyright Copyright © 2012 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" %*
19 |
20 | @endlocal
21 |
--------------------------------------------------------------------------------
/backend/tests/unit/yii.bat:
--------------------------------------------------------------------------------
1 | @echo off
2 |
3 | rem -------------------------------------------------------------
4 | rem Yii command line bootstrap script for Windows.
5 | rem
6 | rem @author Qiang Xue
7 | rem @link http://www.yiiframework.com/
8 | rem @copyright Copyright © 2012 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" %*
19 |
20 | @endlocal
21 |
--------------------------------------------------------------------------------
/common/tests/unit/yii.bat:
--------------------------------------------------------------------------------
1 | @echo off
2 |
3 | rem -------------------------------------------------------------
4 | rem Yii command line bootstrap script for Windows.
5 | rem
6 | rem @author Qiang Xue
7 | rem @link http://www.yiiframework.com/
8 | rem @copyright Copyright © 2012 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" %*
19 |
20 | @endlocal
21 |
--------------------------------------------------------------------------------
/console/tests/unit/yii.bat:
--------------------------------------------------------------------------------
1 | @echo off
2 |
3 | rem -------------------------------------------------------------
4 | rem Yii command line bootstrap script for Windows.
5 | rem
6 | rem @author Qiang Xue
7 | rem @link http://www.yiiframework.com/
8 | rem @copyright Copyright © 2012 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" %*
19 |
20 | @endlocal
21 |
--------------------------------------------------------------------------------
/frontend/tests/unit/yii.bat:
--------------------------------------------------------------------------------
1 | @echo off
2 |
3 | rem -------------------------------------------------------------
4 | rem Yii command line bootstrap script for Windows.
5 | rem
6 | rem @author Qiang Xue
7 | rem @link http://www.yiiframework.com/
8 | rem @copyright Copyright © 2012 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" %*
19 |
20 | @endlocal
21 |
--------------------------------------------------------------------------------
/backend/tests/acceptance/yii.bat:
--------------------------------------------------------------------------------
1 | @echo off
2 |
3 | rem -------------------------------------------------------------
4 | rem Yii command line bootstrap script for Windows.
5 | rem
6 | rem @author Qiang Xue
7 | rem @link http://www.yiiframework.com/
8 | rem @copyright Copyright © 2012 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" %*
19 |
20 | @endlocal
21 |
--------------------------------------------------------------------------------
/backend/tests/functional/yii.bat:
--------------------------------------------------------------------------------
1 | @echo off
2 |
3 | rem -------------------------------------------------------------
4 | rem Yii command line bootstrap script for Windows.
5 | rem
6 | rem @author Qiang Xue
7 | rem @link http://www.yiiframework.com/
8 | rem @copyright Copyright © 2012 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" %*
19 |
20 | @endlocal
21 |
--------------------------------------------------------------------------------
/frontend/tests/acceptance/yii.bat:
--------------------------------------------------------------------------------
1 | @echo off
2 |
3 | rem -------------------------------------------------------------
4 | rem Yii command line bootstrap script for Windows.
5 | rem
6 | rem @author Qiang Xue
7 | rem @link http://www.yiiframework.com/
8 | rem @copyright Copyright © 2012 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" %*
19 |
20 | @endlocal
21 |
--------------------------------------------------------------------------------
/frontend/tests/functional/yii.bat:
--------------------------------------------------------------------------------
1 | @echo off
2 |
3 | rem -------------------------------------------------------------
4 | rem Yii command line bootstrap script for Windows.
5 | rem
6 | rem @author Qiang Xue
7 | rem @link http://www.yiiframework.com/
8 | rem @copyright Copyright © 2012 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" %*
19 |
20 | @endlocal
21 |
--------------------------------------------------------------------------------
/frontend/tests/_pages/ContactPage.php:
--------------------------------------------------------------------------------
1 | $value) {
17 | $inputType = $field === 'body' ? 'textarea' : 'input';
18 | $this->guy->fillField($inputType . '[name="ContactForm[' . $field . ']"]', $value);
19 | }
20 | $this->guy->click('contact-button');
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/frontend/tests/_pages/SignupPage.php:
--------------------------------------------------------------------------------
1 | $value) {
18 | $inputType = $field === 'body' ? 'textarea' : 'input';
19 | $this->guy->fillField($inputType . '[name="SignupForm[' . $field . ']"]', $value);
20 | }
21 | $this->guy->click('signup-button');
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/api/web/index-test.php:
--------------------------------------------------------------------------------
1 | run();
18 |
--------------------------------------------------------------------------------
/backend/assets/AppAsset.php:
--------------------------------------------------------------------------------
1 |
14 | * @since 2.0
15 | */
16 | class AppAsset extends AssetBundle
17 | {
18 | public $basePath = '@webroot';
19 | public $baseUrl = '@web';
20 | public $css = ['css/site.css'];
21 | public $js = [];
22 | public $depends = [
23 | 'yii\web\YiiAsset',
24 | 'yii\bootstrap\BootstrapAsset',
25 | ];
26 | }
27 |
--------------------------------------------------------------------------------
/api/web/index.php:
--------------------------------------------------------------------------------
1 | run();
18 |
--------------------------------------------------------------------------------
/backend/views/site/error.php:
--------------------------------------------------------------------------------
1 | title = $name;
11 | ?>
12 |
13 |
14 |
= Html::encode($this->title) ?>
15 |
16 |
17 | = nl2br(Html::encode($message)) ?>
18 |
19 |
20 |
21 | The above error occurred while the Web server was processing your request.
22 |
23 |
24 | Please contact us if you think this is a server error. Thank you.
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/environments/dev/api/web/index-test.php:
--------------------------------------------------------------------------------
1 | run();
18 |
--------------------------------------------------------------------------------
/frontend/views/site/error.php:
--------------------------------------------------------------------------------
1 | title = $name;
11 | ?>
12 |
13 |
14 |
= Html::encode($this->title) ?>
15 |
16 |
17 | = nl2br(Html::encode($message)) ?>
18 |
19 |
20 |
21 | The above error occurred while the Web server was processing your request.
22 |
23 |
24 | Please contact us if you think this is a server error. Thank you.
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/environments/dev/backend/web/index-test.php:
--------------------------------------------------------------------------------
1 | run();
18 |
--------------------------------------------------------------------------------
/environments/dev/frontend/web/index-test.php:
--------------------------------------------------------------------------------
1 | run();
18 |
--------------------------------------------------------------------------------
/backend/tests/unit/yii:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env php
2 | run();
21 | exit($exitCode);
22 |
--------------------------------------------------------------------------------
/common/tests/unit/yii:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env php
2 | run();
21 | exit($exitCode);
22 |
--------------------------------------------------------------------------------
/console/tests/unit/yii:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env php
2 | run();
21 | exit($exitCode);
22 |
--------------------------------------------------------------------------------
/frontend/tests/unit/yii:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env php
2 | run();
21 | exit($exitCode);
22 |
--------------------------------------------------------------------------------
/backend/tests/acceptance/yii:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env php
2 | run();
21 | exit($exitCode);
22 |
--------------------------------------------------------------------------------
/backend/tests/functional/yii:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env php
2 | run();
21 | exit($exitCode);
22 |
--------------------------------------------------------------------------------
/environments/dev/api/web/index.php:
--------------------------------------------------------------------------------
1 | run();
18 |
--------------------------------------------------------------------------------
/environments/dev/backend/web/index.php:
--------------------------------------------------------------------------------
1 | run();
18 |
--------------------------------------------------------------------------------
/environments/prod/api/web/index.php:
--------------------------------------------------------------------------------
1 | run();
18 |
--------------------------------------------------------------------------------
/console/migrations/m150812_015333_create_country_table.php:
--------------------------------------------------------------------------------
1 | createTable('country', [
11 | 'code' => Schema::TYPE_STRING . ' NOT NULL',
12 | 'country' => Schema::TYPE_STRING . ' NOT NULL',
13 | 'population' => Schema::TYPE_INTEGER . ' NOT NULL',
14 | ]);
15 |
16 | $this->addPrimaryKey('pk_code', 'country', 'code');
17 | }
18 |
19 | public function down()
20 | {
21 | $this->dropTable('country');
22 |
23 | return false;
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/environments/dev/frontend/web/index.php:
--------------------------------------------------------------------------------
1 | run();
18 |
--------------------------------------------------------------------------------
/environments/prod/backend/web/index.php:
--------------------------------------------------------------------------------
1 | run();
18 |
--------------------------------------------------------------------------------
/environments/prod/frontend/web/index.php:
--------------------------------------------------------------------------------
1 | run();
18 |
--------------------------------------------------------------------------------
/frontend/assets/AppAsset.php:
--------------------------------------------------------------------------------
1 |
14 | * @since 2.0
15 | */
16 | class AppAsset extends AssetBundle
17 | {
18 | public $basePath = '@webroot';
19 | public $baseUrl = '@web';
20 | public $css = [
21 | 'css/site.css',
22 | ];
23 | public $js = [
24 | ];
25 | public $depends = [
26 | 'yii\web\YiiAsset',
27 | 'yii\bootstrap\BootstrapAsset',
28 | ];
29 | }
30 |
--------------------------------------------------------------------------------
/frontend/tests/acceptance/yii:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env php
2 | run();
21 | exit($exitCode);
22 |
--------------------------------------------------------------------------------
/frontend/tests/functional/yii:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env php
2 | run();
21 | exit($exitCode);
22 |
--------------------------------------------------------------------------------
/backend/tests/functional/_config.php:
--------------------------------------------------------------------------------
1 | [
15 | 'db' => [
16 | 'dsn' => 'mysql:host=localhost;dbname=yii2_advanced_functional',
17 | ],
18 | ],
19 | ]
20 | );
21 |
--------------------------------------------------------------------------------
/frontend/tests/functional/_config.php:
--------------------------------------------------------------------------------
1 | [
15 | 'db' => [
16 | 'dsn' => 'mysql:host=localhost;dbname=yii2_advanced_functional',
17 | ],
18 | ],
19 | ]
20 | );
21 |
--------------------------------------------------------------------------------
/api/modules/v1/models/Country.php:
--------------------------------------------------------------------------------
1 |
8 | */
9 | class Country extends ActiveRecord
10 | {
11 | /**
12 | * @inheritdoc
13 | */
14 | public static function tableName()
15 | {
16 | return 'country';
17 | }
18 |
19 | /**
20 | * @inheritdoc
21 | */
22 | public static function primaryKey()
23 | {
24 | return ['code'];
25 | }
26 |
27 | /**
28 | * Define rules for validation
29 | */
30 | public function rules()
31 | {
32 | return [
33 | [['code', 'name', 'population'], 'required']
34 | ];
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/common/tests/_console.php:
--------------------------------------------------------------------------------
1 | [
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 | ];
21 |
--------------------------------------------------------------------------------
/console/config/main.php:
--------------------------------------------------------------------------------
1 | 'app-console',
11 | 'basePath' => dirname(__DIR__),
12 | 'bootstrap' => ['log'],
13 | 'controllerNamespace' => 'console\controllers',
14 | 'modules' => [],
15 | 'components' => [
16 | 'log' => [
17 | 'targets' => [
18 | [
19 | 'class' => 'yii\log\FileTarget',
20 | 'levels' => ['error', 'warning'],
21 | ],
22 | ],
23 | ],
24 | ],
25 | 'params' => $params,
26 | ];
27 |
--------------------------------------------------------------------------------
/common/mail/layouts/html.php:
--------------------------------------------------------------------------------
1 |
8 | beginPage() ?>
9 |
10 |
11 |
12 |
13 | = Html::encode($this->title) ?>
14 | head() ?>
15 |
16 |
17 | beginBody() ?>
18 | = $content ?>
19 | endBody() ?>
20 |
21 |
22 | endPage() ?>
23 |
--------------------------------------------------------------------------------
/common/tests/unit/_console.php:
--------------------------------------------------------------------------------
1 | [
10 | 'db' => [
11 | 'dsn' => 'mysql:host=localhost;dbname=yii2_advanced_unit',
12 | ],
13 | ],
14 | 'controllerMap' => [
15 | 'fixture' => [
16 | 'class' => 'yii\faker\FixtureController',
17 | 'fixtureDataPath' => '@common/tests/unit/fixtures/data',
18 | 'templatePath' => '@common/tests/templates/fixtures'
19 | ],
20 | ],
21 | ]
22 | );
23 |
--------------------------------------------------------------------------------
/console/tests/unit/_console.php:
--------------------------------------------------------------------------------
1 | [
10 | 'db' => [
11 | 'dsn' => 'mysql:host=localhost;dbname=yii2_advanced_unit',
12 | ],
13 | ],
14 | 'controllerMap' => [
15 | 'fixture' => [
16 | 'class' => 'yii\faker\FixtureController',
17 | 'fixtureDataPath' => '@console/tests/unit/fixtures/data',
18 | 'templatePath' => '@common/tests/templates/fixtures'
19 | ],
20 | ],
21 | ]
22 | );
23 |
--------------------------------------------------------------------------------
/backend/tests/unit/_console.php:
--------------------------------------------------------------------------------
1 | [
10 | 'db' => [
11 | 'dsn' => 'mysql:host=localhost;dbname=yii2_advanced_unit',
12 | ],
13 | ],
14 | 'controllerMap' => [
15 | 'fixture' => [
16 | 'class' => 'yii\faker\FixtureController',
17 | 'fixtureDataPath' => '@backend/tests/unit/fixtures/data',
18 | 'templatePath' => '@commmon/tests/templates/fixtures'
19 | ],
20 | ],
21 | ]
22 | );
23 |
--------------------------------------------------------------------------------
/frontend/tests/unit/_console.php:
--------------------------------------------------------------------------------
1 | [
10 | 'db' => [
11 | 'dsn' => 'mysql:host=localhost;dbname=yii2_advanced_unit',
12 | ],
13 | ],
14 | 'controllerMap' => [
15 | 'fixture' => [
16 | 'class' => 'yii\faker\FixtureController',
17 | 'fixtureDataPath' => '@frontend/tests/unit/fixtures/data',
18 | 'templatePath' => '@common/tests/templates/fixtures'
19 | ],
20 | ],
21 | ]
22 | );
23 |
--------------------------------------------------------------------------------
/common/tests/_bootstrap.php:
--------------------------------------------------------------------------------
1 | wantTo('ensure login page works');
7 |
8 | $loginPage = LoginPage::openBy($I);
9 |
10 | $I->amGoingTo('submit login form with no data');
11 | $loginPage->login('', '');
12 | $I->expectTo('see validations errors');
13 | $I->see('Username cannot be blank.', '.help-block');
14 | $I->see('Password cannot be blank.', '.help-block');
15 |
16 | $I->amGoingTo('try to login with wrong credentials');
17 | $I->expectTo('see validations errors');
18 | $loginPage->login('admin', 'wrong');
19 | $I->expectTo('see validations errors');
20 | $I->see('Incorrect username or password.', '.help-block');
21 |
22 | $I->amGoingTo('try to login with correct credentials');
23 | $loginPage->login('erau', 'password_0');
24 | $I->expectTo('see that user is logged');
25 | $I->seeLink('Logout (erau)');
26 | $I->dontSeeLink('Login');
27 | $I->dontSeeLink('Signup');
28 |
--------------------------------------------------------------------------------
/frontend/views/site/resetPassword.php:
--------------------------------------------------------------------------------
1 | title = 'Reset password';
10 | $this->params['breadcrumbs'][] = $this->title;
11 | ?>
12 |
13 |
= Html::encode($this->title) ?>
14 |
15 |
Please choose your new password:
16 |
17 |
18 |
19 | 'reset-password-form']); ?>
20 | = $form->field($model, 'password')->passwordInput() ?>
21 |
22 | = Html::submitButton('Save', ['class' => 'btn btn-primary']) ?>
23 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/frontend/tests/functional/LoginCept.php:
--------------------------------------------------------------------------------
1 | wantTo('ensure login page works');
7 |
8 | $loginPage = LoginPage::openBy($I);
9 |
10 | $I->amGoingTo('submit login form with no data');
11 | $loginPage->login('', '');
12 | $I->expectTo('see validations errors');
13 | $I->see('Username cannot be blank.', '.help-block');
14 | $I->see('Password cannot be blank.', '.help-block');
15 |
16 | $I->amGoingTo('try to login with wrong credentials');
17 | $I->expectTo('see validations errors');
18 | $loginPage->login('admin', 'wrong');
19 | $I->expectTo('see validations errors');
20 | $I->see('Incorrect username or password.', '.help-block');
21 |
22 | $I->amGoingTo('try to login with correct credentials');
23 | $loginPage->login('erau', 'password_0');
24 | $I->expectTo('see that user is logged');
25 | $I->seeLink('Logout (erau)');
26 | $I->dontSeeLink('Login');
27 | $I->dontSeeLink('Signup');
28 |
--------------------------------------------------------------------------------
/frontend/tests/unit/fixtures/data/models/user.php:
--------------------------------------------------------------------------------
1 | 'okirlin',
6 | 'auth_key' => 'iwTNae9t34OmnK6l4vT4IeaTk-YWI2Rv',
7 | 'password_hash' => '$2y$13$CXT0Rkle1EMJ/c1l5bylL.EylfmQ39O5JlHJVFpNn618OUS1HwaIi',
8 | 'password_reset_token' => 't5GU9NwpuGYSfb7FEZMAxqtuz2PkEvv_' . time(),
9 | 'created_at' => '1391885313',
10 | 'updated_at' => '1391885313',
11 | 'email' => 'brady.renner@rutherford.com',
12 | ],
13 | [
14 | 'username' => 'troy.becker',
15 | 'auth_key' => 'EdKfXrx88weFMV0vIxuTMWKgfK2tS3Lp',
16 | 'password_hash' => '$2y$13$g5nv41Px7VBqhS3hVsVN2.MKfgT3jFdkXEsMC4rQJLfaMa7VaJqL2',
17 | 'password_reset_token' => '4BSNyiZNAuxjs5Mty990c47sVrgllIi_' . time(),
18 | 'created_at' => '1391885313',
19 | 'updated_at' => '1391885313',
20 | 'email' => 'nicolas.dianna@hotmail.com',
21 | 'status' => '0',
22 | ],
23 | ];
24 |
--------------------------------------------------------------------------------
/frontend/views/site/requestPasswordResetToken.php:
--------------------------------------------------------------------------------
1 | title = 'Request password reset';
10 | $this->params['breadcrumbs'][] = $this->title;
11 | ?>
12 |
13 |
= Html::encode($this->title) ?>
14 |
15 |
Please fill out your email. A link to reset password will be sent there.
16 |
17 |
18 |
19 | 'request-password-reset-form']); ?>
20 | = $form->field($model, 'email') ?>
21 |
22 | = Html::submitButton('Send', ['class' => 'btn btn-primary']) ?>
23 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/common/tests/templates/fixtures/user.php:
--------------------------------------------------------------------------------
1 | 'userName',
5 | 'auth_key' => function ($fixture, $faker, $index) {
6 | $fixture['auth_key'] = Yii::$app->getSecurity()->generateRandomKey();
7 |
8 | return $fixture;
9 | },
10 | 'password_hash' => function ($fixture, $faker, $index) {
11 | $fixture['password_hash'] = Yii::$app->getSecurity()->generatePasswordHash('password_' . $index);
12 |
13 | return $fixture;
14 | },
15 | 'password_reset_token' => function ($fixture, $faker, $index) {
16 | $fixture['password_reset_token'] = Yii::$app->getSecurity()->generateRandomKey() . '_' . time();
17 |
18 | return $fixture;
19 | },
20 | 'created_at' => function ($fixture, $faker, $index) {
21 | $fixture['created_at'] = time();
22 |
23 | return $fixture;
24 | },
25 | 'updated_at' => function ($fixture, $faker, $index) {
26 | $fixture['updated_at'] = time();
27 |
28 | return $fixture;
29 | },
30 | 'email' => 'email',
31 | ];
32 |
--------------------------------------------------------------------------------
/frontend/config/main.php:
--------------------------------------------------------------------------------
1 | 'app-frontend',
11 | 'basePath' => dirname(__DIR__),
12 | 'bootstrap' => ['log'],
13 | 'controllerNamespace' => 'frontend\controllers',
14 | 'components' => [
15 | 'user' => [
16 | 'identityClass' => 'common\models\User',
17 | 'enableAutoLogin' => true,
18 | ],
19 | 'log' => [
20 | 'traceLevel' => YII_DEBUG ? 3 : 0,
21 | 'targets' => [
22 | [
23 | 'class' => 'yii\log\FileTarget',
24 | 'levels' => ['error', 'warning'],
25 | ],
26 | ],
27 | ],
28 | 'errorHandler' => [
29 | 'errorAction' => 'site/error',
30 | ],
31 | ],
32 | 'params' => $params,
33 | ];
34 |
--------------------------------------------------------------------------------
/frontend/views/site/signup.php:
--------------------------------------------------------------------------------
1 | title = 'Signup';
10 | $this->params['breadcrumbs'][] = $this->title;
11 | ?>
12 |
13 |
= Html::encode($this->title) ?>
14 |
15 |
Please fill out the following fields to signup:
16 |
17 |
18 |
19 | 'form-signup']); ?>
20 | = $form->field($model, 'username') ?>
21 | = $form->field($model, 'email') ?>
22 | = $form->field($model, 'password')->passwordInput() ?>
23 |
24 | = Html::submitButton('Signup', ['class' => 'btn btn-primary', 'name' => 'signup-button']) ?>
25 |
26 |
27 |
28 |
29 |
30 |
--------------------------------------------------------------------------------
/backend/config/main.php:
--------------------------------------------------------------------------------
1 | 'app-backend',
11 | 'basePath' => dirname(__DIR__),
12 | 'controllerNamespace' => 'backend\controllers',
13 | 'bootstrap' => ['log'],
14 | 'modules' => [],
15 | 'components' => [
16 | 'user' => [
17 | 'identityClass' => 'common\models\User',
18 | 'enableAutoLogin' => true,
19 | ],
20 | 'log' => [
21 | 'traceLevel' => YII_DEBUG ? 3 : 0,
22 | 'targets' => [
23 | [
24 | 'class' => 'yii\log\FileTarget',
25 | 'levels' => ['error', 'warning'],
26 | ],
27 | ],
28 | ],
29 | 'errorHandler' => [
30 | 'errorAction' => 'site/error',
31 | ],
32 | ],
33 | 'params' => $params,
34 | ];
35 |
--------------------------------------------------------------------------------
/backend/views/site/login.php:
--------------------------------------------------------------------------------
1 | title = 'Login';
10 | $this->params['breadcrumbs'][] = $this->title;
11 | ?>
12 |
13 |
= Html::encode($this->title) ?>
14 |
15 |
Please fill out the following fields to login:
16 |
17 |
18 |
19 | 'login-form']); ?>
20 | = $form->field($model, 'username') ?>
21 | = $form->field($model, 'password')->passwordInput() ?>
22 | = $form->field($model, 'rememberMe')->checkbox() ?>
23 |
24 | = Html::submitButton('Login', ['class' => 'btn btn-primary', 'name' => 'login-button']) ?>
25 |
26 |
27 |
28 |
29 |
30 |
--------------------------------------------------------------------------------
/backend/tests/acceptance/LoginCept.php:
--------------------------------------------------------------------------------
1 | wantTo('ensure login page works');
7 |
8 | $loginPage = LoginPage::openBy($I);
9 |
10 | $I->amGoingTo('submit login form with no data');
11 | $loginPage->login('', '');
12 | $I->expectTo('see validations errors');
13 | $I->see('Username cannot be blank.', '.help-block');
14 | $I->see('Password cannot be blank.', '.help-block');
15 |
16 | $I->amGoingTo('try to login with wrong credentials');
17 | $I->expectTo('see validations errors');
18 | $loginPage->login('admin', 'wrong');
19 | $I->expectTo('see validations errors');
20 | $I->see('Incorrect username or password.', '.help-block');
21 |
22 | $I->amGoingTo('try to login with correct credentials');
23 | $loginPage->login('erau', 'password_0');
24 | $I->expectTo('see that user is logged');
25 | $I->seeLink('Logout (erau)');
26 | $I->dontSeeLink('Login');
27 | $I->dontSeeLink('Signup');
28 | /** Uncomment if using WebDriver
29 | * $I->click('Logout (erau)');
30 | * $I->dontSeeLink('Logout (erau)');
31 | * $I->seeLink('Login');
32 | */
33 |
--------------------------------------------------------------------------------
/frontend/tests/acceptance/LoginCept.php:
--------------------------------------------------------------------------------
1 | wantTo('ensure login page works');
7 |
8 | $loginPage = LoginPage::openBy($I);
9 |
10 | $I->amGoingTo('submit login form with no data');
11 | $loginPage->login('', '');
12 | $I->expectTo('see validations errors');
13 | $I->see('Username cannot be blank.', '.help-block');
14 | $I->see('Password cannot be blank.', '.help-block');
15 |
16 | $I->amGoingTo('try to login with wrong credentials');
17 | $I->expectTo('see validations errors');
18 | $loginPage->login('admin', 'wrong');
19 | $I->expectTo('see validations errors');
20 | $I->see('Incorrect username or password.', '.help-block');
21 |
22 | $I->amGoingTo('try to login with correct credentials');
23 | $loginPage->login('erau', 'password_0');
24 | $I->expectTo('see that user is logged');
25 | $I->seeLink('Logout (erau)');
26 | $I->dontSeeLink('Login');
27 | $I->dontSeeLink('Signup');
28 | /** Uncomment if using WebDriver
29 | * $I->click('Logout (erau)');
30 | * $I->dontSeeLink('Logout (erau)');
31 | * $I->seeLink('Login');
32 | */
33 |
--------------------------------------------------------------------------------
/backend/tests/acceptance.suite.yml:
--------------------------------------------------------------------------------
1 | # Codeception Test Suite Configuration
2 |
3 | # suite for acceptance tests.
4 | # perform tests in browser using the Selenium-like tools.
5 | # powered by Mink (http://mink.behat.org).
6 | # (tip: that's what your customer will see).
7 | # (tip: test your ajax and javascript by one of Mink drivers).
8 |
9 | # RUN `build` COMMAND AFTER ADDING/REMOVING MODULES.
10 |
11 | class_name: WebGuy
12 | modules:
13 | enabled:
14 | - PhpBrowser
15 | - common\tests\_helpers\FixtureHelper
16 | # you can use WebDriver instead of PhpBrowser to test javascript and ajax.
17 | # This will require you to install selenium. See http://codeception.com/docs/04-AcceptanceTests#Selenium
18 | # "restart" option is used by the WebDriver to start each time per test-file new session and cookies,
19 | # it is useful if you want to login in your app in each test.
20 | # - WebDriver
21 | config:
22 | PhpBrowser:
23 | url: 'http://localhost:8080'
24 | # WebDriver:
25 | # url: 'http://localhost'
26 | # browser: firefox
27 | # restart: true
28 |
--------------------------------------------------------------------------------
/environments/dev/yii:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env php
2 | run();
31 | exit($exitCode);
32 |
--------------------------------------------------------------------------------
/environments/prod/yii:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env php
2 | run();
31 | exit($exitCode);
32 |
--------------------------------------------------------------------------------
/frontend/tests/acceptance.suite.yml:
--------------------------------------------------------------------------------
1 | # Codeception Test Suite Configuration
2 |
3 | # suite for acceptance tests.
4 | # perform tests in browser using the Selenium-like tools.
5 | # powered by Mink (http://mink.behat.org).
6 | # (tip: that's what your customer will see).
7 | # (tip: test your ajax and javascript by one of Mink drivers).
8 |
9 | # RUN `build` COMMAND AFTER ADDING/REMOVING MODULES.
10 |
11 | class_name: WebGuy
12 | modules:
13 | enabled:
14 | - PhpBrowser
15 | - common\tests\_helpers\FixtureHelper
16 | # you can use WebDriver instead of PhpBrowser to test javascript and ajax.
17 | # This will require you to install selenium. See http://codeception.com/docs/04-AcceptanceTests#Selenium
18 | # "restart" option is used by the WebDriver to start each time per test-file new session and cookies,
19 | # it is useful if you want to login in your app in each test.
20 | # - WebDriver
21 | config:
22 | PhpBrowser:
23 | url: 'http://localhost:8080'
24 | # WebDriver:
25 | # url: 'http://localhost'
26 | # browser: firefox
27 | # restart: true
28 |
--------------------------------------------------------------------------------
/console/migrations/m150812_020403_populate_country.php:
--------------------------------------------------------------------------------
1 | execute("
11 | INSERT INTO `Country` VALUES ('AU','Australia',18886000);
12 | INSERT INTO `Country` VALUES ('BR','Brazil',170115000);
13 | INSERT INTO `Country` VALUES ('CA','Canada',1147000);
14 | INSERT INTO `Country` VALUES ('CN','China',1277558000);
15 | INSERT INTO `Country` VALUES ('DE','Germany',82164700);
16 | INSERT INTO `Country` VALUES ('FR','France',59225700);
17 | INSERT INTO `Country` VALUES ('GB','United Kingdom',59623400);
18 | INSERT INTO `Country` VALUES ('IN','India',1013662000);
19 | INSERT INTO `Country` VALUES ('RU','Russia',146934000);
20 | INSERT INTO `Country` VALUES ('US','United States',278357000);
21 | ");
22 | }
23 |
24 | public function down()
25 | {
26 | $this->execute('DELETE FROM Country');
27 |
28 | return false;
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | RESTful API in Yii 2 Advanced Application Template
2 | ==================================================
3 |
4 | Yii2 Advanced Application Template with RESTful API configured. Take a look at http://budiirawan.com/setup-restful-api-yii2/ for more detail explanation
5 |
6 | ## Install Composer Packages
7 | You need [Composer](http://getcomposer.org) installed first.
8 | ```
9 | composer self-update
10 | ```
11 | ```
12 | composer install
13 | ```
14 |
15 | ## Run Yii Init
16 | Open terminal and go to the project folder and run
17 |
18 | Mac/Linux
19 | ```
20 | php ./init
21 | ```
22 |
23 | Windows
24 | ```
25 | init
26 | ```
27 | Choose **development** environment and finish the steps.
28 |
29 | ## Configure Database
30 | create your database and configure it in **common/config/main-local.php**
31 |
32 | ## Run Database Migration
33 | This command will create new country table and populate its data
34 |
35 | ```
36 | ./yii migrate
37 | ```
38 |
39 | ## Enable Mod Rewrite if you use Apache
40 | Make sure you already enable this mod. Follow this [Tutorial](http://stackoverflow.com/questions/869092/how-to-enable-mod-rewrite-for-apache-2-2)
41 |
42 |
43 |
44 |
45 |
46 |
47 |
--------------------------------------------------------------------------------
/environments/index.php:
--------------------------------------------------------------------------------
1 | [
11 | * 'path' => 'directory storing the local files',
12 | * 'writable' => [
13 | * // list of directories that should be set writable
14 | * ],
15 | * ],
16 | * ];
17 | * ```
18 | */
19 | return [
20 | 'Development' => [
21 | 'path' => 'dev',
22 | 'writable' => [
23 | 'backend/runtime',
24 | 'backend/web/assets',
25 | 'frontend/runtime',
26 | 'frontend/web/assets',
27 | ],
28 | 'executable' => [
29 | 'yii',
30 | ],
31 | ],
32 | 'Production' => [
33 | 'path' => 'prod',
34 | 'writable' => [
35 | 'backend/runtime',
36 | 'backend/web/assets',
37 | 'frontend/runtime',
38 | 'frontend/web/assets',
39 | ],
40 | 'executable' => [
41 | 'yii',
42 | ],
43 | ],
44 | ];
45 |
--------------------------------------------------------------------------------
/console/migrations/m130524_201442_init.php:
--------------------------------------------------------------------------------
1 | db->driverName === 'mysql') {
12 | $tableOptions = 'CHARACTER SET utf8 COLLATE utf8_general_ci ENGINE=InnoDB';
13 | }
14 |
15 | $this->createTable('{{%user}}', [
16 | 'id' => Schema::TYPE_PK,
17 | 'username' => Schema::TYPE_STRING . ' NOT NULL',
18 | 'auth_key' => Schema::TYPE_STRING . '(32) NOT NULL',
19 | 'password_hash' => Schema::TYPE_STRING . ' NOT NULL',
20 | 'password_reset_token' => Schema::TYPE_STRING,
21 | 'email' => Schema::TYPE_STRING . ' NOT NULL',
22 | 'role' => Schema::TYPE_SMALLINT . ' NOT NULL DEFAULT 10',
23 |
24 | 'status' => Schema::TYPE_SMALLINT . ' NOT NULL DEFAULT 10',
25 | 'created_at' => Schema::TYPE_INTEGER . ' NOT NULL',
26 | 'updated_at' => Schema::TYPE_INTEGER . ' NOT NULL',
27 | ], $tableOptions);
28 | }
29 |
30 | public function down()
31 | {
32 | $this->dropTable('{{%user}}');
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/frontend/tests/unit/models/ResetPasswordFormTest.php:
--------------------------------------------------------------------------------
1 | user[0]['password_reset_token']);
31 | expect('password should be resetted', $form->resetPassword())->true();
32 | }
33 |
34 | public function fixtures()
35 | {
36 | return [
37 | 'user' => [
38 | 'class' => UserFixture::className(),
39 | 'dataFile' => '@frontend/tests/unit/fixtures/data/models/user.php'
40 | ],
41 | ];
42 | }
43 |
44 | }
45 |
--------------------------------------------------------------------------------
/frontend/views/site/login.php:
--------------------------------------------------------------------------------
1 | title = 'Login';
10 | $this->params['breadcrumbs'][] = $this->title;
11 | ?>
12 |
13 |
= Html::encode($this->title) ?>
14 |
15 |
Please fill out the following fields to login:
16 |
17 |
18 |
19 | 'login-form']); ?>
20 | = $form->field($model, 'username') ?>
21 | = $form->field($model, 'password')->passwordInput() ?>
22 | = $form->field($model, 'rememberMe')->checkbox() ?>
23 |
24 | If you forgot your password you can = Html::a('reset it', ['site/request-password-reset']) ?>.
25 |
26 |
27 | = Html::submitButton('Login', ['class' => 'btn btn-primary', 'name' => 'login-button']) ?>
28 |
29 |
30 |
31 |
32 |
33 |
--------------------------------------------------------------------------------
/frontend/views/site/contact.php:
--------------------------------------------------------------------------------
1 | title = 'Contact';
11 | $this->params['breadcrumbs'][] = $this->title;
12 | ?>
13 |
38 |
--------------------------------------------------------------------------------
/composer.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "yiisoft/yii2-app-advanced",
3 | "description": "Yii 2 Advanced Application Template",
4 | "keywords": ["yii2", "framework", "advanced", "application 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": "dev",
16 | "require": {
17 | "php": ">=5.4.0",
18 | "yiisoft/yii2": "*",
19 | "yiisoft/yii2-bootstrap": "*",
20 | "yiisoft/yii2-swiftmailer": "*"
21 | },
22 | "require-dev": {
23 | "yiisoft/yii2-codeception": "*",
24 | "yiisoft/yii2-debug": "*",
25 | "yiisoft/yii2-gii": "*"
26 | },
27 | "suggest": {
28 | "codeception/codeception": "Codeception, 2.0.* is currently works well with Yii.",
29 | "codeception/specify": "BDD style code blocks for PHPUnit and Codeception",
30 | "codeception/verify": "BDD Assertions for PHPUnit and Codeception",
31 | "yiisoft/yii2-faker": "Fixtures generator for Yii2 based on Faker lib"
32 | },
33 | "scripts": {
34 | "post-create-project-cmd": [
35 | "yii\\composer\\Installer::setPermission"
36 | ]
37 | },
38 | "config": {
39 | "process-timeout": 1800
40 | },
41 | "extra": {
42 | "writable": [
43 | "backend/runtime",
44 | "backend/web/assets",
45 |
46 | "frontend/runtime",
47 | "frontend/web/assets"
48 | ]
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/frontend/models/ContactForm.php:
--------------------------------------------------------------------------------
1 | 'Verification Code',
41 | ];
42 | }
43 |
44 | /**
45 | * Sends an email to the specified email address using the information collected by this model.
46 | *
47 | * @param string $email the target email address
48 | * @return boolean whether the email was sent
49 | */
50 | public function sendEmail($email)
51 | {
52 | return Yii::$app->mailer->compose()
53 | ->setTo($email)
54 | ->setFrom([$this->email => $this->name])
55 | ->setSubject($this->subject)
56 | ->setTextBody($this->body)
57 | ->send();
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/api/config/main.php:
--------------------------------------------------------------------------------
1 | 'app-api',
12 | 'basePath' => dirname(__DIR__),
13 | 'bootstrap' => ['log'],
14 | 'modules' => [
15 | 'v1' => [
16 | 'basePath' => '@app/modules/v1',
17 | 'class' => 'api\modules\v1\Module'
18 | ]
19 | ],
20 | 'components' => [
21 | 'user' => [
22 | 'identityClass' => 'common\models\User',
23 | 'enableAutoLogin' => false,
24 | ],
25 | 'log' => [
26 | 'traceLevel' => YII_DEBUG ? 3 : 0,
27 | 'targets' => [
28 | [
29 | 'class' => 'yii\log\FileTarget',
30 | 'levels' => ['error', 'warning'],
31 | ],
32 | ],
33 | ],
34 | 'urlManager' => [
35 | 'enablePrettyUrl' => true,
36 | 'enableStrictParsing' => true,
37 | 'showScriptName' => false,
38 | 'rules' => [
39 | [
40 | 'class' => 'yii\rest\UrlRule',
41 | 'controller' => 'v1/country',
42 | 'tokens' => [
43 | '{id}' => ''
44 | ]
45 |
46 | ]
47 | ],
48 | ]
49 | ],
50 | 'params' => $params,
51 | ];
52 |
53 |
54 |
55 |
--------------------------------------------------------------------------------
/api/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 th {
76 | white-space: nowrap;
77 | }
78 |
79 | .hint-block {
80 | display: block;
81 | margin-top: 5px;
82 | color: #999;
83 | }
84 |
85 | .error-summary {
86 | color: #a94442;
87 | background: #fdf7f7;
88 | border-left: 3px solid #eed3d7;
89 | padding: 10px 20px;
90 | margin: 0 0 15px 0;
91 | }
92 |
--------------------------------------------------------------------------------
/frontend/models/SignupForm.php:
--------------------------------------------------------------------------------
1 | 'trim'],
24 | ['username', 'required'],
25 | ['username', 'unique', 'targetClass' => '\common\models\User', 'message' => 'This username has already been taken.'],
26 | ['username', 'string', 'min' => 2, 'max' => 255],
27 |
28 | ['email', 'filter', 'filter' => 'trim'],
29 | ['email', 'required'],
30 | ['email', 'email'],
31 | ['email', 'unique', 'targetClass' => '\common\models\User', 'message' => 'This email address has already been taken.'],
32 |
33 | ['password', 'required'],
34 | ['password', 'string', 'min' => 6],
35 | ];
36 | }
37 |
38 | /**
39 | * Signs user up.
40 | *
41 | * @return User|null the saved model or null if saving fails
42 | */
43 | public function signup()
44 | {
45 | if ($this->validate()) {
46 | $user = new User();
47 | $user->username = $this->username;
48 | $user->email = $this->email;
49 | $user->setPassword($this->password);
50 | $user->generateAuthKey();
51 | $user->save();
52 | return $user;
53 | }
54 |
55 | return null;
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/frontend/tests/acceptance/ContactCept.php:
--------------------------------------------------------------------------------
1 | wantTo('ensure that contact works');
7 |
8 | $contactPage = ContactPage::openBy($I);
9 |
10 | $I->see('Contact', 'h1');
11 |
12 | $I->amGoingTo('submit contact form with no data');
13 | $contactPage->submit([]);
14 | $I->expectTo('see validations errors');
15 | $I->see('Contact', 'h1');
16 | $I->see('Name cannot be blank', '.help-block');
17 | $I->see('Email cannot be blank', '.help-block');
18 | $I->see('Subject cannot be blank', '.help-block');
19 | $I->see('Body cannot be blank', '.help-block');
20 | $I->see('The verification code is incorrect', '.help-block');
21 |
22 | $I->amGoingTo('submit contact form with not correct email');
23 | $contactPage->submit([
24 | 'name' => 'tester',
25 | 'email' => 'tester.email',
26 | 'subject' => 'test subject',
27 | 'body' => 'test content',
28 | 'verifyCode' => 'testme',
29 | ]);
30 | $I->expectTo('see that email adress is wrong');
31 | $I->dontSee('Name cannot be blank', '.help-block');
32 | $I->see('Email is not a valid email address.', '.help-block');
33 | $I->dontSee('Subject cannot be blank', '.help-block');
34 | $I->dontSee('Body cannot be blank', '.help-block');
35 | $I->dontSee('The verification code is incorrect', '.help-block');
36 |
37 | $I->amGoingTo('submit contact form with correct data');
38 | $contactPage->submit([
39 | 'name' => 'tester',
40 | 'email' => 'tester@example.com',
41 | 'subject' => 'test subject',
42 | 'body' => 'test content',
43 | 'verifyCode' => 'testme',
44 | ]);
45 | $I->see('Thank you for contacting us. We will respond to you as soon as possible.');
46 |
--------------------------------------------------------------------------------
/frontend/tests/functional/ContactCept.php:
--------------------------------------------------------------------------------
1 | wantTo('ensure that contact works');
7 |
8 | $contactPage = ContactPage::openBy($I);
9 |
10 | $I->see('Contact', 'h1');
11 |
12 | $I->amGoingTo('submit contact form with no data');
13 | $contactPage->submit([]);
14 | $I->expectTo('see validations errors');
15 | $I->see('Contact', 'h1');
16 | $I->see('Name cannot be blank', '.help-block');
17 | $I->see('Email cannot be blank', '.help-block');
18 | $I->see('Subject cannot be blank', '.help-block');
19 | $I->see('Body cannot be blank', '.help-block');
20 | $I->see('The verification code is incorrect', '.help-block');
21 |
22 | $I->amGoingTo('submit contact form with not correct email');
23 | $contactPage->submit([
24 | 'name' => 'tester',
25 | 'email' => 'tester.email',
26 | 'subject' => 'test subject',
27 | 'body' => 'test content',
28 | 'verifyCode' => 'testme',
29 | ]);
30 | $I->expectTo('see that email adress is wrong');
31 | $I->dontSee('Name cannot be blank', '.help-block');
32 | $I->see('Email is not a valid email address.', '.help-block');
33 | $I->dontSee('Subject cannot be blank', '.help-block');
34 | $I->dontSee('Body cannot be blank', '.help-block');
35 | $I->dontSee('The verification code is incorrect', '.help-block');
36 |
37 | $I->amGoingTo('submit contact form with correct data');
38 | $contactPage->submit([
39 | 'name' => 'tester',
40 | 'email' => 'tester@example.com',
41 | 'subject' => 'test subject',
42 | 'body' => 'test content',
43 | 'verifyCode' => 'testme',
44 | ]);
45 | $I->see('Thank you for contacting us. We will respond to you as soon as possible.');
46 |
--------------------------------------------------------------------------------
/frontend/tests/unit/models/SignupFormTest.php:
--------------------------------------------------------------------------------
1 | 'some_username',
19 | 'email' => 'some_email@example.com',
20 | 'password' => 'some_password',
21 | ]);
22 |
23 | $user = $model->signup();
24 |
25 | $this->assertInstanceOf('common\models\User', $user, 'user should be valid');
26 |
27 | expect('username should be correct', $user->username)->equals('some_username');
28 | expect('email should be correct', $user->email)->equals('some_email@example.com');
29 | expect('password should be correct', $user->validatePassword('some_password'))->true();
30 | }
31 |
32 | public function testNotCorrectSignup()
33 | {
34 | $model = new SignupForm([
35 | 'username' => 'troy.becker',
36 | 'email' => 'nicolas.dianna@hotmail.com',
37 | 'password' => 'some_password',
38 | ]);
39 |
40 | expect('username and email are in use, user should not be created', $model->signup())->null();
41 | }
42 |
43 | public function fixtures()
44 | {
45 | return [
46 | 'user' => [
47 | 'class' => UserFixture::className(),
48 | 'dataFile' => '@frontend/tests/unit/fixtures/data/models/user.php',
49 | ],
50 | ];
51 | }
52 |
53 | }
54 |
--------------------------------------------------------------------------------
/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.
33 |
--------------------------------------------------------------------------------
/frontend/models/PasswordResetRequestForm.php:
--------------------------------------------------------------------------------
1 | 'trim'],
21 | ['email', 'required'],
22 | ['email', 'email'],
23 | ['email', 'exist',
24 | 'targetClass' => '\common\models\User',
25 | 'filter' => ['status' => User::STATUS_ACTIVE],
26 | 'message' => 'There is no user with such email.'
27 | ],
28 | ];
29 | }
30 |
31 | /**
32 | * Sends an email with a link, for resetting the password.
33 | *
34 | * @return boolean whether the email was send
35 | */
36 | public function sendEmail()
37 | {
38 | /* @var $user User */
39 | $user = User::findOne([
40 | 'status' => User::STATUS_ACTIVE,
41 | 'email' => $this->email,
42 | ]);
43 |
44 | if ($user) {
45 | $user->generatePasswordResetToken();
46 | if ($user->save()) {
47 | return \Yii::$app->mailer->compose('passwordResetToken', ['user' => $user])
48 | ->setFrom([\Yii::$app->params['supportEmail'] => \Yii::$app->name . ' robot'])
49 | ->setTo($this->email)
50 | ->setSubject('Password reset for ' . \Yii::$app->name)
51 | ->send();
52 | }
53 | }
54 |
55 | return false;
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/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 th {
76 | white-space: nowrap;
77 | }
78 |
79 | .hint-block {
80 | display: block;
81 | margin-top: 5px;
82 | color: #999;
83 | }
84 |
85 | .error-summary {
86 | color: #a94442;
87 | background: #fdf7f7;
88 | border-left: 3px solid #eed3d7;
89 | padding: 10px 20px;
90 | margin: 0 0 15px 0;
91 | }
92 |
--------------------------------------------------------------------------------
/frontend/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 th {
76 | white-space: nowrap;
77 | }
78 |
79 | .hint-block {
80 | display: block;
81 | margin-top: 5px;
82 | color: #999;
83 | }
84 |
85 | .error-summary {
86 | color: #a94442;
87 | background: #fdf7f7;
88 | border-left: 3px solid #eed3d7;
89 | padding: 10px 20px;
90 | margin: 0 0 15px 0;
91 | }
92 |
--------------------------------------------------------------------------------
/frontend/models/ResetPasswordForm.php:
--------------------------------------------------------------------------------
1 | _user = User::findByPasswordResetToken($token);
34 | if (!$this->_user) {
35 | throw new InvalidParamException('Wrong password reset token.');
36 | }
37 | parent::__construct($config);
38 | }
39 |
40 | /**
41 | * @inheritdoc
42 | */
43 | public function rules()
44 | {
45 | return [
46 | ['password', 'required'],
47 | ['password', 'string', 'min' => 6],
48 | ];
49 | }
50 |
51 | /**
52 | * Resets password.
53 | *
54 | * @return boolean if password was reset.
55 | */
56 | public function resetPassword()
57 | {
58 | $user = $this->_user;
59 | $user->password = $this->password;
60 | $user->removePasswordResetToken();
61 |
62 | return $user->save();
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/common/tests/_helpers/FixtureHelper.php:
--------------------------------------------------------------------------------
1 | loadFixtures();
38 | }
39 |
40 | /**
41 | * Method is called after all suite tests run
42 | */
43 | public function _afterSuite()
44 | {
45 | $this->unloadFixtures();
46 | }
47 |
48 | /**
49 | * @inheritdoc
50 | */
51 | public function fixtures()
52 | {
53 | return [
54 | 'user' => [
55 | 'class' => UserFixture::className(),
56 | 'dataFile' => '@common/tests/fixtures/data/init_login.php',
57 | ],
58 | ];
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/frontend/tests/unit/models/ContactFormTest.php:
--------------------------------------------------------------------------------
1 | mailer->fileTransportCallback = function ($mailer, $message) {
18 | return 'testing_message.eml';
19 | };
20 | }
21 |
22 | protected function tearDown()
23 | {
24 | unlink($this->getMessageFile());
25 | parent::tearDown();
26 | }
27 |
28 | public function testContact()
29 | {
30 | $model = new ContactForm();
31 |
32 | $model->attributes = [
33 | 'name' => 'Tester',
34 | 'email' => 'tester@example.com',
35 | 'subject' => 'very important letter subject',
36 | 'body' => 'body of current message',
37 | ];
38 |
39 | $model->sendEmail('admin@example.com');
40 |
41 | $this->specify('email should be send', function () {
42 | expect('email file should exist', file_exists($this->getMessageFile()))->true();
43 | });
44 |
45 | $this->specify('message should contain correct data', function () use ($model) {
46 | $emailMessage = file_get_contents($this->getMessageFile());
47 |
48 | expect('email should contain user name', $emailMessage)->contains($model->name);
49 | expect('email should contain sender email', $emailMessage)->contains($model->email);
50 | expect('email should contain subject', $emailMessage)->contains($model->subject);
51 | expect('email should contain body', $emailMessage)->contains($model->body);
52 | });
53 | }
54 |
55 | private function getMessageFile()
56 | {
57 | return Yii::getAlias(Yii::$app->mailer->fileTransportPath) . '/testing_message.eml';
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/common/models/LoginForm.php:
--------------------------------------------------------------------------------
1 | hasErrors()) {
40 | $user = $this->getUser();
41 | if (!$user || !$user->validatePassword($this->password)) {
42 | $this->addError('password', 'Incorrect username or password.');
43 | }
44 | }
45 | }
46 |
47 | /**
48 | * Logs in a user using the provided username and password.
49 | *
50 | * @return boolean whether the user is logged in successfully
51 | */
52 | public function login()
53 | {
54 | if ($this->validate()) {
55 | return Yii::$app->user->login($this->getUser(), $this->rememberMe ? 3600 * 24 * 30 : 0);
56 | } else {
57 | return false;
58 | }
59 | }
60 |
61 | /**
62 | * Finds user by [[username]]
63 | *
64 | * @return User|null
65 | */
66 | public function getUser()
67 | {
68 | if ($this->_user === false) {
69 | $this->_user = User::findByUsername($this->username);
70 | }
71 |
72 | return $this->_user;
73 | }
74 | }
75 |
--------------------------------------------------------------------------------
/backend/controllers/SiteController.php:
--------------------------------------------------------------------------------
1 | [
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 | public function actionIndex()
57 | {
58 | return $this->render('index');
59 | }
60 |
61 | public function actionLogin()
62 | {
63 | if (!\Yii::$app->user->isGuest) {
64 | return $this->goHome();
65 | }
66 |
67 | $model = new LoginForm();
68 | if ($model->load(Yii::$app->request->post()) && $model->login()) {
69 | return $this->goBack();
70 | } else {
71 | return $this->render('login', [
72 | 'model' => $model,
73 | ]);
74 | }
75 | }
76 |
77 | public function actionLogout()
78 | {
79 | Yii::$app->user->logout();
80 |
81 | return $this->goHome();
82 | }
83 | }
84 |
--------------------------------------------------------------------------------
/backend/views/layouts/main.php:
--------------------------------------------------------------------------------
1 |
13 | beginPage() ?>
14 |
15 |
16 |
17 |
18 |
19 | = Html::csrfMetaTags() ?>
20 | = Html::encode($this->title) ?>
21 | head() ?>
22 |
23 |
24 | beginBody() ?>
25 |
26 | 'My Company',
29 | 'brandUrl' => Yii::$app->homeUrl,
30 | 'options' => [
31 | 'class' => 'navbar-inverse navbar-fixed-top',
32 | ],
33 | ]);
34 | $menuItems = [
35 | ['label' => 'Home', 'url' => ['/site/index']],
36 | ];
37 | if (Yii::$app->user->isGuest) {
38 | $menuItems[] = ['label' => 'Login', 'url' => ['/site/login']];
39 | } else {
40 | $menuItems[] = [
41 | 'label' => 'Logout (' . Yii::$app->user->identity->username . ')',
42 | 'url' => ['/site/logout'],
43 | 'linkOptions' => ['data-method' => 'post']
44 | ];
45 | }
46 | echo Nav::widget([
47 | 'options' => ['class' => 'navbar-nav navbar-right'],
48 | 'items' => $menuItems,
49 | ]);
50 | NavBar::end();
51 | ?>
52 |
53 |
54 | = Breadcrumbs::widget([
55 | 'links' => isset($this->params['breadcrumbs']) ? $this->params['breadcrumbs'] : [],
56 | ]) ?>
57 | = $content ?>
58 |
59 |
60 |
61 |
67 |
68 | endBody() ?>
69 |
70 |
71 | endPage() ?>
72 |
--------------------------------------------------------------------------------
/frontend/views/site/index.php:
--------------------------------------------------------------------------------
1 | title = 'My Yii Application';
4 | ?>
5 |
6 |
7 |
8 |
Congratulations!
9 |
10 |
You have successfully created your Yii-powered application.
11 |
12 |
Get started with Yii
13 |
14 |
15 |
16 |
17 |
18 |
19 |
Heading
20 |
21 |
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et
22 | dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip
23 | ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu
24 | fugiat nulla pariatur.
25 |
26 |
Yii Documentation »
27 |
28 |
29 |
Heading
30 |
31 |
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et
32 | dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip
33 | ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu
34 | fugiat nulla pariatur.
35 |
36 |
Yii Forum »
37 |
38 |
39 |
Heading
40 |
41 |
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et
42 | dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip
43 | ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu
44 | fugiat nulla pariatur.
45 |
46 |
Yii Extensions »
47 |
48 |
49 |
50 |
51 |
52 |
--------------------------------------------------------------------------------
/backend/views/site/index.php:
--------------------------------------------------------------------------------
1 | title = 'My Yii Application';
5 | ?>
6 |
7 |
8 |
9 |
Congratulations!
10 |
11 |
You have successfully created your Yii-powered application.
12 |
13 |
Get started with Yii
14 |
15 |
16 |
17 |
18 |
19 |
20 |
Heading
21 |
22 |
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et
23 | dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip
24 | ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu
25 | fugiat nulla pariatur.
26 |
27 |
Yii Documentation »
28 |
29 |
30 |
Heading
31 |
32 |
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et
33 | dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip
34 | ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu
35 | fugiat nulla pariatur.
36 |
37 |
Yii Forum »
38 |
39 |
40 |
Heading
41 |
42 |
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et
43 | dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip
44 | ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu
45 | fugiat nulla pariatur.
46 |
47 |
Yii Extensions »
48 |
49 |
50 |
51 |
52 |
53 |
--------------------------------------------------------------------------------
/frontend/tests/acceptance/SignupCest.php:
--------------------------------------------------------------------------------
1 | 'tester.email@example.com',
27 | 'username' => 'tester',
28 | ]);
29 | }
30 |
31 | /**
32 | * This method is called when test fails.
33 | * @param \Codeception\Event\Fail $event
34 | */
35 | public function _fail($event)
36 | {
37 | }
38 |
39 | /**
40 | * @param \WebGuy $I
41 | * @param \Codeception\Scenario $scenario
42 | */
43 | public function testUserSignup($I, $scenario)
44 | {
45 | $I->wantTo('ensure that signup works');
46 |
47 | $signupPage = SignupPage::openBy($I);
48 | $I->see('Signup', 'h1');
49 | $I->see('Please fill out the following fields to signup:');
50 |
51 | $I->amGoingTo('submit signup form with no data');
52 |
53 | $signupPage->submit([]);
54 |
55 | $I->expectTo('see validation errors');
56 | $I->see('Username cannot be blank.', '.help-block');
57 | $I->see('Email cannot be blank.', '.help-block');
58 | $I->see('Password cannot be blank.', '.help-block');
59 |
60 | $I->amGoingTo('submit signup form with not correct email');
61 | $signupPage->submit([
62 | 'username' => 'tester',
63 | 'email' => 'tester.email',
64 | 'password' => 'tester_password',
65 | ]);
66 |
67 | $I->expectTo('see that email address is wrong');
68 | $I->dontSee('Username cannot be blank.', '.help-block');
69 | $I->dontSee('Password cannot be blank.', '.help-block');
70 | $I->see('Email is not a valid email address.', '.help-block');
71 |
72 | $I->amGoingTo('submit signup form with correct email');
73 | $signupPage->submit([
74 | 'username' => 'tester',
75 | 'email' => 'tester.email@example.com',
76 | 'password' => 'tester_password',
77 | ]);
78 |
79 | $I->expectTo('see that user logged in');
80 | $I->seeLink('Logout (tester)');
81 | }
82 | }
83 |
--------------------------------------------------------------------------------
/frontend/views/layouts/main.php:
--------------------------------------------------------------------------------
1 |
14 | beginPage() ?>
15 |
16 |
17 |
18 |
19 |
20 | = Html::csrfMetaTags() ?>
21 | = Html::encode($this->title) ?>
22 | head() ?>
23 |
24 |
25 | beginBody() ?>
26 |
27 | 'My Company',
30 | 'brandUrl' => Yii::$app->homeUrl,
31 | 'options' => [
32 | 'class' => 'navbar-inverse navbar-fixed-top',
33 | ],
34 | ]);
35 | $menuItems = [
36 | ['label' => 'Home', 'url' => ['/site/index']],
37 | ['label' => 'About', 'url' => ['/site/about']],
38 | ['label' => 'Contact', 'url' => ['/site/contact']],
39 | ];
40 | if (Yii::$app->user->isGuest) {
41 | $menuItems[] = ['label' => 'Signup', 'url' => ['/site/signup']];
42 | $menuItems[] = ['label' => 'Login', 'url' => ['/site/login']];
43 | } else {
44 | $menuItems[] = [
45 | 'label' => 'Logout (' . Yii::$app->user->identity->username . ')',
46 | 'url' => ['/site/logout'],
47 | 'linkOptions' => ['data-method' => 'post']
48 | ];
49 | }
50 | echo Nav::widget([
51 | 'options' => ['class' => 'navbar-nav navbar-right'],
52 | 'items' => $menuItems,
53 | ]);
54 | NavBar::end();
55 | ?>
56 |
57 |
58 | = Breadcrumbs::widget([
59 | 'links' => isset($this->params['breadcrumbs']) ? $this->params['breadcrumbs'] : [],
60 | ]) ?>
61 | = Alert::widget() ?>
62 | = $content ?>
63 |
64 |
65 |
66 |
72 |
73 | endBody() ?>
74 |
75 |
76 | endPage() ?>
77 |
--------------------------------------------------------------------------------
/frontend/widgets/Alert.php:
--------------------------------------------------------------------------------
1 | getSession()->setFlash('error', 'This is the message');
16 | * \Yii::$app->getSession()->setFlash('success', 'This is the message');
17 | * \Yii::$app->getSession()->setFlash('info', 'This is the message');
18 | * ```
19 | *
20 | * Multiple messages could be set as follows:
21 | *
22 | * ```php
23 | * \Yii::$app->getSession()->setFlash('error', ['Error 1', 'Error 2']);
24 | * ```
25 | *
26 | * @author Kartik Visweswaran
27 | * @author Alexander Makarov
28 | */
29 | class Alert extends \yii\bootstrap\Widget
30 | {
31 | /**
32 | * @var array the alert types configuration for the flash messages.
33 | * This array is setup as $key => $value, where:
34 | * - $key is the name of the session flash variable
35 | * - $value is the bootstrap alert type (i.e. danger, success, info, warning)
36 | */
37 | public $alertTypes = [
38 | 'error' => 'alert-danger',
39 | 'danger' => 'alert-danger',
40 | 'success' => 'alert-success',
41 | 'info' => 'alert-info',
42 | 'warning' => 'alert-warning'
43 | ];
44 |
45 | /**
46 | * @var array the options for rendering the close button tag.
47 | */
48 | public $closeButton = [];
49 |
50 | public function init()
51 | {
52 | parent::init();
53 |
54 | $session = \Yii::$app->getSession();
55 | $flashes = $session->getAllFlashes();
56 | $appendCss = isset($this->options['class']) ? ' ' . $this->options['class'] : '';
57 |
58 | foreach ($flashes as $type => $data) {
59 | if (isset($this->alertTypes[$type])) {
60 | $data = (array) $data;
61 | foreach ($data as $message) {
62 | /* initialize css class for each alert box */
63 | $this->options['class'] = $this->alertTypes[$type] . $appendCss;
64 |
65 | /* assign unique id to each alert box */
66 | $this->options['id'] = $this->getId() . '-' . $type;
67 |
68 | echo \yii\bootstrap\Alert::widget([
69 | 'body' => $message,
70 | 'closeButton' => $this->closeButton,
71 | 'options' => $this->options,
72 | ]);
73 | }
74 |
75 | $session->removeFlash($type);
76 | }
77 | }
78 | }
79 | }
80 |
--------------------------------------------------------------------------------
/frontend/tests/unit/models/PasswordResetRequestFormTest.php:
--------------------------------------------------------------------------------
1 | mailer->fileTransportCallback = function ($mailer, $message) {
21 | return 'testing_message.eml';
22 | };
23 | }
24 |
25 | protected function tearDown()
26 | {
27 | @unlink($this->getMessageFile());
28 |
29 | parent::tearDown();
30 | }
31 |
32 | public function testSendEmailWrongUser()
33 | {
34 | $this->specify('no user with such email, message should not be send', function () {
35 |
36 | $model = new PasswordResetRequestForm();
37 | $model->email = 'not-existing-email@example.com';
38 |
39 | expect('email not send', $model->sendEmail())->false();
40 |
41 | });
42 |
43 | $this->specify('user is not active, message should not be send', function () {
44 |
45 | $model = new PasswordResetRequestForm();
46 | $model->email = $this->user[1]['email'];
47 |
48 | expect('email not send', $model->sendEmail())->false();
49 |
50 | });
51 | }
52 |
53 | public function testSendEmailCorrectUser()
54 | {
55 | $model = new PasswordResetRequestForm();
56 | $model->email = $this->user[0]['email'];
57 | $user = User::findOne(['password_reset_token' => $this->user[0]['password_reset_token']]);
58 |
59 | expect('email sent', $model->sendEmail())->true();
60 | expect('user has valid token', $user->password_reset_token)->notNull();
61 |
62 | $this->specify('message has correct format', function () use ($model) {
63 |
64 | expect('message file exists', file_exists($this->getMessageFile()))->true();
65 |
66 | $message = file_get_contents($this->getMessageFile());
67 | expect('message "from" is correct', $message)->contains(Yii::$app->params['supportEmail']);
68 | expect('message "to" is correct', $message)->contains($model->email);
69 |
70 | });
71 | }
72 |
73 | public function fixtures()
74 | {
75 | return [
76 | 'user' => [
77 | 'class' => UserFixture::className(),
78 | 'dataFile' => '@frontend/tests/unit/fixtures/data/models/user.php'
79 | ],
80 | ];
81 | }
82 |
83 | private function getMessageFile()
84 | {
85 | return Yii::getAlias(Yii::$app->mailer->fileTransportPath) . '/testing_message.eml';
86 | }
87 |
88 | }
89 |
--------------------------------------------------------------------------------
/frontend/tests/functional/SignupCest.php:
--------------------------------------------------------------------------------
1 | 'tester.email@example.com',
27 | 'username' => 'tester',
28 | ]);
29 | }
30 |
31 | /**
32 | * This method is called when test fails.
33 | * @param \Codeception\Event\Fail $event
34 | */
35 | public function _fail($event)
36 | {
37 |
38 | }
39 |
40 | /**
41 | *
42 | * @param \TestGuy $I
43 | * @param \Codeception\Scenario $scenario
44 | */
45 | public function testUserSignup($I, $scenario)
46 | {
47 | $I->wantTo('ensure that signup works');
48 |
49 | $signupPage = SignupPage::openBy($I);
50 | $I->see('Signup', 'h1');
51 | $I->see('Please fill out the following fields to signup:');
52 |
53 | $I->amGoingTo('submit signup form with no data');
54 |
55 | $signupPage->submit([]);
56 |
57 | $I->expectTo('see validation errors');
58 | $I->see('Username cannot be blank.', '.help-block');
59 | $I->see('Email cannot be blank.', '.help-block');
60 | $I->see('Password cannot be blank.', '.help-block');
61 |
62 | $I->amGoingTo('submit signup form with not correct email');
63 | $signupPage->submit([
64 | 'username' => 'tester',
65 | 'email' => 'tester.email',
66 | 'password' => 'tester_password',
67 | ]);
68 |
69 | $I->expectTo('see that email address is wrong');
70 | $I->dontSee('Username cannot be blank.', '.help-block');
71 | $I->dontSee('Password cannot be blank.', '.help-block');
72 | $I->see('Email is not a valid email address.', '.help-block');
73 |
74 | $I->amGoingTo('submit signup form with correct email');
75 | $signupPage->submit([
76 | 'username' => 'tester',
77 | 'email' => 'tester.email@example.com',
78 | 'password' => 'tester_password',
79 | ]);
80 |
81 | $I->expectTo('see that user is created');
82 | $I->seeRecord('common\models\User', [
83 | 'username' => 'tester',
84 | 'email' => 'tester.email@example.com',
85 | ]);
86 |
87 | $I->expectTo('see that user logged in');
88 | $I->seeLink('Logout (tester)');
89 | }
90 | }
91 |
--------------------------------------------------------------------------------
/common/tests/unit/models/LoginFormTest.php:
--------------------------------------------------------------------------------
1 | [
22 | 'user' => [
23 | 'class' => 'yii\web\User',
24 | 'identityClass' => 'common\models\User',
25 | ],
26 | ],
27 | ]);
28 | }
29 |
30 | protected function tearDown()
31 | {
32 | Yii::$app->user->logout();
33 | parent::tearDown();
34 | }
35 |
36 | public function testLoginNoUser()
37 | {
38 | $model = new LoginForm([
39 | 'username' => 'not_existing_username',
40 | 'password' => 'not_existing_password',
41 | ]);
42 |
43 | $this->specify('user should not be able to login, when there is no identity', function () use ($model) {
44 | expect('model should not login user', $model->login())->false();
45 | expect('user should not be logged in', Yii::$app->user->isGuest)->true();
46 | });
47 | }
48 |
49 | public function testLoginWrongPassword()
50 | {
51 | $model = new LoginForm([
52 | 'username' => 'bayer.hudson',
53 | 'password' => 'wrong_password',
54 | ]);
55 |
56 | $this->specify('user should not be able to login with wrong password', function () use ($model) {
57 | expect('model should not login user', $model->login())->false();
58 | expect('error message should be set', $model->errors)->hasKey('password');
59 | expect('user should not be logged in', Yii::$app->user->isGuest)->true();
60 | });
61 | }
62 |
63 | public function testLoginCorrect()
64 | {
65 |
66 | $model = new LoginForm([
67 | 'username' => 'bayer.hudson',
68 | 'password' => 'password_0',
69 | ]);
70 |
71 | $this->specify('user should be able to login with correct credentials', function () use ($model) {
72 | expect('model should login user', $model->login())->true();
73 | expect('error message should not be set', $model->errors)->hasntKey('password');
74 | expect('user should be logged in', Yii::$app->user->isGuest)->false();
75 | });
76 | }
77 |
78 | public function fixtures()
79 | {
80 | return [
81 | 'user' => [
82 | 'class' => UserFixture::className(),
83 | 'dataFile' => '@common/tests/unit/fixtures/data/models/user.php'
84 | ],
85 | ];
86 | }
87 |
88 | }
89 |
--------------------------------------------------------------------------------
/requirements.php:
--------------------------------------------------------------------------------
1 | Error';
18 | echo 'The path to yii framework seems to be incorrect.
';
19 | echo 'You need to install Yii framework via composer or adjust the framework path in file ' . basename(__FILE__) . '.
';
20 | echo 'Please refer to the README on how to install Yii.
';
21 | }
22 |
23 | require_once($frameworkPath . '/requirements/YiiRequirementChecker.php');
24 | $requirementsChecker = new YiiRequirementChecker();
25 |
26 | /**
27 | * Adjust requirements according to your application specifics.
28 | */
29 | $requirements = array(
30 | // Database :
31 | array(
32 | 'name' => 'PDO extension',
33 | 'mandatory' => true,
34 | 'condition' => extension_loaded('pdo'),
35 | 'by' => 'All DB-related classes',
36 | ),
37 | array(
38 | 'name' => 'PDO SQLite extension',
39 | 'mandatory' => false,
40 | 'condition' => extension_loaded('pdo_sqlite'),
41 | 'by' => 'All DB-related classes',
42 | 'memo' => 'Required for SQLite database.',
43 | ),
44 | array(
45 | 'name' => 'PDO MySQL extension',
46 | 'mandatory' => false,
47 | 'condition' => extension_loaded('pdo_mysql'),
48 | 'by' => 'All DB-related classes',
49 | 'memo' => 'Required for MySQL database.',
50 | ),
51 | array(
52 | 'name' => 'PDO PostgreSQL extension',
53 | 'mandatory' => false,
54 | 'condition' => extension_loaded('pdo_pgsql'),
55 | 'by' => 'All DB-related classes',
56 | 'memo' => 'Required for PostgreSQL database.',
57 | ),
58 | // Cache :
59 | array(
60 | 'name' => 'Memcache extension',
61 | 'mandatory' => false,
62 | 'condition' => extension_loaded('memcache') || extension_loaded('memcached'),
63 | 'by' => 'MemCache',
64 | 'memo' => extension_loaded('memcached') ? 'To use memcached set MemCache::useMemcached to true.' : ''
65 | ),
66 | array(
67 | 'name' => 'APC extension',
68 | 'mandatory' => false,
69 | 'condition' => extension_loaded('apc'),
70 | 'by' => 'ApcCache',
71 | ),
72 | // PHP ini :
73 | 'phpSafeMode' => array(
74 | 'name' => 'PHP safe mode',
75 | 'mandatory' => false,
76 | 'condition' => $requirementsChecker->checkPhpIniOff("safe_mode"),
77 | 'by' => 'File uploading and console command execution',
78 | 'memo' => '"safe_mode" should be disabled at php.ini',
79 | ),
80 | 'phpExposePhp' => array(
81 | 'name' => 'Expose PHP',
82 | 'mandatory' => false,
83 | 'condition' => $requirementsChecker->checkPhpIniOff("expose_php"),
84 | 'by' => 'Security reasons',
85 | 'memo' => '"expose_php" should be disabled at php.ini',
86 | ),
87 | 'phpAllowUrlInclude' => array(
88 | 'name' => 'PHP allow url include',
89 | 'mandatory' => false,
90 | 'condition' => $requirementsChecker->checkPhpIniOff("allow_url_include"),
91 | 'by' => 'Security reasons',
92 | 'memo' => '"allow_url_include" should be disabled at php.ini',
93 | ),
94 | 'phpSmtp' => array(
95 | 'name' => 'PHP mail SMTP',
96 | 'mandatory' => false,
97 | 'condition' => strlen(ini_get('SMTP')) > 0,
98 | 'by' => 'Email sending',
99 | 'memo' => 'PHP mail SMTP server required',
100 | ),
101 | );
102 | $requirementsChecker->checkYii()->check($requirements)->render();
103 |
--------------------------------------------------------------------------------
/common/models/User.php:
--------------------------------------------------------------------------------
1 | self::STATUS_ACTIVE],
56 | ['status', 'in', 'range' => [self::STATUS_ACTIVE, self::STATUS_DELETED]],
57 |
58 | ['role', 'default', 'value' => self::ROLE_USER],
59 | ['role', 'in', 'range' => [self::ROLE_USER]],
60 | ];
61 | }
62 |
63 | /**
64 | * @inheritdoc
65 | */
66 | public static function findIdentity($id)
67 | {
68 | return static::findOne(['id' => $id, 'status' => self::STATUS_ACTIVE]);
69 | }
70 |
71 | /**
72 | * @inheritdoc
73 | */
74 | public static function findIdentityByAccessToken($token, $type = null)
75 | {
76 | throw new NotSupportedException('"findIdentityByAccessToken" is not implemented.');
77 | }
78 |
79 | /**
80 | * Finds user by username
81 | *
82 | * @param string $username
83 | * @return static|null
84 | */
85 | public static function findByUsername($username)
86 | {
87 | return static::findOne(['username' => $username, 'status' => self::STATUS_ACTIVE]);
88 | }
89 |
90 | /**
91 | * Finds user by password reset token
92 | *
93 | * @param string $token password reset token
94 | * @return static|null
95 | */
96 | public static function findByPasswordResetToken($token)
97 | {
98 | $expire = Yii::$app->params['user.passwordResetTokenExpire'];
99 | $parts = explode('_', $token);
100 | $timestamp = (int) end($parts);
101 | if ($timestamp + $expire < time()) {
102 | // token expired
103 | return null;
104 | }
105 |
106 | return static::findOne([
107 | 'password_reset_token' => $token,
108 | 'status' => self::STATUS_ACTIVE,
109 | ]);
110 | }
111 |
112 | /**
113 | * @inheritdoc
114 | */
115 | public function getId()
116 | {
117 | return $this->getPrimaryKey();
118 | }
119 |
120 | /**
121 | * @inheritdoc
122 | */
123 | public function getAuthKey()
124 | {
125 | return $this->auth_key;
126 | }
127 |
128 | /**
129 | * @inheritdoc
130 | */
131 | public function validateAuthKey($authKey)
132 | {
133 | return $this->getAuthKey() === $authKey;
134 | }
135 |
136 | /**
137 | * Validates password
138 | *
139 | * @param string $password password to validate
140 | * @return boolean if password provided is valid for current user
141 | */
142 | public function validatePassword($password)
143 | {
144 | return Yii::$app->security->validatePassword($password, $this->password_hash);
145 | }
146 |
147 | /**
148 | * Generates password hash from password and sets it to the model
149 | *
150 | * @param string $password
151 | */
152 | public function setPassword($password)
153 | {
154 | $this->password_hash = Yii::$app->security->generatePasswordHash($password);
155 | }
156 |
157 | /**
158 | * Generates "remember me" authentication key
159 | */
160 | public function generateAuthKey()
161 | {
162 | $this->auth_key = Yii::$app->security->generateRandomKey();
163 | }
164 |
165 | /**
166 | * Generates new password reset token
167 | */
168 | public function generatePasswordResetToken()
169 | {
170 | $this->password_reset_token = Yii::$app->security->generateRandomKey() . '_' . time();
171 | }
172 |
173 | /**
174 | * Removes password reset token
175 | */
176 | public function removePasswordResetToken()
177 | {
178 | $this->password_reset_token = null;
179 | }
180 | }
181 |
--------------------------------------------------------------------------------
/init:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env php
2 |
11 | *
12 | * @link http://www.yiiframework.com/
13 | * @copyright Copyright (c) 2008 Yii Software LLC
14 | * @license http://www.yiiframework.com/license/
15 | */
16 |
17 | $params = getParams();
18 | $root = str_replace('\\', '/', __DIR__);
19 | $envs = require("$root/environments/index.php");
20 | $envNames = array_keys($envs);
21 |
22 | echo "Yii Application Initialization Tool v1.0\n\n";
23 |
24 | $envName = null;
25 | if (empty($params['env']) || $params['env'] === '1') {
26 | echo "Which environment do you want the application to be initialized in?\n\n";
27 | foreach ($envNames as $i => $name) {
28 | echo " [$i] $name\n";
29 | }
30 | echo "\n Your choice [0-" . (count($envs) - 1) . ', or "q" to quit] ';
31 | $answer = trim(fgets(STDIN));
32 |
33 | if (!ctype_digit($answer) || !in_array($answer, range(0, count($envs) - 1))) {
34 | echo "\n Quit initialization.\n";
35 | exit(0);
36 | }
37 |
38 | if (isset($envNames[$answer])) {
39 | $envName = $envNames[$answer];
40 | }
41 | } else {
42 | $envName = $params['env'];
43 | }
44 |
45 | if (!in_array($envName, $envNames)) {
46 | $envsList = implode(', ', $envNames);
47 | echo "\n $envName is not a valid environment. Try one of the following: $envsList. \n";
48 | exit(2);
49 | }
50 |
51 | $env = $envs[$envName];
52 |
53 | if (empty($params['env'])) {
54 | echo "\n Initialize the application under '{$envNames[$answer]}' environment? [yes|no] ";
55 | $answer = trim(fgets(STDIN));
56 | if (strncasecmp($answer, 'y', 1)) {
57 | echo "\n Quit initialization.\n";
58 | exit(0);
59 | }
60 | }
61 |
62 | echo "\n Start initialization ...\n\n";
63 | $files = getFileList("$root/environments/{$env['path']}");
64 | $all = false;
65 | foreach ($files as $file) {
66 | if (!copyFile($root, "environments/{$env['path']}/$file", $file, $all, $params)) {
67 | break;
68 | }
69 | }
70 |
71 | if (isset($env['writable'])) {
72 | foreach ($env['writable'] as $writable) {
73 | echo " chmod 0777 $writable\n";
74 | @chmod("$root/$writable", 0777);
75 | }
76 | }
77 |
78 | if (isset($env['executable'])) {
79 | foreach ($env['executable'] as $executable) {
80 | echo " chmod 0755 $executable\n";
81 | @chmod("$root/$executable", 0755);
82 | }
83 | }
84 |
85 | echo "\n ... initialization completed.\n\n";
86 |
87 | function getFileList($root, $basePath = '')
88 | {
89 | $files = [];
90 | $handle = opendir($root);
91 | while (($path = readdir($handle)) !== false) {
92 | if ($path === '.svn' || $path === '.' || $path === '..') {
93 | continue;
94 | }
95 | $fullPath = "$root/$path";
96 | $relativePath = $basePath === '' ? $path : "$basePath/$path";
97 | if (is_dir($fullPath)) {
98 | $files = array_merge($files, getFileList($fullPath, $relativePath));
99 | } else {
100 | $files[] = $relativePath;
101 | }
102 | }
103 | closedir($handle);
104 | return $files;
105 | }
106 |
107 | function copyFile($root, $source, $target, &$all, $params)
108 | {
109 | if (!is_file($root . '/' . $source)) {
110 | echo " skip $target ($source not exist)\n";
111 | return true;
112 | }
113 | if (is_file($root . '/' . $target)) {
114 | if (file_get_contents($root . '/' . $source) === file_get_contents($root . '/' . $target)) {
115 | echo " unchanged $target\n";
116 | return true;
117 | }
118 | if ($all) {
119 | echo " overwrite $target\n";
120 | } else {
121 | echo " exist $target\n";
122 | echo " ...overwrite? [Yes|No|All|Quit] ";
123 |
124 |
125 | $answer = !empty($params['overwrite']) ? $params['overwrite'] : trim(fgets(STDIN));
126 | if (!strncasecmp($answer, 'q', 1)) {
127 | return false;
128 | } else {
129 | if (!strncasecmp($answer, 'y', 1)) {
130 | echo " overwrite $target\n";
131 | } else {
132 | if (!strncasecmp($answer, 'a', 1)) {
133 | echo " overwrite $target\n";
134 | $all = true;
135 | } else {
136 | echo " skip $target\n";
137 | return true;
138 | }
139 | }
140 | }
141 | }
142 | file_put_contents($root . '/' . $target, file_get_contents($root . '/' . $source));
143 | return true;
144 | }
145 | echo " generate $target\n";
146 | @mkdir(dirname($root . '/' . $target), 0777, true);
147 | file_put_contents($root . '/' . $target, file_get_contents($root . '/' . $source));
148 | return true;
149 | }
150 |
151 | function getParams()
152 | {
153 | $rawParams = [];
154 | if (isset($_SERVER['argv'])) {
155 | $rawParams = $_SERVER['argv'];
156 | array_shift($rawParams);
157 | }
158 |
159 | $params = [];
160 | foreach ($rawParams as $param) {
161 | if (preg_match('/^--(\w+)(=(.*))?$/', $param, $matches)) {
162 | $name = $matches[1];
163 | $params[$name] = isset($matches[3]) ? $matches[3] : true;
164 | } else {
165 | $params[] = $param;
166 | }
167 | }
168 | return $params;
169 | }
170 |
--------------------------------------------------------------------------------
/frontend/controllers/SiteController.php:
--------------------------------------------------------------------------------
1 | [
28 | 'class' => AccessControl::className(),
29 | 'only' => ['logout', 'signup'],
30 | 'rules' => [
31 | [
32 | 'actions' => ['signup'],
33 | 'allow' => true,
34 | 'roles' => ['?'],
35 | ],
36 | [
37 | 'actions' => ['logout'],
38 | 'allow' => true,
39 | 'roles' => ['@'],
40 | ],
41 | ],
42 | ],
43 | 'verbs' => [
44 | 'class' => VerbFilter::className(),
45 | 'actions' => [
46 | 'logout' => ['post'],
47 | ],
48 | ],
49 | ];
50 | }
51 |
52 | /**
53 | * @inheritdoc
54 | */
55 | public function actions()
56 | {
57 | return [
58 | 'error' => [
59 | 'class' => 'yii\web\ErrorAction',
60 | ],
61 | 'captcha' => [
62 | 'class' => 'yii\captcha\CaptchaAction',
63 | 'fixedVerifyCode' => YII_ENV_TEST ? 'testme' : null,
64 | ],
65 | ];
66 | }
67 |
68 | public function actionIndex()
69 | {
70 | return $this->render('index');
71 | }
72 |
73 | public function actionLogin()
74 | {
75 | if (!\Yii::$app->user->isGuest) {
76 | return $this->goHome();
77 | }
78 |
79 | $model = new LoginForm();
80 | if ($model->load(Yii::$app->request->post()) && $model->login()) {
81 | return $this->goBack();
82 | } else {
83 | return $this->render('login', [
84 | 'model' => $model,
85 | ]);
86 | }
87 | }
88 |
89 | public function actionLogout()
90 | {
91 | Yii::$app->user->logout();
92 |
93 | return $this->goHome();
94 | }
95 |
96 | public function actionContact()
97 | {
98 | $model = new ContactForm();
99 | if ($model->load(Yii::$app->request->post()) && $model->validate()) {
100 | if ($model->sendEmail(Yii::$app->params['adminEmail'])) {
101 | Yii::$app->session->setFlash('success', 'Thank you for contacting us. We will respond to you as soon as possible.');
102 | } else {
103 | Yii::$app->session->setFlash('error', 'There was an error sending email.');
104 | }
105 |
106 | return $this->refresh();
107 | } else {
108 | return $this->render('contact', [
109 | 'model' => $model,
110 | ]);
111 | }
112 | }
113 |
114 | public function actionAbout()
115 | {
116 | return $this->render('about');
117 | }
118 |
119 | public function actionSignup()
120 | {
121 | $model = new SignupForm();
122 | if ($model->load(Yii::$app->request->post())) {
123 | if ($user = $model->signup()) {
124 | if (Yii::$app->getUser()->login($user)) {
125 | return $this->goHome();
126 | }
127 | }
128 | }
129 |
130 | return $this->render('signup', [
131 | 'model' => $model,
132 | ]);
133 | }
134 |
135 | public function actionRequestPasswordReset()
136 | {
137 | $model = new PasswordResetRequestForm();
138 | if ($model->load(Yii::$app->request->post()) && $model->validate()) {
139 | if ($model->sendEmail()) {
140 | Yii::$app->getSession()->setFlash('success', 'Check your email for further instructions.');
141 |
142 | return $this->goHome();
143 | } else {
144 | Yii::$app->getSession()->setFlash('error', 'Sorry, we are unable to reset password for email provided.');
145 | }
146 | }
147 |
148 | return $this->render('requestPasswordResetToken', [
149 | 'model' => $model,
150 | ]);
151 | }
152 |
153 | public function actionResetPassword($token)
154 | {
155 | try {
156 | $model = new ResetPasswordForm($token);
157 | } catch (InvalidParamException $e) {
158 | throw new BadRequestHttpException($e->getMessage());
159 | }
160 |
161 | if ($model->load(Yii::$app->request->post()) && $model->validate() && $model->resetPassword()) {
162 | Yii::$app->getSession()->setFlash('success', 'New password was saved.');
163 |
164 | return $this->goHome();
165 | }
166 |
167 | return $this->render('resetPassword', [
168 | 'model' => $model,
169 | ]);
170 | }
171 | }
172 |
--------------------------------------------------------------------------------