7 | rem @link http://www.yiiframework.com/
8 | rem @copyright Copyright (c) 2008 Yii Software LLC
9 | rem @license http://www.yiiframework.com/license/
10 | rem -------------------------------------------------------------
11 |
12 | @setlocal
13 |
14 | set YII_PATH=%~dp0
15 |
16 | if "%PHP_COMMAND%" == "" set PHP_COMMAND=php.exe
17 |
18 | "%PHP_COMMAND%" "%YII_PATH%yii_test" %*
19 |
20 | @endlocal
21 |
--------------------------------------------------------------------------------
/frontend/views/user/update.php:
--------------------------------------------------------------------------------
1 | title = 'Update User: {nameAttribute}';
9 | $this->params['breadcrumbs'][] = ['label' => 'Users', 'url' => ['index']];
10 | $this->params['breadcrumbs'][] = ['label' => $model->id, 'url' => ['view', 'id' => $model->id]];
11 | $this->params['breadcrumbs'][] = 'Update';
12 | ?>
13 |
14 |
15 |
= Html::encode($this->title) ?>
16 |
17 | = $this->render('_form', [
18 | 'model' => $model,
19 | ]) ?>
20 |
21 |
22 |
--------------------------------------------------------------------------------
/frontend/views/employee/update.php:
--------------------------------------------------------------------------------
1 | title = 'Update Employee: {nameAttribute}';
9 | $this->params['breadcrumbs'][] = ['label' => 'Employees', 'url' => ['index']];
10 | $this->params['breadcrumbs'][] = ['label' => $model->name, 'url' => ['view', 'id' => $model->id]];
11 | $this->params['breadcrumbs'][] = 'Update';
12 | ?>
13 |
14 |
15 |
= Html::encode($this->title) ?>
16 |
17 | = $this->render('_form', [
18 | 'model' => $model,
19 | ]) ?>
20 |
21 |
22 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/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.php:
--------------------------------------------------------------------------------
1 | run();
18 |
--------------------------------------------------------------------------------
/environments/dev/frontend/web/index.php:
--------------------------------------------------------------------------------
1 | run();
18 |
--------------------------------------------------------------------------------
/environments/dev/backend/config/main-local.php:
--------------------------------------------------------------------------------
1 | [
5 | 'request' => [
6 | // !!! insert a secret key in the following (if it is empty) - this is required by cookie validation
7 | 'cookieValidationKey' => '',
8 | ],
9 | ],
10 | ];
11 |
12 | if (!YII_ENV_TEST) {
13 | // configuration adjustments for 'dev' environment
14 | $config['bootstrap'][] = 'debug';
15 | $config['modules']['debug'] = [
16 | 'class' => 'yii\debug\Module',
17 | ];
18 |
19 | $config['bootstrap'][] = 'gii';
20 | $config['modules']['gii'] = [
21 | 'class' => 'yii\gii\Module',
22 | ];
23 | }
24 |
25 | return $config;
26 |
--------------------------------------------------------------------------------
/environments/dev/frontend/config/main-local.php:
--------------------------------------------------------------------------------
1 | [
5 | 'request' => [
6 | // !!! insert a secret key in the following (if it is empty) - this is required by cookie validation
7 | 'cookieValidationKey' => '',
8 | ],
9 | ],
10 | ];
11 |
12 | if (!YII_ENV_TEST) {
13 | // configuration adjustments for 'dev' environment
14 | $config['bootstrap'][] = 'debug';
15 | $config['modules']['debug'] = [
16 | 'class' => 'yii\debug\Module',
17 | ];
18 |
19 | $config['bootstrap'][] = 'gii';
20 | $config['modules']['gii'] = [
21 | 'class' => 'yii\gii\Module',
22 | ];
23 | }
24 |
25 | return $config;
26 |
--------------------------------------------------------------------------------
/environments/prod/backend/web/index.php:
--------------------------------------------------------------------------------
1 | run();
18 |
--------------------------------------------------------------------------------
/environments/prod/frontend/web/index.php:
--------------------------------------------------------------------------------
1 | run();
18 |
--------------------------------------------------------------------------------
/environments/dev/backend/web/index-test.php:
--------------------------------------------------------------------------------
1 | run();
19 |
--------------------------------------------------------------------------------
/environments/dev/frontend/web/index-test.php:
--------------------------------------------------------------------------------
1 | run();
19 |
--------------------------------------------------------------------------------
/common/tests/_support/UnitTester.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 |
--------------------------------------------------------------------------------
/backend/tests/_support/UnitTester.php:
--------------------------------------------------------------------------------
1 |
10 |
11 |
30 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/environments/dev/yii_test:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env php
2 | run();
27 | exit($exitCode);
28 |
--------------------------------------------------------------------------------
/frontend/views/employee/_search.php:
--------------------------------------------------------------------------------
1 |
10 |
11 |
12 |
13 | ['index'],
15 | 'method' => 'get',
16 | ]); ?>
17 |
18 | = $form->field($model, 'id') ?>
19 |
20 | = $form->field($model, 'name') ?>
21 |
22 | = $form->field($model, 'email') ?>
23 |
24 | = $form->field($model, 'created_at') ?>
25 |
26 | = $form->field($model, 'updated_at') ?>
27 |
28 |
29 | = Html::submitButton('Search', ['class' => 'btn btn-primary']) ?>
30 | = Html::resetButton('Reset', ['class' => 'btn btn-default']) ?>
31 |
32 |
33 |
34 |
35 |
36 |
--------------------------------------------------------------------------------
/frontend/tests/_data/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 |
--------------------------------------------------------------------------------
/environments/dev/yii:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env php
2 | run();
28 | exit($exitCode);
29 |
--------------------------------------------------------------------------------
/environments/prod/yii:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env php
2 | run();
28 | exit($exitCode);
29 |
--------------------------------------------------------------------------------
/frontend/tests/_support/FunctionalTester.php:
--------------------------------------------------------------------------------
1 | see($message, '.help-block');
27 | }
28 |
29 | public function dontSeeValidationError($message)
30 | {
31 | $this->dontSee($message, '.help-block');
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/vagrant/provision/once-as-vagrant.sh:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | #== Import script args ==
4 |
5 | github_token=$(echo "$1")
6 |
7 | #== Bash helpers ==
8 |
9 | function info {
10 | echo " "
11 | echo "--> $1"
12 | echo " "
13 | }
14 |
15 | #== Provision script ==
16 |
17 | info "Provision-script user: `whoami`"
18 |
19 | info "Configure composer"
20 | composer config --global github-oauth.github.com ${github_token}
21 | echo "Done!"
22 |
23 | info "Install project dependencies"
24 | cd /app
25 | composer --no-progress --prefer-dist install
26 |
27 | info "Init project"
28 | ./init --env=Development --overwrite=y
29 |
30 | info "Apply migrations"
31 | ./yii migrate --interactive=0
32 | ./yii_test migrate --interactive=0
33 |
34 | info "Create bash-alias 'app' for vagrant user"
35 | echo 'alias app="cd /app"' | tee /home/vagrant/.bash_aliases
36 |
37 | info "Enabling colorized prompt for guest console"
38 | sed -i "s/#force_color_prompt=yes/force_color_prompt=yes/" /home/vagrant/.bashrc
39 |
--------------------------------------------------------------------------------
/frontend/views/site/resetPassword.php:
--------------------------------------------------------------------------------
1 | title = 'Reset password';
11 | $this->params['breadcrumbs'][] = $this->title;
12 | ?>
13 |
14 |
= Html::encode($this->title) ?>
15 |
16 |
Please choose your new password:
17 |
18 |
19 |
20 | 'reset-password-form']); ?>
21 |
22 | = $form->field($model, 'password')->passwordInput(['autofocus' => true]) ?>
23 |
24 |
25 | = Html::submitButton('Save', ['class' => 'btn btn-primary']) ?>
26 |
27 |
28 |
29 |
30 |
31 |
32 |
--------------------------------------------------------------------------------
/frontend/views/employee/index.php:
--------------------------------------------------------------------------------
1 | title = 'Employees';
11 | $this->params['breadcrumbs'][] = $this->title;
12 | ?>
13 |
14 |
15 |
= Html::encode($this->title) ?>
16 | render('_search', ['model' => $searchModel]); ?>
17 |
18 |
19 | = Html::a('Create Employee', ['create'], ['class' => 'btn btn-success']) ?>
20 |
21 |
22 | = GridView::widget([
23 | 'dataProvider' => $dataProvider,
24 | 'filterModel' => $searchModel,
25 | 'columns' => [
26 | ['class' => 'yii\grid\SerialColumn'],
27 |
28 | 'id',
29 | 'name',
30 | 'email:email',
31 | 'created_at',
32 | 'updated_at',
33 |
34 | ['class' => 'yii\grid\ActionColumn'],
35 | ],
36 | ]); ?>
37 |
38 |
--------------------------------------------------------------------------------
/frontend/views/site/requestPasswordResetToken.php:
--------------------------------------------------------------------------------
1 | title = 'Request password reset';
11 | $this->params['breadcrumbs'][] = $this->title;
12 | ?>
13 |
14 |
= Html::encode($this->title) ?>
15 |
16 |
Please fill out your email. A link to reset password will be sent there.
17 |
18 |
19 |
20 | 'request-password-reset-form']); ?>
21 |
22 | = $form->field($model, 'email')->textInput(['autofocus' => true]) ?>
23 |
24 |
25 | = Html::submitButton('Send', ['class' => 'btn btn-primary']) ?>
26 |
27 |
28 |
29 |
30 |
31 |
32 |
--------------------------------------------------------------------------------
/console/config/main.php:
--------------------------------------------------------------------------------
1 | 'app-console',
11 | 'basePath' => dirname(__DIR__),
12 | 'bootstrap' => ['log'],
13 | 'controllerNamespace' => 'console\controllers',
14 | 'aliases' => [
15 | '@bower' => '@vendor/bower-asset',
16 | '@npm' => '@vendor/npm-asset',
17 | ],
18 | 'controllerMap' => [
19 | 'fixture' => [
20 | 'class' => 'yii\console\controllers\FixtureController',
21 | 'namespace' => 'common\fixtures',
22 | ],
23 | ],
24 | 'components' => [
25 | 'log' => [
26 | 'targets' => [
27 | [
28 | 'class' => 'yii\log\FileTarget',
29 | 'levels' => ['error', 'warning'],
30 | ],
31 | ],
32 | ],
33 | ],
34 | 'params' => $params,
35 | ];
36 |
--------------------------------------------------------------------------------
/frontend/views/site/signup.php:
--------------------------------------------------------------------------------
1 | title = 'Signup';
11 | $this->params['breadcrumbs'][] = $this->title;
12 | ?>
13 |
14 |
= Html::encode($this->title) ?>
15 |
16 |
Please fill out the following fields to signup:
17 |
18 |
19 |
20 | 'form-signup']); ?>
21 |
22 | = $form->field($model, 'username')->textInput(['autofocus' => true]) ?>
23 |
24 | = $form->field($model, 'email') ?>
25 |
26 | = $form->field($model, 'password')->passwordInput() ?>
27 |
28 |
29 | = Html::submitButton('Signup', ['class' => 'btn btn-primary', 'name' => 'signup-button']) ?>
30 |
31 |
32 |
33 |
34 |
35 |
36 |
--------------------------------------------------------------------------------
/frontend/views/user/_form.php:
--------------------------------------------------------------------------------
1 |
10 |
11 |
38 |
--------------------------------------------------------------------------------
/backend/views/site/login.php:
--------------------------------------------------------------------------------
1 | title = 'Login';
11 | $this->params['breadcrumbs'][] = $this->title;
12 | ?>
13 |
14 |
= Html::encode($this->title) ?>
15 |
16 |
Please fill out the following fields to login:
17 |
18 |
19 |
20 | 'login-form']); ?>
21 |
22 | = $form->field($model, 'username')->textInput(['autofocus' => true]) ?>
23 |
24 | = $form->field($model, 'password')->passwordInput() ?>
25 |
26 | = $form->field($model, 'rememberMe')->checkbox() ?>
27 |
28 |
29 | = Html::submitButton('Login', ['class' => 'btn btn-primary', 'name' => 'login-button']) ?>
30 |
31 |
32 |
33 |
34 |
35 |
36 |
--------------------------------------------------------------------------------
/frontend/views/employee/view.php:
--------------------------------------------------------------------------------
1 | title = $model->name;
10 | $this->params['breadcrumbs'][] = ['label' => 'Employees', 'url' => ['index']];
11 | $this->params['breadcrumbs'][] = $this->title;
12 | ?>
13 |
14 |
15 |
= Html::encode($this->title) ?>
16 |
17 |
18 | = Html::a('Update', ['update', 'id' => $model->id], ['class' => 'btn btn-primary']) ?>
19 | = Html::a('Delete', ['delete', 'id' => $model->id], [
20 | 'class' => 'btn btn-danger',
21 | 'data' => [
22 | 'confirm' => 'Are you sure you want to delete this item?',
23 | 'method' => 'post',
24 | ],
25 | ]) ?>
26 |
27 |
28 | = DetailView::widget([
29 | 'model' => $model,
30 | 'attributes' => [
31 | 'id',
32 | 'name',
33 | 'email:email',
34 | 'created_at',
35 | 'updated_at',
36 | ],
37 | ]) ?>
38 |
39 |
40 |
--------------------------------------------------------------------------------
/frontend/views/user/_search.php:
--------------------------------------------------------------------------------
1 |
10 |
11 |
12 |
13 | ['index'],
15 | 'method' => 'get',
16 | ]); ?>
17 |
18 | = $form->field($model, 'id') ?>
19 |
20 | = $form->field($model, 'username') ?>
21 |
22 | = $form->field($model, 'auth_key') ?>
23 |
24 | = $form->field($model, 'password_hash') ?>
25 |
26 | = $form->field($model, 'password_reset_token') ?>
27 |
28 | field($model, 'email') ?>
29 |
30 | field($model, 'status') ?>
31 |
32 | field($model, 'created_at') ?>
33 |
34 | field($model, 'updated_at') ?>
35 |
36 |
37 | = Html::submitButton('Search', ['class' => 'btn btn-primary']) ?>
38 | = Html::resetButton('Reset', ['class' => 'btn btn-default']) ?>
39 |
40 |
41 |
42 |
43 |
44 |
--------------------------------------------------------------------------------
/frontend/views/user/index.php:
--------------------------------------------------------------------------------
1 | title = 'Users';
11 | $this->params['breadcrumbs'][] = $this->title;
12 | ?>
13 |
14 |
15 |
= Html::encode($this->title) ?>
16 | render('_search', ['model' => $searchModel]); ?>
17 |
18 |
19 | = Html::a('Create User', ['create'], ['class' => 'btn btn-success']) ?>
20 |
21 |
22 | = GridView::widget([
23 | 'dataProvider' => $dataProvider,
24 | 'filterModel' => $searchModel,
25 | 'columns' => [
26 | ['class' => 'yii\grid\SerialColumn'],
27 |
28 | 'id',
29 | 'username',
30 | 'auth_key',
31 | 'password_hash',
32 | 'password_reset_token',
33 | // 'email:email',
34 | // 'status',
35 | // 'created_at',
36 | // 'updated_at',
37 |
38 | ['class' => 'yii\grid\ActionColumn'],
39 | ],
40 | ]); ?>
41 |
42 |
--------------------------------------------------------------------------------
/frontend/models/Employee.php:
--------------------------------------------------------------------------------
1 | 200],
35 | [['email'], 'string', 'max' => 100],
36 | ];
37 | }
38 |
39 | /**
40 | * @inheritdoc
41 | */
42 | public function attributeLabels()
43 | {
44 | return [
45 | 'id' => 'ID',
46 | 'name' => 'Name',
47 | 'email' => 'Email',
48 | 'created_at' => 'Created At',
49 | 'updated_at' => 'Updated At',
50 | ];
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/backend/tests/functional/LoginCest.php:
--------------------------------------------------------------------------------
1 | [
25 | 'class' => UserFixture::className(),
26 | 'dataFile' => codecept_data_dir() . 'login_data.php'
27 | ]
28 | ];
29 | }
30 |
31 | /**
32 | * @param FunctionalTester $I
33 | */
34 | public function loginUser(FunctionalTester $I)
35 | {
36 | $I->amOnPage('/site/login');
37 | $I->fillField('Username', 'erau');
38 | $I->fillField('Password', 'password_0');
39 | $I->click('login-button');
40 |
41 | $I->see('Logout (erau)', 'form button[type=submit]');
42 | $I->dontSeeLink('Login');
43 | $I->dontSeeLink('Signup');
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/frontend/tests/unit/models/ContactFormTest.php:
--------------------------------------------------------------------------------
1 | attributes = [
14 | 'name' => 'Tester',
15 | 'email' => 'tester@example.com',
16 | 'subject' => 'very important letter subject',
17 | 'body' => 'body of current message',
18 | ];
19 |
20 | expect_that($model->sendEmail('admin@example.com'));
21 |
22 | // using Yii2 module actions to check email was sent
23 | $this->tester->seeEmailIsSent();
24 |
25 | $emailMessage = $this->tester->grabLastSentEmail();
26 | expect('valid email is sent', $emailMessage)->isInstanceOf('yii\mail\MessageInterface');
27 | expect($emailMessage->getTo())->hasKey('admin@example.com');
28 | expect($emailMessage->getFrom())->hasKey('tester@example.com');
29 | expect($emailMessage->getSubject())->equals('very important letter subject');
30 | expect($emailMessage->toString())->contains('body of current message');
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/console/migrations/m130524_201442_init.php:
--------------------------------------------------------------------------------
1 | db->driverName === 'mysql') {
11 | // http://stackoverflow.com/questions/766809/whats-the-difference-between-utf8-general-ci-and-utf8-unicode-ci
12 | $tableOptions = 'CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE=InnoDB';
13 | }
14 |
15 | $this->createTable('{{%user}}', [
16 | 'id' => $this->primaryKey(),
17 | 'username' => $this->string()->notNull()->unique(),
18 | 'auth_key' => $this->string(32)->notNull(),
19 | 'password_hash' => $this->string()->notNull(),
20 | 'password_reset_token' => $this->string()->unique(),
21 | 'email' => $this->string()->notNull()->unique(),
22 |
23 | 'status' => $this->smallInteger()->notNull()->defaultValue(10),
24 | 'created_at' => $this->integer()->notNull(),
25 | 'updated_at' => $this->integer()->notNull(),
26 | ], $tableOptions);
27 | }
28 |
29 | public function down()
30 | {
31 | $this->dropTable('{{%user}}');
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/frontend/views/user/view.php:
--------------------------------------------------------------------------------
1 | title = $model->id;
10 | $this->params['breadcrumbs'][] = ['label' => 'Users', 'url' => ['index']];
11 | $this->params['breadcrumbs'][] = $this->title;
12 | ?>
13 |
14 |
15 |
= Html::encode($this->title) ?>
16 |
17 |
18 | = Html::a('Update', ['update', 'id' => $model->id], ['class' => 'btn btn-primary']) ?>
19 | = Html::a('Delete', ['delete', 'id' => $model->id], [
20 | 'class' => 'btn btn-danger',
21 | 'data' => [
22 | 'confirm' => 'Are you sure you want to delete this item?',
23 | 'method' => 'post',
24 | ],
25 | ]) ?>
26 |
27 |
28 | = DetailView::widget([
29 | 'model' => $model,
30 | 'attributes' => [
31 | 'id',
32 | 'username',
33 | 'auth_key',
34 | 'password_hash',
35 | 'password_reset_token',
36 | 'email:email',
37 | 'status',
38 | 'created_at',
39 | 'updated_at',
40 | ],
41 | ]) ?>
42 |
43 |
44 |
--------------------------------------------------------------------------------
/frontend/tests/unit/models/ResetPasswordFormTest.php:
--------------------------------------------------------------------------------
1 | tester->haveFixtures([
19 | 'user' => [
20 | 'class' => UserFixture::className(),
21 | 'dataFile' => codecept_data_dir() . 'user.php'
22 | ],
23 | ]);
24 | }
25 |
26 | public function testResetWrongToken()
27 | {
28 | $this->tester->expectException('yii\base\InvalidParamException', function() {
29 | new ResetPasswordForm('');
30 | });
31 |
32 | $this->tester->expectException('yii\base\InvalidParamException', function() {
33 | new ResetPasswordForm('notexistingtoken_1391882543');
34 | });
35 | }
36 |
37 | public function testResetCorrectToken()
38 | {
39 | $user = $this->tester->grabFixture('user', 0);
40 | $form = new ResetPasswordForm($user['password_reset_token']);
41 | expect_that($form->resetPassword());
42 | }
43 |
44 | }
45 |
--------------------------------------------------------------------------------
/composer.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "yiisoft/yii2-app-advanced",
3 | "description": "Yii 2 Advanced Project Template",
4 | "keywords": ["yii2", "framework", "advanced", "project template"],
5 | "homepage": "http://www.yiiframework.com/",
6 | "type": "project",
7 | "license": "BSD-3-Clause",
8 | "support": {
9 | "issues": "https://github.com/yiisoft/yii2/issues?state=open",
10 | "forum": "http://www.yiiframework.com/forum/",
11 | "wiki": "http://www.yiiframework.com/wiki/",
12 | "irc": "irc://irc.freenode.net/yii",
13 | "source": "https://github.com/yiisoft/yii2"
14 | },
15 | "minimum-stability": "dev",
16 | "require": {
17 | "php": ">=5.4.0",
18 | "yiisoft/yii2": "~2.0.6",
19 | "yiisoft/yii2-bootstrap": "~2.0.0",
20 | "yiisoft/yii2-swiftmailer": "~2.0.0 || ~2.1.0"
21 | },
22 | "require-dev": {
23 | "yiisoft/yii2-debug": "~2.0.0",
24 | "yiisoft/yii2-gii": "~2.0.0",
25 | "yiisoft/yii2-faker": "~2.0.0",
26 | "codeception/base": "^2.2.3",
27 | "codeception/verify": "~0.3.1"
28 | },
29 | "config": {
30 | "process-timeout": 1800
31 | },
32 | "repositories": [
33 | {
34 | "type": "composer",
35 | "url": "https://asset-packagist.org"
36 | }
37 | ]
38 | }
39 |
--------------------------------------------------------------------------------
/frontend/views/site/login.php:
--------------------------------------------------------------------------------
1 | title = 'Login';
11 | $this->params['breadcrumbs'][] = $this->title;
12 | ?>
13 |
14 |
= Html::encode($this->title) ?>
15 |
16 |
Please fill out the following fields to login:
17 |
18 |
19 |
20 | 'login-form']); ?>
21 |
22 | = $form->field($model, 'username')->textInput(['autofocus' => true]) ?>
23 |
24 | = $form->field($model, 'password')->passwordInput() ?>
25 |
26 | = $form->field($model, 'rememberMe')->checkbox() ?>
27 |
28 |
29 | If you forgot your password you can = Html::a('reset it', ['site/request-password-reset']) ?>.
30 |
31 |
32 |
33 | = Html::submitButton('Login', ['class' => 'btn btn-primary', 'name' => 'login-button']) ?>
34 |
35 |
36 |
37 |
38 |
39 |
40 |
--------------------------------------------------------------------------------
/console/migrations/m170916_095928_adding_first_user.php:
--------------------------------------------------------------------------------
1 | db->createCommand($sql)->execute();
19 | }
20 |
21 | /**
22 | * @inheritdoc
23 | */
24 | public function safeDown()
25 | {
26 | // echo "m170916_095928_adding_first_user cannot be reverted.\n";
27 |
28 | $sql="DELETE from user where username='sirinibin'";
29 | Yii::$app->db->createCommand($sql)->execute();
30 |
31 | }
32 |
33 | /*
34 | // Use up()/down() to run migration code without a transaction.
35 | public function up()
36 | {
37 |
38 | }
39 |
40 | public function down()
41 | {
42 | echo "m170916_095928_adding_first_user cannot be reverted.\n";
43 |
44 | return false;
45 | }
46 | */
47 | }
48 |
--------------------------------------------------------------------------------
/console/migrations/m170916_101824_adding_sample_data_to_employee_table.php:
--------------------------------------------------------------------------------
1 | db->createCommand($sql)->execute();
17 |
18 | }
19 |
20 | /**
21 | * @inheritdoc
22 | */
23 | public function safeDown()
24 | {
25 | // echo "m170916_101824_adding_sample_data_to_employee_table cannot be reverted.\n";
26 |
27 | $sql="DELETE from employee where email='john@gmail.com' or email='james@gmail.com' ";
28 | Yii::$app->db->createCommand($sql)->execute();
29 |
30 | // return false;
31 | }
32 |
33 | /*
34 | // Use up()/down() to run migration code without a transaction.
35 | public function up()
36 | {
37 |
38 | }
39 |
40 | public function down()
41 | {
42 | echo "m170916_101824_adding_sample_data_to_employee_table cannot be reverted.\n";
43 |
44 | return false;
45 | }
46 | */
47 | }
48 |
--------------------------------------------------------------------------------
/backend/controllers/RestController.php:
--------------------------------------------------------------------------------
1 | \yii\filters\Cors::className(),
27 | 'cors' => [
28 | 'Origin' => ['*'],
29 | // 'Access-Control-Allow-Origin' => ['*', 'http://haikuwebapp.local.com:81','http://localhost:81'],
30 | 'Access-Control-Request-Method' => ['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'HEAD', 'OPTIONS'],
31 | 'Access-Control-Request-Headers' => ['*'],
32 | 'Access-Control-Allow-Credentials' => null,
33 | 'Access-Control-Max-Age' => 86400,
34 | 'Access-Control-Expose-Headers' => []
35 | ]
36 |
37 | ];
38 | return $behaviors;
39 | }
40 |
41 | public function init()
42 | {
43 | $this->request = json_decode(file_get_contents('php://input'), true);
44 |
45 | if($this->request&&!is_array($this->request)){
46 | Yii::$app->api->sendFailedResponse(['Invalid Json']);
47 |
48 | }
49 |
50 | }
51 |
52 | }
53 |
54 |
55 |
--------------------------------------------------------------------------------
/common/models/AccessTokens.php:
--------------------------------------------------------------------------------
1 | 300],
38 | [['auth_code', 'app_id'], 'string', 'max' => 200],
39 | ];
40 | }
41 |
42 | /**
43 | * @inheritdoc
44 | */
45 | public function attributeLabels()
46 | {
47 | return [
48 | 'id' => 'ID',
49 | 'token' => 'Token',
50 | 'expires_at' => 'Expires At',
51 | 'auth_code' => 'Auth Code',
52 | 'user_id' => 'User ID',
53 | 'app_id' => 'App ID',
54 | 'created_at' => 'Created At',
55 | 'updated_at' => 'Updated At',
56 | ];
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/console/migrations/m170916_100717_adding_employee_table.php:
--------------------------------------------------------------------------------
1 | db->createCommand($sql)->execute();
45 |
46 |
47 | }
48 |
49 | /**
50 | * @inheritdoc
51 | */
52 | public function safeDown()
53 | {
54 | $this->dropTable('{{%employee}}');
55 | }
56 |
57 | /*
58 | // Use up()/down() to run migration code without a transaction.
59 | public function up()
60 | {
61 |
62 | }
63 |
64 | public function down()
65 | {
66 | echo "m170916_100717_adding_employee_table cannot be reverted.\n";
67 |
68 | return false;
69 | }
70 | */
71 | }
72 |
--------------------------------------------------------------------------------
/frontend/views/site/contact.php:
--------------------------------------------------------------------------------
1 | title = 'Contact';
12 | $this->params['breadcrumbs'][] = $this->title;
13 | ?>
14 |
46 |
--------------------------------------------------------------------------------
/frontend/models/ContactForm.php:
--------------------------------------------------------------------------------
1 | 'Verification Code',
42 | ];
43 | }
44 |
45 | /**
46 | * Sends an email to the specified email address using the information collected by this model.
47 | *
48 | * @param string $email the target email address
49 | * @return bool whether the email was sent
50 | */
51 | public function sendEmail($email)
52 | {
53 | return Yii::$app->mailer->compose()
54 | ->setTo($email)
55 | ->setFrom([$this->email => $this->name])
56 | ->setSubject($this->subject)
57 | ->setTextBody($this->body)
58 | ->send();
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/backend/behaviours/Verbcheck.php:
--------------------------------------------------------------------------------
1 | action->id;
24 |
25 |
26 | if (isset($this->actions[$action])) {
27 | $verbs = $this->actions[$action];
28 | } elseif (isset($this->actions['*'])) {
29 | $verbs = $this->actions['*'];
30 | } else {
31 | return $event->isValid;
32 | }
33 |
34 | $verb = Yii::$app->getRequest()->getMethod();
35 | $allowed = array_map('strtoupper', $verbs);
36 | if (!in_array($verb, $allowed)) {
37 | $event->isValid = false;
38 | // http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.7
39 | Yii::$app->getResponse()->getHeaders()->set('Allow', implode(', ', $allowed));
40 |
41 | Yii::$app->api->sendFailedResponse('Method Not Allowed. This url can only handle the following request methods: ' . implode(', ', $allowed) . '.');
42 |
43 | // throw new MethodNotAllowedHttpException('Method Not Allowed. This url can only handle the following request methods: ' . implode(', ', $allowed) . '.');
44 | }
45 |
46 | return $event->isValid;
47 | }
48 |
49 | }
--------------------------------------------------------------------------------
/frontend/models/SignupForm.php:
--------------------------------------------------------------------------------
1 | '\common\models\User', 'message' => 'This username has already been taken.'],
26 | ['username', 'string', 'min' => 2, 'max' => 255],
27 |
28 | ['email', 'trim'],
29 | ['email', 'required'],
30 | ['email', 'email'],
31 | ['email', 'string', 'max' => 255],
32 | ['email', 'unique', 'targetClass' => '\common\models\User', 'message' => 'This email address has already been taken.'],
33 |
34 | ['password', 'required'],
35 | ['password', 'string', 'min' => 6],
36 | ];
37 | }
38 |
39 | /**
40 | * Signs user up.
41 | *
42 | * @return User|null the saved model or null if saving fails
43 | */
44 | public function signup()
45 | {
46 | if (!$this->validate()) {
47 | return null;
48 | }
49 |
50 | $user = new User();
51 | $user->username = $this->username;
52 | $user->email = $this->email;
53 | $user->setPassword($this->password);
54 | $user->generateAuthKey();
55 |
56 | return $user->save() ? $user : null;
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/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/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 bool if password was reset.
55 | */
56 | public function resetPassword()
57 | {
58 | $user = $this->_user;
59 | $user->setPassword($this->password);
60 | $user->removePasswordResetToken();
61 |
62 | return $user->save(false);
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/backend/models/SignupForm.php:
--------------------------------------------------------------------------------
1 | '\common\models\User', 'message' => 'This username has already been taken.'],
28 | ['username', 'string', 'min' => 2, 'max' => 255],
29 |
30 | ['email', 'trim'],
31 | ['email', 'required'],
32 | ['email', 'email'],
33 | ['email', 'string', 'max' => 255],
34 | ['email', 'unique', 'targetClass' => '\common\models\User', 'message' => 'This email address has already been taken.'],
35 |
36 | ['password', 'required'],
37 | ['password', 'string', 'min' => 6],
38 | ];
39 | }
40 |
41 | /**
42 | * Signs user up.
43 | *
44 | * @return User|null the saved model or null if saving fails
45 | */
46 | public function signup()
47 | {
48 |
49 | if (!$this->validate()) {
50 |
51 | Yii::$app->api->sendFailedResponse($this->errors);
52 | //return null;
53 | }
54 |
55 | $user = new User();
56 | $user->username = $this->username;
57 | $user->email = $this->email;
58 | $user->setPassword($this->password);
59 | $user->generateAuthKey();
60 |
61 | return $user->save() ? $user : null;
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/frontend/models/User.php:
--------------------------------------------------------------------------------
1 | 255],
39 | [['auth_key'], 'string', 'max' => 32],
40 | [['username'], 'unique'],
41 | [['email'], 'unique'],
42 | [['password_reset_token'], 'unique'],
43 | ];
44 | }
45 |
46 | /**
47 | * @inheritdoc
48 | */
49 | public function attributeLabels()
50 | {
51 | return [
52 | 'id' => 'ID',
53 | 'username' => 'Username',
54 | 'auth_key' => 'Auth Key',
55 | 'password_hash' => 'Password Hash',
56 | 'password_reset_token' => 'Password Reset Token',
57 | 'email' => 'Email',
58 | 'status' => 'Status',
59 | 'created_at' => 'Created At',
60 | 'updated_at' => 'Updated At',
61 | ];
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/common/models/AuthorizationCodes.php:
--------------------------------------------------------------------------------
1 | 150],
37 | [['app_id'], 'string', 'max' => 200],
38 | ];
39 | }
40 |
41 | /**
42 | * @inheritdoc
43 | */
44 | public function attributeLabels()
45 | {
46 | return [
47 | 'id' => 'ID',
48 | 'code' => 'Code',
49 | 'expires_at' => 'Expires At',
50 | 'user_id' => 'User ID',
51 | 'app_id' => 'App ID',
52 | 'created_at' => 'Created At',
53 | 'updated_at' => 'Updated At',
54 | ];
55 | }
56 | public static function isValid($code)
57 | {
58 | $model=static::findOne(['code' => $code]);
59 |
60 | if(!$model||$model->expires_at