├── .bowerrc
├── .gitignore
├── LICENSE.md
├── README.md
├── Vagrantfile
├── backend
├── config
│ ├── .gitignore
│ ├── bootstrap.php
│ ├── main-local.php
│ ├── main.php
│ ├── params-local.php
│ └── params.php
├── controllers
│ └── SiteController.php
├── models
│ └── .gitkeep
├── views
│ ├── layouts
│ │ └── main.php
│ └── site
│ │ ├── error.php
│ │ ├── index.php
│ │ └── login.php
└── web
│ ├── .gitignore
│ ├── assets
│ ├── .gitignore
│ ├── 21b30ea1
│ │ ├── css
│ │ │ ├── bootstrap-theme.css
│ │ │ ├── bootstrap-theme.css.map
│ │ │ ├── bootstrap-theme.min.css
│ │ │ ├── bootstrap.css
│ │ │ ├── bootstrap.css.map
│ │ │ └── bootstrap.min.css
│ │ ├── fonts
│ │ │ ├── glyphicons-halflings-regular.eot
│ │ │ ├── glyphicons-halflings-regular.svg
│ │ │ ├── glyphicons-halflings-regular.ttf
│ │ │ ├── glyphicons-halflings-regular.woff
│ │ │ └── glyphicons-halflings-regular.woff2
│ │ └── js
│ │ │ ├── bootstrap.js
│ │ │ ├── bootstrap.min.js
│ │ │ └── npm.js
│ ├── 7452e4ca
│ │ ├── jquery.js
│ │ ├── jquery.min.js
│ │ └── jquery.min.map
│ └── 747cfac7
│ │ ├── yii.activeForm.js
│ │ ├── yii.captcha.js
│ │ ├── yii.gridView.js
│ │ ├── yii.js
│ │ └── yii.validation.js
│ ├── css
│ └── site.css
│ ├── favicon.ico
│ ├── index-test.php
│ ├── index.php
│ └── robots.txt
├── common
├── config
│ ├── .gitignore
│ ├── bootstrap.php
│ ├── main-local.php
│ ├── main.php
│ ├── params-local.php
│ └── params.php
├── controllers
│ └── CommonController.php
├── mail
│ ├── layouts
│ │ ├── html.php
│ │ └── text.php
│ ├── passwordResetToken-html.php
│ └── passwordResetToken-text.php
├── models
│ ├── LoginForm.php
│ └── User.php
└── widgets
│ └── Alert.php
├── composer.json
├── composer.lock
├── console
├── config
│ ├── .gitignore
│ ├── bootstrap.php
│ ├── main-local.php
│ ├── main.php
│ ├── params-local.php
│ └── params.php
├── controllers
│ ├── .gitkeep
│ └── SendController.php
├── migrations
│ ├── m130524_2014423_init.php
│ └── m130524_201442_init.php
├── models
│ └── .gitkeep
└── runtime
│ └── .gitignore
├── environments
├── dev
│ ├── backend
│ │ ├── config
│ │ │ ├── main-local.php
│ │ │ └── params-local.php
│ │ └── web
│ │ │ ├── index-test.php
│ │ │ └── index.php
│ ├── common
│ │ └── config
│ │ │ ├── main-local.php
│ │ │ └── params-local.php
│ ├── console
│ │ └── config
│ │ │ ├── main-local.php
│ │ │ └── params-local.php
│ ├── frontend
│ │ ├── config
│ │ │ ├── main-local.php
│ │ │ └── params-local.php
│ │ └── web
│ │ │ ├── index-test.php
│ │ │ └── index.php
│ ├── tests
│ │ └── codeception
│ │ │ └── config
│ │ │ └── config-local.php
│ └── yii
├── index.php
└── prod
│ ├── backend
│ ├── config
│ │ ├── main-local.php
│ │ └── params-local.php
│ └── web
│ │ └── index.php
│ ├── common
│ └── config
│ │ ├── main-local.php
│ │ └── params-local.php
│ ├── console
│ └── config
│ │ ├── main-local.php
│ │ └── params-local.php
│ ├── frontend
│ ├── config
│ │ ├── main-local.php
│ │ └── params-local.php
│ └── web
│ │ └── index.php
│ ├── tests
│ └── codeception
│ │ └── config
│ │ └── config-local.php
│ └── yii
├── frontend
├── assets
│ └── AppAsset.php
├── config
│ ├── .gitignore
│ ├── bootstrap.php
│ ├── main.php
│ └── params.php
├── controllers
│ ├── AppController.php
│ ├── IndexController.php
│ ├── RewardController.php
│ └── SiteController.php
├── models
│ ├── ContactForm.php
│ ├── PasswordResetRequestForm.php
│ ├── ResetPasswordForm.php
│ └── SignupForm.php
├── runtime
│ └── .gitignore
├── views
│ ├── app
│ │ ├── draw.php
│ │ └── jiemeng.php
│ ├── index
│ │ └── answer.php
│ ├── layouts
│ │ └── main.php
│ ├── reward
│ │ └── apply.php
│ └── site
│ │ ├── about.php
│ │ ├── contact.php
│ │ ├── error.php
│ │ ├── index.php
│ │ ├── login.php
│ │ ├── requestPasswordResetToken.php
│ │ ├── resetPassword.php
│ │ └── signup.php
└── web
│ ├── .gitignore
│ ├── assets
│ └── .gitignore
│ ├── css
│ ├── bootstrap-theme.css
│ ├── bootstrap-theme.css.map
│ ├── bootstrap-theme.min.css
│ ├── bootstrap.css
│ ├── bootstrap.css.map
│ ├── bootstrap.min.css
│ └── site.css
│ ├── favicon.ico
│ ├── fonts
│ ├── glyphicons-halflings-regular.eot
│ ├── glyphicons-halflings-regular.svg
│ ├── glyphicons-halflings-regular.ttf
│ └── glyphicons-halflings-regular.woff
│ ├── images
│ ├── chrome-big.jpg
│ ├── chrome-logo-small.jpg
│ ├── chrome-logo.jpg
│ ├── firefox-big.jpg
│ ├── firefox-logo-small.jpg
│ ├── firefox-logo.jpg
│ ├── ie-big.jpg
│ ├── ie-logo.jpg
│ ├── logo.psd
│ ├── opera-big.jpg
│ ├── opera-logo.jpg
│ ├── safari-big.jpg
│ ├── safari-logo-small.jpg
│ └── safari-logo.jpg
│ ├── js
│ ├── bootstrap.js
│ ├── bootstrap.min.js
│ ├── html5shiv.js
│ ├── jquery-1.11.1.js
│ ├── jquery-1.11.1.min.js
│ ├── jquery-1.11.1.min.map
│ └── respond.min.js
│ └── robots.txt
├── init
├── init.bat
├── requirements.php
├── tests
├── README.md
├── codeception.yml
└── codeception
│ ├── _output
│ └── .gitignore
│ ├── backend
│ ├── .gitignore
│ ├── _bootstrap.php
│ ├── _output
│ │ └── .gitignore
│ ├── acceptance.suite.yml
│ ├── acceptance
│ │ ├── LoginCept.php
│ │ └── _bootstrap.php
│ ├── codeception.yml
│ ├── functional.suite.yml
│ ├── functional
│ │ ├── LoginCept.php
│ │ └── _bootstrap.php
│ ├── unit.suite.yml
│ └── unit
│ │ ├── DbTestCase.php
│ │ ├── TestCase.php
│ │ ├── _bootstrap.php
│ │ └── fixtures
│ │ └── data
│ │ └── .gitkeep
│ ├── bin
│ ├── _bootstrap.php
│ ├── yii
│ └── yii.bat
│ ├── common
│ ├── .gitignore
│ ├── _bootstrap.php
│ ├── _output
│ │ └── .gitignore
│ ├── _pages
│ │ └── LoginPage.php
│ ├── _support
│ │ └── FixtureHelper.php
│ ├── codeception.yml
│ ├── fixtures
│ │ ├── UserFixture.php
│ │ └── data
│ │ │ └── init_login.php
│ ├── templates
│ │ └── fixtures
│ │ │ └── user.php
│ ├── unit.suite.yml
│ └── unit
│ │ ├── DbTestCase.php
│ │ ├── TestCase.php
│ │ ├── _bootstrap.php
│ │ ├── fixtures
│ │ └── data
│ │ │ └── models
│ │ │ └── user.php
│ │ └── models
│ │ └── LoginFormTest.php
│ ├── config
│ ├── .gitignore
│ ├── acceptance.php
│ ├── backend
│ │ ├── acceptance.php
│ │ ├── config.php
│ │ ├── functional.php
│ │ └── unit.php
│ ├── common
│ │ └── unit.php
│ ├── config.php
│ ├── console
│ │ └── unit.php
│ ├── frontend
│ │ ├── acceptance.php
│ │ ├── config.php
│ │ ├── functional.php
│ │ └── unit.php
│ ├── functional.php
│ └── unit.php
│ ├── console
│ ├── .gitignore
│ ├── _bootstrap.php
│ ├── _output
│ │ └── .gitignore
│ ├── codeception.yml
│ ├── unit.suite.yml
│ └── unit
│ │ ├── DbTestCase.php
│ │ ├── TestCase.php
│ │ ├── _bootstrap.php
│ │ └── fixtures
│ │ └── data
│ │ └── .gitkeep
│ └── frontend
│ ├── .gitignore
│ ├── _bootstrap.php
│ ├── _output
│ └── .gitignore
│ ├── _pages
│ ├── AboutPage.php
│ ├── ContactPage.php
│ └── SignupPage.php
│ ├── acceptance.suite.yml
│ ├── acceptance
│ ├── AboutCept.php
│ ├── ContactCept.php
│ ├── HomeCept.php
│ ├── LoginCept.php
│ ├── SignupCest.php
│ └── _bootstrap.php
│ ├── codeception.yml
│ ├── functional.suite.yml
│ ├── functional
│ ├── AboutCept.php
│ ├── ContactCept.php
│ ├── HomeCept.php
│ ├── LoginCept.php
│ ├── SignupCest.php
│ └── _bootstrap.php
│ ├── unit.suite.yml
│ └── unit
│ ├── DbTestCase.php
│ ├── TestCase.php
│ ├── _bootstrap.php
│ ├── fixtures
│ └── data
│ │ └── models
│ │ └── user.php
│ └── models
│ ├── ContactFormTest.php
│ ├── PasswordResetRequestFormTest.php
│ ├── ResetPasswordFormTest.php
│ └── SignupFormTest.php
├── vagrant
├── config
│ ├── .gitignore
│ └── vagrant-local.example.yml
├── nginx
│ ├── app.conf
│ └── log
│ │ └── .gitignore
└── provision
│ ├── always-as-root.sh
│ ├── once-as-root.sh
│ └── once-as-vagrant.sh
├── yii
└── yii.bat
/.bowerrc:
--------------------------------------------------------------------------------
1 | {
2 | "directory" : "vendor/bower"
3 | }
4 |
--------------------------------------------------------------------------------
/.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 |
32 | # vagrant runtime
33 | /.vagrant
34 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | Yii 2 Advanced Project Template
2 | ===============================
3 |
4 | Yii 2 Advanced Project Template is a skeleton [Yii 2](http://www.yiiframework.com/) application best for
5 | developing complex Web applications with multiple tiers.
6 |
7 | The template includes three tiers: front end, back end, and console, each of which
8 | is a separate Yii application.
9 |
10 | The template is designed to work in a team development environment. It supports
11 | deploying the application in different environments.
12 |
13 | Documentation is at [docs/guide/README.md](docs/guide/README.md).
14 |
15 | [](https://packagist.org/packages/yiisoft/yii2-app-advanced)
16 | [](https://packagist.org/packages/yiisoft/yii2-app-advanced)
17 | [](https://travis-ci.org/yiisoft/yii2-app-advanced)
18 |
19 | DIRECTORY STRUCTURE
20 | -------------------
21 |
22 | ```
23 | common
24 | config/ contains shared configurations
25 | mail/ contains view files for e-mails
26 | models/ contains model classes used in both backend and frontend
27 | console
28 | config/ contains console configurations
29 | controllers/ contains console controllers (commands)
30 | migrations/ contains database migrations
31 | models/ contains console-specific model classes
32 | runtime/ contains files generated during runtime
33 | backend
34 | assets/ contains application assets such as JavaScript and CSS
35 | config/ contains backend configurations
36 | controllers/ contains Web controller classes
37 | models/ contains backend-specific model classes
38 | runtime/ contains files generated during runtime
39 | views/ contains view files for the Web application
40 | web/ contains the entry script and Web resources
41 | frontend
42 | assets/ contains application assets such as JavaScript and CSS
43 | config/ contains frontend configurations
44 | controllers/ contains Web controller classes
45 | models/ contains frontend-specific model classes
46 | runtime/ contains files generated during runtime
47 | views/ contains view files for the Web application
48 | web/ contains the entry script and Web resources
49 | widgets/ contains frontend widgets
50 | vendor/ contains dependent 3rd-party packages
51 | environments/ contains environment-based overrides
52 | tests contains various tests for the advanced application
53 | codeception/ contains tests developed with Codeception PHP Testing Framework
54 | ```
55 |
56 | 微信公众号初始化指南
57 | ```
58 | 1.创建微信公众号(https://mp.weixin.qq.com/)
59 | 2.在开发->基本配置->填写服务器配置 中配置如下信息
60 | URL: 服务器域名+ /xuechaozhang/weight/frontend/web/index.php?r=index/index
61 | Token:share_time (如果修改的话需要同时修改代码中的这个关键字)
62 | ```
63 |
--------------------------------------------------------------------------------
/Vagrantfile:
--------------------------------------------------------------------------------
1 | require 'yaml'
2 | require 'fileutils'
3 |
4 | domains = {
5 | frontend: 'y2aa-frontend.dev',
6 | backend: 'y2aa-backend.dev'
7 | }
8 |
9 | config = {
10 | local: './vagrant/config/vagrant-local.yml',
11 | example: './vagrant/config/vagrant-local.example.yml'
12 | }
13 |
14 | # copy config from example if local config not exists
15 | FileUtils.cp config[:example], config[:local] unless File.exist?(config[:local])
16 | # read config
17 | options = YAML.load_file config[:local]
18 |
19 | # check github token
20 | if options['github_token'].nil? || options['github_token'].to_s.length != 40
21 | puts "You must place REAL GitHub token into configuration:\n/yii2-app-advancded/vagrant/config/vagrant-local.yml"
22 | exit
23 | end
24 |
25 | # vagrant configurate
26 | Vagrant.configure(2) do |config|
27 | # select the box
28 | config.vm.box = 'ubuntu/trusty64'
29 |
30 | # should we ask about box updates?
31 | config.vm.box_check_update = options['box_check_update']
32 |
33 | config.vm.provider 'virtualbox' do |vb|
34 | # machine cpus count
35 | vb.cpus = options['cpus']
36 | # machine memory size
37 | vb.memory = options['memory']
38 | # machine name (for VirtualBox UI)
39 | vb.name = options['machine_name']
40 | end
41 |
42 | # machine name (for vagrant console)
43 | config.vm.define options['machine_name']
44 |
45 | # machine name (for guest machine console)
46 | config.vm.hostname = options['machine_name']
47 |
48 | # network settings
49 | config.vm.network 'private_network', ip: options['ip']
50 |
51 | # sync: folder 'yii2-app-advanced' (host machine) -> folder '/app' (guest machine)
52 | config.vm.synced_folder './', '/app', owner: 'vagrant', group: 'vagrant'
53 |
54 | # disable folder '/vagrant' (guest machine)
55 | config.vm.synced_folder '.', '/vagrant', disabled: true
56 |
57 | # hosts settings (host machine)
58 | config.vm.provision :hostmanager
59 | config.hostmanager.enabled = true
60 | config.hostmanager.manage_host = true
61 | config.hostmanager.ignore_private_ip = false
62 | config.hostmanager.include_offline = true
63 | config.hostmanager.aliases = domains.values
64 |
65 | # provisioners
66 | config.vm.provision 'shell', path: './vagrant/provision/once-as-root.sh', args: [options['timezone']]
67 | config.vm.provision 'shell', path: './vagrant/provision/once-as-vagrant.sh', args: [options['github_token']], privileged: false
68 | config.vm.provision 'shell', path: './vagrant/provision/always-as-root.sh', run: 'always'
69 |
70 | # post-install message (vagrant console)
71 | config.vm.post_up_message = "Frontend URL: http://#{domains[:frontend]}\nBackend URL: http://#{domains[:backend]}"
72 | end
73 |
--------------------------------------------------------------------------------
/backend/config/.gitignore:
--------------------------------------------------------------------------------
1 | main-local.php
2 | params-local.php
--------------------------------------------------------------------------------
/backend/config/bootstrap.php:
--------------------------------------------------------------------------------
1 | [
5 | 'request' => [
6 | // !!! insert a secret key in the following (if it is empty) - this is required by cookie validation
7 | 'cookieValidationKey' => 'xi-yVdchVmDJ6-wicaMlwG-mTx_2u4e6',
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 |
--------------------------------------------------------------------------------
/backend/config/main.php:
--------------------------------------------------------------------------------
1 | 'app-backend',
11 | 'basePath' => dirname(__DIR__),
12 | 'controllerNamespace' => 'backend\controllers',
13 | 'bootstrap' => ['log'],
14 | 'modules' => [],
15 | 'components' => [
16 | 'request' => [
17 | 'csrfParam' => '_csrf-backend',
18 | ],
19 | 'user' => [
20 | 'identityClass' => 'common\models\User',
21 | 'enableAutoLogin' => true,
22 | 'identityCookie' => ['name' => '_identity-backend', 'httpOnly' => true],
23 | ],
24 | 'session' => [
25 | // this is the name of the session cookie used for login on the backend
26 | 'name' => 'advanced-backend',
27 | ],
28 | 'log' => [
29 | 'traceLevel' => YII_DEBUG ? 3 : 0,
30 | 'targets' => [
31 | [
32 | 'class' => 'yii\log\FileTarget',
33 | 'levels' => ['error', 'warning'],
34 | ],
35 | ],
36 | ],
37 | 'errorHandler' => [
38 | 'errorAction' => 'site/error',
39 | ],
40 | /*
41 | 'urlManager' => [
42 | 'enablePrettyUrl' => true,
43 | 'showScriptName' => false,
44 | 'rules' => [
45 | ],
46 | ],
47 | */
48 | ],
49 | 'params' => $params,
50 | ];
51 |
--------------------------------------------------------------------------------
/backend/config/params-local.php:
--------------------------------------------------------------------------------
1 | 'admin@example.com',
4 | ];
5 |
--------------------------------------------------------------------------------
/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 | /**
57 | * Displays homepage.
58 | *
59 | * @return string
60 | */
61 | public function actionIndex()
62 | {
63 | return $this->render('index');
64 | }
65 |
66 | /**
67 | * Login action.
68 | *
69 | * @return string
70 | */
71 | public function actionLogin()
72 | {
73 | if (!Yii::$app->user->isGuest) {
74 | return $this->goHome();
75 | }
76 |
77 | $model = new LoginForm();
78 | if ($model->load(Yii::$app->request->post()) && $model->login()) {
79 | return $this->goBack();
80 | } else {
81 | return $this->render('login', [
82 | 'model' => $model,
83 | ]);
84 | }
85 | }
86 |
87 | /**
88 | * Logout action.
89 | *
90 | * @return string
91 | */
92 | public function actionLogout()
93 | {
94 | Yii::$app->user->logout();
95 |
96 | return $this->goHome();
97 | }
98 | }
99 |
--------------------------------------------------------------------------------
/backend/models/.gitkeep:
--------------------------------------------------------------------------------
1 | *
2 |
--------------------------------------------------------------------------------
/backend/views/layouts/main.php:
--------------------------------------------------------------------------------
1 |
15 | beginPage() ?>
16 |
17 |
18 |
19 |
20 |
21 | = Html::csrfMetaTags() ?>
22 | = Html::encode($this->title) ?>
23 | head() ?>
24 |
25 |
26 | beginBody() ?>
27 |
28 |
29 | 'My Company',
32 | 'brandUrl' => Yii::$app->homeUrl,
33 | 'options' => [
34 | 'class' => 'navbar-inverse navbar-fixed-top',
35 | ],
36 | ]);
37 | $menuItems = [
38 | ['label' => 'Home', 'url' => ['/site/index']],
39 | ];
40 | if (Yii::$app->user->isGuest) {
41 | $menuItems[] = ['label' => 'Login', 'url' => ['/site/login']];
42 | } else {
43 | $menuItems[] = '
'
44 | . Html::beginForm(['/site/logout'], 'post')
45 | . Html::submitButton(
46 | 'Logout (' . Yii::$app->user->identity->username . ')',
47 | ['class' => 'btn btn-link']
48 | )
49 | . Html::endForm()
50 | . '';
51 | }
52 | echo Nav::widget([
53 | 'options' => ['class' => 'navbar-nav navbar-right'],
54 | 'items' => $menuItems,
55 | ]);
56 | NavBar::end();
57 | ?>
58 |
59 |
60 | = Breadcrumbs::widget([
61 | 'links' => isset($this->params['breadcrumbs']) ? $this->params['breadcrumbs'] : [],
62 | ]) ?>
63 | = Alert::widget() ?>
64 | = $content ?>
65 |
66 |
67 |
68 |
75 |
76 | endBody() ?>
77 |
78 |
79 | endPage() ?>
80 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/backend/views/site/index.php:
--------------------------------------------------------------------------------
1 | title = 'My Yii Application';
6 | ?>
7 |
8 |
9 |
10 |
Congratulations!
11 |
12 |
You have successfully created your Yii-powered application.
13 |
14 |
Get started with Yii
15 |
16 |
17 |
18 |
19 |
20 |
21 |
Heading
22 |
23 |
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et
24 | dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip
25 | ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu
26 | fugiat nulla pariatur.
27 |
28 |
Yii Documentation »
29 |
30 |
31 |
Heading
32 |
33 |
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et
34 | dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip
35 | ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu
36 | fugiat nulla pariatur.
37 |
38 |
Yii Forum »
39 |
40 |
41 |
Heading
42 |
43 |
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et
44 | dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip
45 | ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu
46 | fugiat nulla pariatur.
47 |
48 |
Yii Extensions »
49 |
50 |
51 |
52 |
53 |
54 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/backend/web/.gitignore:
--------------------------------------------------------------------------------
1 | /index.php
2 | /index-test.php
3 |
--------------------------------------------------------------------------------
/backend/web/assets/.gitignore:
--------------------------------------------------------------------------------
1 | *
2 | !.gitignore
3 |
--------------------------------------------------------------------------------
/backend/web/assets/21b30ea1/fonts/glyphicons-halflings-regular.eot:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ChaozhangXue/weiYii2/cbd6cd0dcdc9c2ff36ed5b82988063218616384b/backend/web/assets/21b30ea1/fonts/glyphicons-halflings-regular.eot
--------------------------------------------------------------------------------
/backend/web/assets/21b30ea1/fonts/glyphicons-halflings-regular.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ChaozhangXue/weiYii2/cbd6cd0dcdc9c2ff36ed5b82988063218616384b/backend/web/assets/21b30ea1/fonts/glyphicons-halflings-regular.ttf
--------------------------------------------------------------------------------
/backend/web/assets/21b30ea1/fonts/glyphicons-halflings-regular.woff:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ChaozhangXue/weiYii2/cbd6cd0dcdc9c2ff36ed5b82988063218616384b/backend/web/assets/21b30ea1/fonts/glyphicons-halflings-regular.woff
--------------------------------------------------------------------------------
/backend/web/assets/21b30ea1/fonts/glyphicons-halflings-regular.woff2:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ChaozhangXue/weiYii2/cbd6cd0dcdc9c2ff36ed5b82988063218616384b/backend/web/assets/21b30ea1/fonts/glyphicons-halflings-regular.woff2
--------------------------------------------------------------------------------
/backend/web/assets/21b30ea1/js/npm.js:
--------------------------------------------------------------------------------
1 | // This file is autogenerated via the `commonjs` Grunt task. You can require() this file in a CommonJS environment.
2 | require('../../js/transition.js')
3 | require('../../js/alert.js')
4 | require('../../js/button.js')
5 | require('../../js/carousel.js')
6 | require('../../js/collapse.js')
7 | require('../../js/dropdown.js')
8 | require('../../js/modal.js')
9 | require('../../js/tooltip.js')
10 | require('../../js/popover.js')
11 | require('../../js/scrollspy.js')
12 | require('../../js/tab.js')
13 | require('../../js/affix.js')
--------------------------------------------------------------------------------
/backend/web/assets/747cfac7/yii.captcha.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Yii Captcha widget.
3 | *
4 | * This is the JavaScript widget used by the yii\captcha\Captcha widget.
5 | *
6 | * @link http://www.yiiframework.com/
7 | * @copyright Copyright (c) 2008 Yii Software LLC
8 | * @license http://www.yiiframework.com/license/
9 | * @author Qiang Xue
10 | * @since 2.0
11 | */
12 | (function ($) {
13 | $.fn.yiiCaptcha = function (method) {
14 | if (methods[method]) {
15 | return methods[method].apply(this, Array.prototype.slice.call(arguments, 1));
16 | } else if (typeof method === 'object' || !method) {
17 | return methods.init.apply(this, arguments);
18 | } else {
19 | $.error('Method ' + method + ' does not exist on jQuery.yiiCaptcha');
20 | return false;
21 | }
22 | };
23 |
24 | var defaults = {
25 | refreshUrl: undefined,
26 | hashKey: undefined
27 | };
28 |
29 | var methods = {
30 | init: function (options) {
31 | return this.each(function () {
32 | var $e = $(this);
33 | var settings = $.extend({}, defaults, options || {});
34 | $e.data('yiiCaptcha', {
35 | settings: settings
36 | });
37 |
38 | $e.on('click.yiiCaptcha', function () {
39 | methods.refresh.apply($e);
40 | return false;
41 | });
42 |
43 | });
44 | },
45 |
46 | refresh: function () {
47 | var $e = this,
48 | settings = this.data('yiiCaptcha').settings;
49 | $.ajax({
50 | url: $e.data('yiiCaptcha').settings.refreshUrl,
51 | dataType: 'json',
52 | cache: false,
53 | success: function (data) {
54 | $e.attr('src', data.url);
55 | $('body').data(settings.hashKey, [data.hash1, data.hash2]);
56 | }
57 | });
58 | },
59 |
60 | destroy: function () {
61 | return this.each(function () {
62 | $(window).unbind('.yiiCaptcha');
63 | $(this).removeData('yiiCaptcha');
64 | });
65 | },
66 |
67 | data: function () {
68 | return this.data('yiiCaptcha');
69 | }
70 | };
71 | })(window.jQuery);
72 |
73 |
--------------------------------------------------------------------------------
/backend/web/css/site.css:
--------------------------------------------------------------------------------
1 | html,
2 | body {
3 | height: 100%;
4 | }
5 |
6 | .wrap {
7 | min-height: 100%;
8 | height: auto;
9 | margin: 0 auto -60px;
10 | padding: 0 0 60px;
11 | }
12 |
13 | .wrap > .container {
14 | padding: 70px 15px 20px;
15 | }
16 |
17 | .footer {
18 | height: 60px;
19 | background-color: #f5f5f5;
20 | border-top: 1px solid #ddd;
21 | padding-top: 20px;
22 | }
23 |
24 | .jumbotron {
25 | text-align: center;
26 | background-color: transparent;
27 | }
28 |
29 | .jumbotron .btn {
30 | font-size: 21px;
31 | padding: 14px 24px;
32 | }
33 |
34 | .not-set {
35 | color: #c55;
36 | font-style: italic;
37 | }
38 |
39 | /* add sorting icons to gridview sort links */
40 | a.asc:after, a.desc:after {
41 | position: relative;
42 | top: 1px;
43 | display: inline-block;
44 | font-family: 'Glyphicons Halflings';
45 | font-style: normal;
46 | font-weight: normal;
47 | line-height: 1;
48 | padding-left: 5px;
49 | }
50 |
51 | a.asc:after {
52 | content: /*"\e113"*/ "\e151";
53 | }
54 |
55 | a.desc:after {
56 | content: /*"\e114"*/ "\e152";
57 | }
58 |
59 | .sort-numerical a.asc:after {
60 | content: "\e153";
61 | }
62 |
63 | .sort-numerical a.desc:after {
64 | content: "\e154";
65 | }
66 |
67 | .sort-ordinal a.asc:after {
68 | content: "\e155";
69 | }
70 |
71 | .sort-ordinal a.desc:after {
72 | content: "\e156";
73 | }
74 |
75 | .grid-view td {
76 | white-space: nowrap;
77 | }
78 |
79 | .grid-view .filters input,
80 | .grid-view .filters select {
81 | min-width: 50px;
82 | }
83 |
84 | .hint-block {
85 | display: block;
86 | margin-top: 5px;
87 | color: #999;
88 | }
89 |
90 | .error-summary {
91 | color: #a94442;
92 | background: #fdf7f7;
93 | border-left: 3px solid #eed3d7;
94 | padding: 10px 20px;
95 | margin: 0 0 15px 0;
96 | }
97 |
98 | /* align the logout "link" (button in form) of the navbar */
99 | .nav > li > form {
100 | padding: 8px;
101 | }
102 |
103 | @media(max-width:768px) {
104 | .nav li > form {
105 | padding: 3px;
106 | }
107 | }
108 |
109 | .nav > li > form > button:hover {
110 | text-decoration: none;
111 | }
112 |
--------------------------------------------------------------------------------
/backend/web/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ChaozhangXue/weiYii2/cbd6cd0dcdc9c2ff36ed5b82988063218616384b/backend/web/favicon.ico
--------------------------------------------------------------------------------
/backend/web/index-test.php:
--------------------------------------------------------------------------------
1 | run();
20 |
--------------------------------------------------------------------------------
/backend/web/index.php:
--------------------------------------------------------------------------------
1 | run();
19 |
--------------------------------------------------------------------------------
/backend/web/robots.txt:
--------------------------------------------------------------------------------
1 | User-agent: *
2 | Disallow: /
3 |
--------------------------------------------------------------------------------
/common/config/.gitignore:
--------------------------------------------------------------------------------
1 | main-local.php
2 | params-local.php
3 |
--------------------------------------------------------------------------------
/common/config/bootstrap.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 |
--------------------------------------------------------------------------------
/common/config/main.php:
--------------------------------------------------------------------------------
1 | dirname(dirname(__DIR__)) . '/vendor',
4 | 'components' => [
5 | 'cache' => [
6 | 'class' => 'yii\caching\FileCache',
7 | ],
8 | 'redis' => [
9 | 'class' => 'yii\redis\Connection',
10 | 'hostname' => 'localhost',
11 | 'port' => 6379,
12 | ],
13 | ],
14 | ];
15 |
--------------------------------------------------------------------------------
/common/config/params-local.php:
--------------------------------------------------------------------------------
1 | 'admin@example.com',
4 | 'supportEmail' => 'support@example.com',
5 | 'user.passwordResetTokenExpire' => 3600,
6 | 'appid' => 'wxa2789f8465121198',
7 | 'appSecret' => 'f406cbbd1ff279785dbaa25147233a4a',
8 | 'baiduApiKey' => '206cb2f2c98119ded7dcba4a10b396e5',
9 | 'redirectUri' => 'http://121.201.108.221',
10 | 'zhaoOpenId' => 'oZUvEw9RDnw2z9qeBnqKw4BFg-yY',
11 | 'xueOpenId' => 'oZUvEw_SiWiifl0PHGme7STl_q7I',
12 | ];
13 |
--------------------------------------------------------------------------------
/common/controllers/CommonController.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/mail/layouts/text.php:
--------------------------------------------------------------------------------
1 |
8 | beginPage() ?>
9 | beginBody() ?>
10 | = $content ?>
11 | endBody() ?>
12 | endPage() ?>
13 |
--------------------------------------------------------------------------------
/common/mail/passwordResetToken-html.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 |
16 |
--------------------------------------------------------------------------------
/common/mail/passwordResetToken-text.php:
--------------------------------------------------------------------------------
1 | urlManager->createAbsoluteUrl(['site/reset-password', 'token' => $user->password_reset_token]);
7 | ?>
8 | Hello = $user->username ?>,
9 |
10 | Follow the link below to reset your password:
11 |
12 | = $resetLink ?>
13 |
--------------------------------------------------------------------------------
/common/models/LoginForm.php:
--------------------------------------------------------------------------------
1 | hasErrors()) {
44 | $user = $this->getUser();
45 | if (!$user || !$user->validatePassword($this->password)) {
46 | $this->addError($attribute, 'Incorrect username or password.');
47 | }
48 | }
49 | }
50 |
51 | /**
52 | * Logs in a user using the provided username and password.
53 | *
54 | * @return boolean whether the user is logged in successfully
55 | */
56 | public function login()
57 | {
58 | if ($this->validate()) {
59 | return Yii::$app->user->login($this->getUser(), $this->rememberMe ? 3600 * 24 * 30 : 0);
60 | } else {
61 | return false;
62 | }
63 | }
64 |
65 | /**
66 | * Finds user by [[username]]
67 | *
68 | * @return User|null
69 | */
70 | protected function getUser()
71 | {
72 | if ($this->_user === null) {
73 | $this->_user = User::findByUsername($this->username);
74 | }
75 |
76 | return $this->_user;
77 | }
78 | }
79 |
--------------------------------------------------------------------------------
/common/models/User.php:
--------------------------------------------------------------------------------
1 | self::STATUS_ACTIVE],
55 | ['status', 'in', 'range' => [self::STATUS_ACTIVE, self::STATUS_DELETED]],
56 | ];
57 | }
58 |
59 | /**
60 | * @inheritdoc
61 | */
62 | public static function findIdentity($id)
63 | {
64 | return static::findOne(['id' => $id, 'status' => self::STATUS_ACTIVE]);
65 | }
66 |
67 | /**
68 | * @inheritdoc
69 | */
70 | public static function findIdentityByAccessToken($token, $type = null)
71 | {
72 | throw new NotSupportedException('"findIdentityByAccessToken" is not implemented.');
73 | }
74 |
75 | /**
76 | * Finds user by username
77 | *
78 | * @param string $username
79 | * @return static|null
80 | */
81 | public static function findByUsername($username)
82 | {
83 | return static::findOne(['username' => $username, 'status' => self::STATUS_ACTIVE]);
84 | }
85 |
86 | /**
87 | * Finds user by password reset token
88 | *
89 | * @param string $token password reset token
90 | * @return static|null
91 | */
92 | public static function findByPasswordResetToken($token)
93 | {
94 | if (!static::isPasswordResetTokenValid($token)) {
95 | return null;
96 | }
97 |
98 | return static::findOne([
99 | 'password_reset_token' => $token,
100 | 'status' => self::STATUS_ACTIVE,
101 | ]);
102 | }
103 |
104 | /**
105 | * Finds out if password reset token is valid
106 | *
107 | * @param string $token password reset token
108 | * @return boolean
109 | */
110 | public static function isPasswordResetTokenValid($token)
111 | {
112 | if (empty($token)) {
113 | return false;
114 | }
115 |
116 | $timestamp = (int) substr($token, strrpos($token, '_') + 1);
117 | $expire = Yii::$app->params['user.passwordResetTokenExpire'];
118 | return $timestamp + $expire >= time();
119 | }
120 |
121 | /**
122 | * @inheritdoc
123 | */
124 | public function getId()
125 | {
126 | return $this->getPrimaryKey();
127 | }
128 |
129 | /**
130 | * @inheritdoc
131 | */
132 | public function getAuthKey()
133 | {
134 | return $this->auth_key;
135 | }
136 |
137 | /**
138 | * @inheritdoc
139 | */
140 | public function validateAuthKey($authKey)
141 | {
142 | return $this->getAuthKey() === $authKey;
143 | }
144 |
145 | /**
146 | * Validates password
147 | *
148 | * @param string $password password to validate
149 | * @return boolean if password provided is valid for current user
150 | */
151 | public function validatePassword($password)
152 | {
153 | return Yii::$app->security->validatePassword($password, $this->password_hash);
154 | }
155 |
156 | /**
157 | * Generates password hash from password and sets it to the model
158 | *
159 | * @param string $password
160 | */
161 | public function setPassword($password)
162 | {
163 | $this->password_hash = Yii::$app->security->generatePasswordHash($password);
164 | }
165 |
166 | /**
167 | * Generates "remember me" authentication key
168 | */
169 | public function generateAuthKey()
170 | {
171 | $this->auth_key = Yii::$app->security->generateRandomString();
172 | }
173 |
174 | /**
175 | * Generates new password reset token
176 | */
177 | public function generatePasswordResetToken()
178 | {
179 | $this->password_reset_token = Yii::$app->security->generateRandomString() . '_' . time();
180 | }
181 |
182 | /**
183 | * Removes password reset token
184 | */
185 | public function removePasswordResetToken()
186 | {
187 | $this->password_reset_token = null;
188 | }
189 | }
190 |
--------------------------------------------------------------------------------
/common/widgets/Alert.php:
--------------------------------------------------------------------------------
1 | session->setFlash('error', 'This is the message');
18 | * Yii::$app->session->setFlash('success', 'This is the message');
19 | * Yii::$app->session->setFlash('info', 'This is the message');
20 | * ```
21 | *
22 | * Multiple messages could be set as follows:
23 | *
24 | * ```php
25 | * Yii::$app->session->setFlash('error', ['Error 1', 'Error 2']);
26 | * ```
27 | *
28 | * @author Kartik Visweswaran
29 | * @author Alexander Makarov
30 | */
31 | class Alert extends \yii\bootstrap\Widget
32 | {
33 | /**
34 | * @var array the alert types configuration for the flash messages.
35 | * This array is setup as $key => $value, where:
36 | * - $key is the name of the session flash variable
37 | * - $value is the bootstrap alert type (i.e. danger, success, info, warning)
38 | */
39 | public $alertTypes = [
40 | 'error' => 'alert-danger',
41 | 'danger' => 'alert-danger',
42 | 'success' => 'alert-success',
43 | 'info' => 'alert-info',
44 | 'warning' => 'alert-warning'
45 | ];
46 | /**
47 | * @var array the options for rendering the close button tag.
48 | */
49 | public $closeButton = [];
50 |
51 |
52 | public function init()
53 | {
54 | parent::init();
55 |
56 | $session = Yii::$app->session;
57 | $flashes = $session->getAllFlashes();
58 | $appendCss = isset($this->options['class']) ? ' ' . $this->options['class'] : '';
59 |
60 | foreach ($flashes as $type => $data) {
61 | if (isset($this->alertTypes[$type])) {
62 | $data = (array) $data;
63 | foreach ($data as $i => $message) {
64 | /* initialize css class for each alert box */
65 | $this->options['class'] = $this->alertTypes[$type] . $appendCss;
66 |
67 | /* assign unique id to each alert box */
68 | $this->options['id'] = $this->getId() . '-' . $type . '-' . $i;
69 |
70 | echo \yii\bootstrap\Alert::widget([
71 | 'body' => $message,
72 | 'closeButton' => $this->closeButton,
73 | 'options' => $this->options,
74 | ]);
75 | }
76 |
77 | $session->removeFlash($type);
78 | }
79 | }
80 | }
81 | }
82 |
--------------------------------------------------------------------------------
/composer.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "yiisoft/yii2-app-advanced",
3 | "description": "Yii 2 Advanced Project Template",
4 | "keywords": ["yii2", "framework", "advanced", "project template"],
5 | "homepage": "http://www.yiiframework.com/",
6 | "type": "project",
7 | "license": "BSD-3-Clause",
8 | "support": {
9 | "issues": "https://github.com/yiisoft/yii2/issues?state=open",
10 | "forum": "http://www.yiiframework.com/forum/",
11 | "wiki": "http://www.yiiframework.com/wiki/",
12 | "irc": "irc://irc.freenode.net/yii",
13 | "source": "https://github.com/yiisoft/yii2"
14 | },
15 | "minimum-stability": "stable",
16 | "require": {
17 | "php": ">=5.4.0",
18 | "yiisoft/yii2": ">=2.0.6",
19 | "yiisoft/yii2-bootstrap": "*",
20 | "yiisoft/yii2-swiftmailer": "*"
21 | },
22 | "require-dev": {
23 | "yiisoft/yii2-codeception": "*",
24 | "yiisoft/yii2-debug": "*",
25 | "yiisoft/yii2-gii": "*",
26 | "yiisoft/yii2-faker": "*"
27 | },
28 | "config": {
29 | "process-timeout": 1800
30 | },
31 | "extra": {
32 | "asset-installer-paths": {
33 | "npm-asset-library": "vendor/npm",
34 | "bower-asset-library": "vendor/bower"
35 | }
36 | },
37 | "scripts": {
38 | "post-install-cmd": "php init --env=Development --overwrite=n"
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/console/config/.gitignore:
--------------------------------------------------------------------------------
1 | main-local.php
2 | params-local.php
--------------------------------------------------------------------------------
/console/config/bootstrap.php:
--------------------------------------------------------------------------------
1 | ['gii'],
4 | 'modules' => [
5 | 'gii' => 'yii\gii\Module',
6 | ],
7 | ];
8 |
--------------------------------------------------------------------------------
/console/config/main.php:
--------------------------------------------------------------------------------
1 | 'app-console',
11 | 'basePath' => dirname(__DIR__),
12 | 'bootstrap' => ['log'],
13 | 'controllerNamespace' => 'console\controllers',
14 | 'components' => [
15 | 'log' => [
16 | 'targets' => [
17 | [
18 | 'class' => 'yii\log\FileTarget',
19 | 'levels' => ['error', 'warning'],
20 | ],
21 | ],
22 | ],
23 | ],
24 | 'params' => $params,
25 | ];
26 |
--------------------------------------------------------------------------------
/console/config/params-local.php:
--------------------------------------------------------------------------------
1 | 'admin@example.com',
4 | ];
5 |
--------------------------------------------------------------------------------
/console/controllers/.gitkeep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ChaozhangXue/weiYii2/cbd6cd0dcdc9c2ff36ed5b82988063218616384b/console/controllers/.gitkeep
--------------------------------------------------------------------------------
/console/controllers/SendController.php:
--------------------------------------------------------------------------------
1 | actionGetWeather();
20 | $weather_report = $weather['HeWeather data service 3.0']['0']['daily_forecast']['0']['cond']['txt_d'] . "转" . $weather['HeWeather data service 3.0']['0']['daily_forecast']['0']['cond']['txt_n'];
21 |
22 | if (stripos($weather_report, '雨') !== false) {
23 | $place = $weather['HeWeather data service 3.0']['0']['basic']['city'];
24 | $date = $weather['HeWeather data service 3.0']['0']['daily_forecast']['0']['date'];
25 | $weather = "天气:" . $weather['HeWeather data service 3.0']['0']['daily_forecast']['0']['cond']['txt_d'] . "转"
26 | . $weather['HeWeather data service 3.0']['0']['daily_forecast']['0']['cond']['txt_n'] . "\n"
27 | . "温度" . $weather['HeWeather data service 3.0']['0']['daily_forecast']['0']['tmp']['min'] . "-" . $weather['HeWeather data service 3.0']['0']['daily_forecast']['0']['tmp']['max'];
28 |
29 | //1.获取到access token
30 | $access_token = $this->getAccessToken();
31 | // 2.组装数组
32 | $url = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token={$access_token}";
33 | // 3.将数组成json
34 | $ids = [Yii::$app->params['zhaoOpenId'],Yii::$app->params['xueOpenId']];
35 | foreach($ids as $id){
36 | $content = [
37 | 'touser' => $id,
38 | 'template_id' => 'LLkHbz2I2HyEdfCyD08O9tad8Jvzb_eHgPtQlNkK02Q',
39 | 'url' => 'http://www.weather.com.cn/weather/101210106.shtml',
40 | 'data' => [
41 | 'place' => [
42 | 'value' => $place,
43 | 'color' => '#173177',
44 | ],
45 | 'date' => [
46 | 'value' => $date,
47 | 'color' => '#173177',
48 | ],
49 | 'weather' => [
50 | 'value' => $weather,
51 | 'color' => '#173177',
52 | ],
53 | ],
54 | ];
55 | $content = json_encode($content);
56 | $this->http_curl($url, 'post', 'json', $content);
57 | }
58 | } else {
59 | return;
60 | }
61 | }
62 | /*
63 | * 获取天气
64 | * 需要手动执行 http://121.201.108.221/xuechaozhang/weight/frontend/web/index.php?r=index/get-weather
65 | */
66 | public function actionGetWeather(){
67 | $ch = curl_init();
68 | $url = 'http://apis.baidu.com/heweather/weather/free?city=hangzhou';
69 | $header = array(
70 | 'apikey: ' . Yii::$app->params['baiduApiKey'],
71 | );
72 | // 添加apikey到header
73 | curl_setopt($ch, CURLOPT_HTTPHEADER , $header);
74 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
75 | // 执行HTTP请求
76 | curl_setopt($ch , CURLOPT_URL , $url);
77 | $res = curl_exec($ch);
78 | $res = json_decode($res,true);
79 | return $res;
80 | }
81 |
82 | public function http_curl($url, $type='get',$res='json',$arr='')
83 | {
84 | //获取imooc
85 | //1.初始化curl
86 | $ch = curl_init();
87 | //2.设置curl的参数
88 | curl_setopt($ch, CURLOPT_URL, $url);
89 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
90 |
91 | if($type == 'post'){
92 | curl_setopt($ch, CURLOPT_POST, 1);
93 | curl_setopt($ch, CURLOPT_POSTFIELDS, $arr);
94 | }
95 |
96 | //3.采集
97 | $output = curl_exec($ch);
98 | //4.关闭
99 | curl_close($ch);
100 |
101 | if($res == 'json'){
102 | return json_decode($output,true);
103 | }
104 | }
105 |
106 | /*
107 | * 三点钟招行提醒
108 | * 需要手动执行 http://121.201.108.221/xuechaozhang/weight/frontend/web/index.php?r=index/send-template-msg
109 | */
110 | public function actionAlert()
111 | {
112 | //1.获取到access token
113 | $access_token = $this->getAccessToken();
114 | // 2.组装数组
115 | $url = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token={$access_token}";
116 | // 3.将数组成json
117 | $id = Yii::$app->params['zhaoOpenId'];
118 | // $ids = [Yii::$app->params['zhaoOpenId'],Yii::$app->params['xueOpenId']];
119 | // foreach($ids as $id){
120 | $content = [
121 | 'touser' => $id,
122 | 'template_id' => 'hylKxS6wuktvJKqjL1MgM30vhtWxEl7f7rduJBS7G0w',
123 | 'url' => '',
124 | ];
125 | $content = json_encode($content);
126 | $this->http_curl($url, 'post', 'json', $content);
127 | // }
128 | }
129 | /*
130 | * 获取微信access token
131 | */
132 | public function getAccessToken()
133 | {
134 | if(isset($_SESSION['access_token']) && $_SESSION['expire_time'] > time()){
135 | return $_SESSION['access_token'];
136 | }else{
137 | //1.请求url地址
138 | $appid = Yii::$app->params['appid'];
139 | $appsecret = Yii::$app->params['appSecret'];
140 | $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=" . $appid . "&secret=" . $appsecret;
141 | //2初始化
142 | $ch = curl_init();
143 | //3.设置参数
144 | curl_setopt($ch, CURLOPT_URL, $url);
145 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
146 | //4.调用接口
147 | $res = curl_exec($ch);
148 | //5.关闭curl
149 | curl_close($ch);
150 | // if (curl_errno($ch)) {
151 | // var_dump(curl_error($ch));
152 | // }
153 | $arr = json_decode($res, true);
154 | $access_token = $arr['access_token'];
155 |
156 | //存入session
157 | $_SESSION['access_token'] = $access_token;
158 | $_SESSION['expire_time'] = time() + 7200;
159 |
160 | return $arr['access_token'];
161 | }
162 |
163 | }
164 | }
--------------------------------------------------------------------------------
/console/migrations/m130524_2014423_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 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/console/models/.gitkeep:
--------------------------------------------------------------------------------
1 | *
2 |
--------------------------------------------------------------------------------
/console/runtime/.gitignore:
--------------------------------------------------------------------------------
1 | *
2 | !.gitignore
--------------------------------------------------------------------------------
/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/backend/config/params-local.php:
--------------------------------------------------------------------------------
1 | run();
20 |
--------------------------------------------------------------------------------
/environments/dev/backend/web/index.php:
--------------------------------------------------------------------------------
1 | run();
19 |
--------------------------------------------------------------------------------
/environments/dev/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 | // 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 |
--------------------------------------------------------------------------------
/environments/dev/common/config/params-local.php:
--------------------------------------------------------------------------------
1 | ['gii'],
4 | 'modules' => [
5 | 'gii' => 'yii\gii\Module',
6 | ],
7 | ];
8 |
--------------------------------------------------------------------------------
/environments/dev/console/config/params-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 | $config['bootstrap'][] = 'gii';
19 | $config['modules']['gii'] = [
20 | 'class' => 'yii\gii\Module',
21 | ];
22 | }
23 |
24 | return $config;
25 |
--------------------------------------------------------------------------------
/environments/dev/frontend/config/params-local.php:
--------------------------------------------------------------------------------
1 | run();
19 |
--------------------------------------------------------------------------------
/environments/dev/frontend/web/index.php:
--------------------------------------------------------------------------------
1 | run();
19 |
--------------------------------------------------------------------------------
/environments/dev/tests/codeception/config/config-local.php:
--------------------------------------------------------------------------------
1 | [
4 | 'db' => [
5 | 'dsn' => 'mysql:host=localhost;dbname=yii2_advanced_tests',
6 | 'username' => 'root',
7 | 'password' => '',
8 | 'charset' => 'utf8',
9 | ],
10 | ],
11 | ];
12 |
--------------------------------------------------------------------------------
/environments/dev/yii:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env php
2 | run();
28 | exit($exitCode);
29 |
--------------------------------------------------------------------------------
/environments/index.php:
--------------------------------------------------------------------------------
1 | [
11 | * 'path' => 'directory storing the local files',
12 | * 'skipFiles' => [
13 | * // list of files that should only copied once and skipped if they already exist
14 | * ],
15 | * 'setWritable' => [
16 | * // list of directories that should be set writable
17 | * ],
18 | * 'setExecutable' => [
19 | * // list of files that should be set executable
20 | * ],
21 | * 'setCookieValidationKey' => [
22 | * // list of config files that need to be inserted with automatically generated cookie validation keys
23 | * ],
24 | * 'createSymlink' => [
25 | * // list of symlinks to be created. Keys are symlinks, and values are the targets.
26 | * ],
27 | * ],
28 | * ];
29 | * ```
30 | */
31 | return [
32 | 'Development' => [
33 | 'path' => 'dev',
34 | 'setWritable' => [
35 | 'backend/runtime',
36 | 'backend/web/assets',
37 | 'frontend/runtime',
38 | 'frontend/web/assets',
39 | ],
40 | 'setExecutable' => [
41 | 'yii',
42 | 'tests/codeception/bin/yii',
43 | ],
44 | 'setCookieValidationKey' => [
45 | 'backend/config/main-local.php',
46 | 'frontend/config/main-local.php',
47 | ],
48 | ],
49 | 'Production' => [
50 | 'path' => 'prod',
51 | 'setWritable' => [
52 | 'backend/runtime',
53 | 'backend/web/assets',
54 | 'frontend/runtime',
55 | 'frontend/web/assets',
56 | ],
57 | 'setExecutable' => [
58 | 'yii',
59 | ],
60 | 'setCookieValidationKey' => [
61 | 'backend/config/main-local.php',
62 | 'frontend/config/main-local.php',
63 | ],
64 | ],
65 | ];
66 |
--------------------------------------------------------------------------------
/environments/prod/backend/config/main-local.php:
--------------------------------------------------------------------------------
1 | [
4 | 'request' => [
5 | // !!! insert a secret key in the following (if it is empty) - this is required by cookie validation
6 | 'cookieValidationKey' => '',
7 | ],
8 | ],
9 | ];
10 |
--------------------------------------------------------------------------------
/environments/prod/backend/config/params-local.php:
--------------------------------------------------------------------------------
1 | run();
19 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/environments/prod/common/config/params-local.php:
--------------------------------------------------------------------------------
1 | [
4 | 'request' => [
5 | // !!! insert a secret key in the following (if it is empty) - this is required by cookie validation
6 | 'cookieValidationKey' => '',
7 | ],
8 | ],
9 | ];
10 |
--------------------------------------------------------------------------------
/environments/prod/frontend/config/params-local.php:
--------------------------------------------------------------------------------
1 | run();
19 |
--------------------------------------------------------------------------------
/environments/prod/tests/codeception/config/config-local.php:
--------------------------------------------------------------------------------
1 | [
4 | 'db' => [
5 | 'dsn' => 'mysql:host=localhost;dbname=yii2_advanced_tests',
6 | 'username' => 'root',
7 | 'password' => '',
8 | 'charset' => 'utf8',
9 | ],
10 | ],
11 | ];
12 |
--------------------------------------------------------------------------------
/environments/prod/yii:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env php
2 | run();
28 | exit($exitCode);
29 |
--------------------------------------------------------------------------------
/frontend/assets/AppAsset.php:
--------------------------------------------------------------------------------
1 | 'app-frontend',
11 | 'basePath' => dirname(__DIR__),
12 | 'bootstrap' => ['log'],
13 | 'controllerNamespace' => 'frontend\controllers',
14 | 'components' => [
15 | 'request' => [
16 | 'csrfParam' => '_csrf-frontend',
17 | ],
18 | 'user' => [
19 | 'identityClass' => 'common\models\User',
20 | 'enableAutoLogin' => true,
21 | 'identityCookie' => ['name' => '_identity-frontend', 'httpOnly' => true],
22 | ],
23 | 'session' => [
24 | // this is the name of the session cookie used for login on the frontend
25 | 'name' => 'advanced-frontend',
26 | ],
27 | 'log' => [
28 | 'traceLevel' => YII_DEBUG ? 3 : 0,
29 | 'targets' => [
30 | [
31 | 'class' => 'yii\log\FileTarget',
32 | 'levels' => ['error', 'warning'],
33 | ],
34 | ],
35 | ],
36 | 'errorHandler' => [
37 | 'errorAction' => 'site/error',
38 | ],
39 | /*
40 | 'urlManager' => [
41 | 'enablePrettyUrl' => true,
42 | 'showScriptName' => false,
43 | 'rules' => [
44 | ],
45 | ],
46 | */
47 | ],
48 | 'params' => $params,
49 | ];
50 |
--------------------------------------------------------------------------------
/frontend/config/params.php:
--------------------------------------------------------------------------------
1 | 'admin@example.com',
4 | ];
5 |
--------------------------------------------------------------------------------
/frontend/controllers/AppController.php:
--------------------------------------------------------------------------------
1 | renderPartial("jiemeng");
18 | }
19 |
20 | /*
21 | * 抽奖页面
22 | */
23 | public function actionDraw()
24 | {
25 | return $this->renderPartial("draw");
26 | }
27 | }
--------------------------------------------------------------------------------
/frontend/controllers/RewardController.php:
--------------------------------------------------------------------------------
1 | renderPartial("apply");
15 | }
16 | }
--------------------------------------------------------------------------------
/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 | /**
69 | * Displays homepage.
70 | *
71 | * @return mixed
72 | */
73 | public function actionIndex()
74 | {
75 | return $this->render('index');
76 | }
77 |
78 | /**
79 | * Logs in a user.
80 | *
81 | * @return mixed
82 | */
83 | public function actionLogin()
84 | {
85 | if (!Yii::$app->user->isGuest) {
86 | return $this->goHome();
87 | }
88 |
89 | $model = new LoginForm();
90 | if ($model->load(Yii::$app->request->post()) && $model->login()) {
91 | return $this->goBack();
92 | } else {
93 | return $this->render('login', [
94 | 'model' => $model,
95 | ]);
96 | }
97 | }
98 |
99 | /**
100 | * Logs out the current user.
101 | *
102 | * @return mixed
103 | */
104 | public function actionLogout()
105 | {
106 | Yii::$app->user->logout();
107 |
108 | return $this->goHome();
109 | }
110 |
111 | /**
112 | * Displays contact page.
113 | *
114 | * @return mixed
115 | */
116 | public function actionContact()
117 | {
118 | $model = new ContactForm();
119 | if ($model->load(Yii::$app->request->post()) && $model->validate()) {
120 | if ($model->sendEmail(Yii::$app->params['adminEmail'])) {
121 | Yii::$app->session->setFlash('success', 'Thank you for contacting us. We will respond to you as soon as possible.');
122 | } else {
123 | Yii::$app->session->setFlash('error', 'There was an error sending email.');
124 | }
125 |
126 | return $this->refresh();
127 | } else {
128 | return $this->render('contact', [
129 | 'model' => $model,
130 | ]);
131 | }
132 | }
133 |
134 | /**
135 | * Displays about page.
136 | *
137 | * @return mixed
138 | */
139 | public function actionAbout()
140 | {
141 | return $this->render('about');
142 | }
143 |
144 | /**
145 | * Signs user up.
146 | *
147 | * @return mixed
148 | */
149 | public function actionSignup()
150 | {
151 | $model = new SignupForm();
152 | if ($model->load(Yii::$app->request->post())) {
153 | if ($user = $model->signup()) {
154 | if (Yii::$app->getUser()->login($user)) {
155 | return $this->goHome();
156 | }
157 | }
158 | }
159 |
160 | return $this->render('signup', [
161 | 'model' => $model,
162 | ]);
163 | }
164 |
165 | /**
166 | * Requests password reset.
167 | *
168 | * @return mixed
169 | */
170 | public function actionRequestPasswordReset()
171 | {
172 | $model = new PasswordResetRequestForm();
173 | if ($model->load(Yii::$app->request->post()) && $model->validate()) {
174 | if ($model->sendEmail()) {
175 | Yii::$app->session->setFlash('success', 'Check your email for further instructions.');
176 |
177 | return $this->goHome();
178 | } else {
179 | Yii::$app->session->setFlash('error', 'Sorry, we are unable to reset password for email provided.');
180 | }
181 | }
182 |
183 | return $this->render('requestPasswordResetToken', [
184 | 'model' => $model,
185 | ]);
186 | }
187 |
188 | /**
189 | * Resets password.
190 | *
191 | * @param string $token
192 | * @return mixed
193 | * @throws BadRequestHttpException
194 | */
195 | public function actionResetPassword($token)
196 | {
197 | try {
198 | $model = new ResetPasswordForm($token);
199 | } catch (InvalidParamException $e) {
200 | throw new BadRequestHttpException($e->getMessage());
201 | }
202 |
203 | if ($model->load(Yii::$app->request->post()) && $model->validate() && $model->resetPassword()) {
204 | Yii::$app->session->setFlash('success', 'New password was saved.');
205 |
206 | return $this->goHome();
207 | }
208 |
209 | return $this->render('resetPassword', [
210 | 'model' => $model,
211 | ]);
212 | }
213 | }
214 |
--------------------------------------------------------------------------------
/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 boolean 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 |
--------------------------------------------------------------------------------
/frontend/models/PasswordResetRequestForm.php:
--------------------------------------------------------------------------------
1 | '\common\models\User',
27 | 'filter' => ['status' => User::STATUS_ACTIVE],
28 | 'message' => 'There is no user with such email.'
29 | ],
30 | ];
31 | }
32 |
33 | /**
34 | * Sends an email with a link, for resetting the password.
35 | *
36 | * @return boolean whether the email was send
37 | */
38 | public function sendEmail()
39 | {
40 | /* @var $user User */
41 | $user = User::findOne([
42 | 'status' => User::STATUS_ACTIVE,
43 | 'email' => $this->email,
44 | ]);
45 |
46 | if (!$user) {
47 | return false;
48 | }
49 |
50 | if (!User::isPasswordResetTokenValid($user->password_reset_token)) {
51 | $user->generatePasswordResetToken();
52 | if (!$user->save()) {
53 | return false;
54 | }
55 | }
56 |
57 | return Yii::$app
58 | ->mailer
59 | ->compose(
60 | ['html' => 'passwordResetToken-html', 'text' => 'passwordResetToken-text'],
61 | ['user' => $user]
62 | )
63 | ->setFrom([Yii::$app->params['supportEmail'] => Yii::$app->name . ' robot'])
64 | ->setTo($this->email)
65 | ->setSubject('Password reset for ' . Yii::$app->name)
66 | ->send();
67 | }
68 | }
69 |
--------------------------------------------------------------------------------
/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->setPassword($this->password);
60 | $user->removePasswordResetToken();
61 |
62 | return $user->save(false);
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/frontend/runtime/.gitignore:
--------------------------------------------------------------------------------
1 | *
2 | !.gitignore
--------------------------------------------------------------------------------
/frontend/views/app/draw.php:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | = $answer; ?>
--------------------------------------------------------------------------------
/frontend/views/layouts/main.php:
--------------------------------------------------------------------------------
1 |
15 | beginPage() ?>
16 |
17 |
18 |
19 |
20 |
21 | = Html::csrfMetaTags() ?>
22 | = Html::encode($this->title) ?>
23 | head() ?>
24 |
25 |
26 | beginBody() ?>
27 |
28 |
29 | 'My Company',
32 | 'brandUrl' => Yii::$app->homeUrl,
33 | 'options' => [
34 | 'class' => 'navbar-inverse navbar-fixed-top',
35 | ],
36 | ]);
37 | $menuItems = [
38 | ['label' => 'Home', 'url' => ['/site/index']],
39 | ['label' => 'About', 'url' => ['/site/about']],
40 | ['label' => 'Contact', 'url' => ['/site/contact']],
41 | ];
42 | if (Yii::$app->user->isGuest) {
43 | $menuItems[] = ['label' => 'Signup', 'url' => ['/site/signup']];
44 | $menuItems[] = ['label' => 'Login', 'url' => ['/site/login']];
45 | } else {
46 | $menuItems[] = '
'
47 | . Html::beginForm(['/site/logout'], 'post')
48 | . Html::submitButton(
49 | 'Logout (' . Yii::$app->user->identity->username . ')',
50 | ['class' => 'btn btn-link']
51 | )
52 | . Html::endForm()
53 | . '';
54 | }
55 | echo Nav::widget([
56 | 'options' => ['class' => 'navbar-nav navbar-right'],
57 | 'items' => $menuItems,
58 | ]);
59 | NavBar::end();
60 | ?>
61 |
62 |
63 | = Breadcrumbs::widget([
64 | 'links' => isset($this->params['breadcrumbs']) ? $this->params['breadcrumbs'] : [],
65 | ]) ?>
66 | = Alert::widget() ?>
67 | = $content ?>
68 |
69 |
70 |
71 |
78 |
79 | endBody() ?>
80 |
81 |
82 | endPage() ?>
83 |
--------------------------------------------------------------------------------
/frontend/views/reward/apply.php:
--------------------------------------------------------------------------------
1 | 1111
2 |
--------------------------------------------------------------------------------
/frontend/views/site/about.php:
--------------------------------------------------------------------------------
1 | title = 'About';
8 | $this->params['breadcrumbs'][] = $this->title;
9 | ?>
10 |
11 |
= Html::encode($this->title) ?>
12 |
13 |
This is the About page. You may modify the following file to customize its content:
14 |
15 |
= __FILE__ ?>
16 |
17 |
--------------------------------------------------------------------------------
/frontend/views/site/contact.php:
--------------------------------------------------------------------------------
1 | title = 'Contact';
12 | $this->params['breadcrumbs'][] = $this->title;
13 | ?>
14 |
46 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/frontend/views/site/index.php:
--------------------------------------------------------------------------------
1 | title = 'My Yii Application';
6 | ?>
7 |
8 |
9 |
10 |
Congratulations!
11 |
12 |
You have successfully created your Yii-powered application.
13 |
14 |
Get started with Yii
15 |
16 |
17 |
18 |
19 |
20 |
21 |
Heading
22 |
23 |
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et
24 | dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip
25 | ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu
26 | fugiat nulla pariatur.
27 |
28 |
Yii Documentation »
29 |
30 |
31 |
Heading
32 |
33 |
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et
34 | dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip
35 | ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu
36 | fugiat nulla pariatur.
37 |
38 |
Yii Forum »
39 |
40 |
41 |
Heading
42 |
43 |
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et
44 | dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip
45 | ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu
46 | fugiat nulla pariatur.
47 |
48 |
Yii Extensions »
49 |
50 |
51 |
52 |
53 |
54 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/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/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/web/.gitignore:
--------------------------------------------------------------------------------
1 | /index.php
2 | /index-test.php
3 |
--------------------------------------------------------------------------------
/frontend/web/assets/.gitignore:
--------------------------------------------------------------------------------
1 | *
2 | !.gitignore
3 |
--------------------------------------------------------------------------------
/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: "\e151";
53 | }
54 |
55 | a.desc:after {
56 | content: "\e152";
57 | }
58 |
59 | .sort-numerical a.asc:after {
60 | content: "\e153";
61 | }
62 |
63 | .sort-numerical a.desc:after {
64 | content: "\e154";
65 | }
66 |
67 | .sort-ordinal a.asc:after {
68 | content: "\e155";
69 | }
70 |
71 | .sort-ordinal a.desc:after {
72 | content: "\e156";
73 | }
74 |
75 | .grid-view td {
76 | white-space: nowrap;
77 | }
78 |
79 | .grid-view .filters input,
80 | .grid-view .filters select {
81 | min-width: 50px;
82 | }
83 |
84 | .hint-block {
85 | display: block;
86 | margin-top: 5px;
87 | color: #999;
88 | }
89 |
90 | .error-summary {
91 | color: #a94442;
92 | background: #fdf7f7;
93 | border-left: 3px solid #eed3d7;
94 | padding: 10px 20px;
95 | margin: 0 0 15px 0;
96 | }
97 |
98 | /* align the logout "link" (button in form) of the navbar */
99 | .nav > li > form {
100 | padding: 8px;
101 | }
102 |
103 | @media(max-width:768px) {
104 | .nav li > form {
105 | padding: 3px;
106 | }
107 | }
108 |
109 | .nav > li > form > button:hover {
110 | text-decoration: none;
111 | }
112 |
--------------------------------------------------------------------------------
/frontend/web/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ChaozhangXue/weiYii2/cbd6cd0dcdc9c2ff36ed5b82988063218616384b/frontend/web/favicon.ico
--------------------------------------------------------------------------------
/frontend/web/fonts/glyphicons-halflings-regular.eot:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ChaozhangXue/weiYii2/cbd6cd0dcdc9c2ff36ed5b82988063218616384b/frontend/web/fonts/glyphicons-halflings-regular.eot
--------------------------------------------------------------------------------
/frontend/web/fonts/glyphicons-halflings-regular.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ChaozhangXue/weiYii2/cbd6cd0dcdc9c2ff36ed5b82988063218616384b/frontend/web/fonts/glyphicons-halflings-regular.ttf
--------------------------------------------------------------------------------
/frontend/web/fonts/glyphicons-halflings-regular.woff:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ChaozhangXue/weiYii2/cbd6cd0dcdc9c2ff36ed5b82988063218616384b/frontend/web/fonts/glyphicons-halflings-regular.woff
--------------------------------------------------------------------------------
/frontend/web/images/chrome-big.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ChaozhangXue/weiYii2/cbd6cd0dcdc9c2ff36ed5b82988063218616384b/frontend/web/images/chrome-big.jpg
--------------------------------------------------------------------------------
/frontend/web/images/chrome-logo-small.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ChaozhangXue/weiYii2/cbd6cd0dcdc9c2ff36ed5b82988063218616384b/frontend/web/images/chrome-logo-small.jpg
--------------------------------------------------------------------------------
/frontend/web/images/chrome-logo.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ChaozhangXue/weiYii2/cbd6cd0dcdc9c2ff36ed5b82988063218616384b/frontend/web/images/chrome-logo.jpg
--------------------------------------------------------------------------------
/frontend/web/images/firefox-big.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ChaozhangXue/weiYii2/cbd6cd0dcdc9c2ff36ed5b82988063218616384b/frontend/web/images/firefox-big.jpg
--------------------------------------------------------------------------------
/frontend/web/images/firefox-logo-small.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ChaozhangXue/weiYii2/cbd6cd0dcdc9c2ff36ed5b82988063218616384b/frontend/web/images/firefox-logo-small.jpg
--------------------------------------------------------------------------------
/frontend/web/images/firefox-logo.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ChaozhangXue/weiYii2/cbd6cd0dcdc9c2ff36ed5b82988063218616384b/frontend/web/images/firefox-logo.jpg
--------------------------------------------------------------------------------
/frontend/web/images/ie-big.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ChaozhangXue/weiYii2/cbd6cd0dcdc9c2ff36ed5b82988063218616384b/frontend/web/images/ie-big.jpg
--------------------------------------------------------------------------------
/frontend/web/images/ie-logo.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ChaozhangXue/weiYii2/cbd6cd0dcdc9c2ff36ed5b82988063218616384b/frontend/web/images/ie-logo.jpg
--------------------------------------------------------------------------------
/frontend/web/images/logo.psd:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ChaozhangXue/weiYii2/cbd6cd0dcdc9c2ff36ed5b82988063218616384b/frontend/web/images/logo.psd
--------------------------------------------------------------------------------
/frontend/web/images/opera-big.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ChaozhangXue/weiYii2/cbd6cd0dcdc9c2ff36ed5b82988063218616384b/frontend/web/images/opera-big.jpg
--------------------------------------------------------------------------------
/frontend/web/images/opera-logo.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ChaozhangXue/weiYii2/cbd6cd0dcdc9c2ff36ed5b82988063218616384b/frontend/web/images/opera-logo.jpg
--------------------------------------------------------------------------------
/frontend/web/images/safari-big.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ChaozhangXue/weiYii2/cbd6cd0dcdc9c2ff36ed5b82988063218616384b/frontend/web/images/safari-big.jpg
--------------------------------------------------------------------------------
/frontend/web/images/safari-logo-small.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ChaozhangXue/weiYii2/cbd6cd0dcdc9c2ff36ed5b82988063218616384b/frontend/web/images/safari-logo-small.jpg
--------------------------------------------------------------------------------
/frontend/web/images/safari-logo.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ChaozhangXue/weiYii2/cbd6cd0dcdc9c2ff36ed5b82988063218616384b/frontend/web/images/safari-logo.jpg
--------------------------------------------------------------------------------
/frontend/web/js/html5shiv.js:
--------------------------------------------------------------------------------
1 | /*
2 | HTML5 Shiv v3.7.0 | @afarkas @jdalton @jon_neal @rem | MIT/GPL2 Licensed
3 | */
4 | (function(l,f){function m(){var a=e.elements;return"string"==typeof a?a.split(" "):a}function i(a){var b=n[a[o]];b||(b={},h++,a[o]=h,n[h]=b);return b}function p(a,b,c){b||(b=f);if(g)return b.createElement(a);c||(c=i(b));b=c.cache[a]?c.cache[a].cloneNode():r.test(a)?(c.cache[a]=c.createElem(a)).cloneNode():c.createElem(a);return b.canHaveChildren&&!s.test(a)?c.frag.appendChild(b):b}function t(a,b){if(!b.cache)b.cache={},b.createElem=a.createElement,b.createFrag=a.createDocumentFragment,b.frag=b.createFrag();
5 | a.createElement=function(c){return!e.shivMethods?b.createElem(c):p(c,a,b)};a.createDocumentFragment=Function("h,f","return function(){var n=f.cloneNode(),c=n.createElement;h.shivMethods&&("+m().join().replace(/[\w\-]+/g,function(a){b.createElem(a);b.frag.createElement(a);return'c("'+a+'")'})+");return n}")(e,b.frag)}function q(a){a||(a=f);var b=i(a);if(e.shivCSS&&!j&&!b.hasCSS){var c,d=a;c=d.createElement("p");d=d.getElementsByTagName("head")[0]||d.documentElement;c.innerHTML="x";
6 | c=d.insertBefore(c.lastChild,d.firstChild);b.hasCSS=!!c}g||t(a,b);return a}var k=l.html5||{},s=/^<|^(?:button|map|select|textarea|object|iframe|option|optgroup)$/i,r=/^(?:a|b|code|div|fieldset|h1|h2|h3|h4|h5|h6|i|label|li|ol|p|q|span|strong|style|table|tbody|td|th|tr|ul)$/i,j,o="_html5shiv",h=0,n={},g;(function(){try{var a=f.createElement("a");a.innerHTML="";j="hidden"in a;var b;if(!(b=1==a.childNodes.length)){f.createElement("a");var c=f.createDocumentFragment();b="undefined"==typeof c.cloneNode||
7 | "undefined"==typeof c.createDocumentFragment||"undefined"==typeof c.createElement}g=b}catch(d){g=j=!0}})();var e={elements:k.elements||"abbr article aside audio bdi canvas data datalist details dialog figcaption figure footer header hgroup main mark meter nav output progress section summary template time video",version:"3.7.0",shivCSS:!1!==k.shivCSS,supportsUnknownElements:g,shivMethods:!1!==k.shivMethods,type:"default",shivDocument:q,createElement:p,createDocumentFragment:function(a,b){a||(a=f);
8 | if(g)return a.createDocumentFragment();for(var b=b||i(a),c=b.frag.cloneNode(),d=0,e=m(),h=e.length;d #mq-test-1 { width: 42px; }',c.insertBefore(e,d),b=42===f.offsetWidth,c.removeChild(e),{matches:b,media:a}}}(a.document)}(this),function(a){"use strict";function b(){u(!0)}var c={};a.respond=c,c.update=function(){};var d=[],e=function(){var b=!1;try{b=new a.XMLHttpRequest}catch(c){b=new a.ActiveXObject("Microsoft.XMLHTTP")}return function(){return b}}(),f=function(a,b){var c=e();c&&(c.open("GET",a,!0),c.onreadystatechange=function(){4!==c.readyState||200!==c.status&&304!==c.status||b(c.responseText)},4!==c.readyState&&c.send(null))};if(c.ajax=f,c.queue=d,c.regex={media:/@media[^\{]+\{([^\{\}]*\{[^\}\{]*\})+/gi,keyframes:/@(?:\-(?:o|moz|webkit)\-)?keyframes[^\{]+\{(?:[^\{\}]*\{[^\}\{]*\})+[^\}]*\}/gi,urls:/(url\()['"]?([^\/\)'"][^:\)'"]+)['"]?(\))/g,findStyles:/@media *([^\{]+)\{([\S\s]+?)$/,only:/(only\s+)?([a-zA-Z]+)\s?/,minw:/\([\s]*min\-width\s*:[\s]*([\s]*[0-9\.]+)(px|em)[\s]*\)/,maxw:/\([\s]*max\-width\s*:[\s]*([\s]*[0-9\.]+)(px|em)[\s]*\)/},c.mediaQueriesSupported=a.matchMedia&&null!==a.matchMedia("only all")&&a.matchMedia("only all").matches,!c.mediaQueriesSupported){var g,h,i,j=a.document,k=j.documentElement,l=[],m=[],n=[],o={},p=30,q=j.getElementsByTagName("head")[0]||k,r=j.getElementsByTagName("base")[0],s=q.getElementsByTagName("link"),t=function(){var a,b=j.createElement("div"),c=j.body,d=k.style.fontSize,e=c&&c.style.fontSize,f=!1;return b.style.cssText="position:absolute;font-size:1em;width:1em",c||(c=f=j.createElement("body"),c.style.background="none"),k.style.fontSize="100%",c.style.fontSize="100%",c.appendChild(b),f&&k.insertBefore(c,k.firstChild),a=b.offsetWidth,f?k.removeChild(c):c.removeChild(b),k.style.fontSize=d,e&&(c.style.fontSize=e),a=i=parseFloat(a)},u=function(b){var c="clientWidth",d=k[c],e="CSS1Compat"===j.compatMode&&d||j.body[c]||d,f={},o=s[s.length-1],r=(new Date).getTime();if(b&&g&&p>r-g)return a.clearTimeout(h),h=a.setTimeout(u,p),void 0;g=r;for(var v in l)if(l.hasOwnProperty(v)){var w=l[v],x=w.minw,y=w.maxw,z=null===x,A=null===y,B="em";x&&(x=parseFloat(x)*(x.indexOf(B)>-1?i||t():1)),y&&(y=parseFloat(y)*(y.indexOf(B)>-1?i||t():1)),w.hasquery&&(z&&A||!(z||e>=x)||!(A||y>=e))||(f[w.media]||(f[w.media]=[]),f[w.media].push(m[w.rules]))}for(var C in n)n.hasOwnProperty(C)&&n[C]&&n[C].parentNode===q&&q.removeChild(n[C]);n.length=0;for(var D in f)if(f.hasOwnProperty(D)){var E=j.createElement("style"),F=f[D].join("\n");E.type="text/css",E.media=D,q.insertBefore(E,o.nextSibling),E.styleSheet?E.styleSheet.cssText=F:E.appendChild(j.createTextNode(F)),n.push(E)}},v=function(a,b,d){var e=a.replace(c.regex.keyframes,"").match(c.regex.media),f=e&&e.length||0;b=b.substring(0,b.lastIndexOf("/"));var g=function(a){return a.replace(c.regex.urls,"$1"+b+"$2$3")},h=!f&&d;b.length&&(b+="/"),h&&(f=1);for(var i=0;f>i;i++){var j,k,n,o;h?(j=d,m.push(g(a))):(j=e[i].match(c.regex.findStyles)&&RegExp.$1,m.push(RegExp.$2&&g(RegExp.$2))),n=j.split(","),o=n.length;for(var p=0;o>p;p++)k=n[p],l.push({media:k.split("(")[0].match(c.regex.only)&&RegExp.$2||"all",rules:m.length-1,hasquery:k.indexOf("(")>-1,minw:k.match(c.regex.minw)&&parseFloat(RegExp.$1)+(RegExp.$2||""),maxw:k.match(c.regex.maxw)&&parseFloat(RegExp.$1)+(RegExp.$2||"")})}u()},w=function(){if(d.length){var b=d.shift();f(b.href,function(c){v(c,b.href,b.media),o[b.href]=!0,a.setTimeout(function(){w()},0)})}},x=function(){for(var b=0;b
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 | if (!extension_loaded('openssl')) {
18 | die('The OpenSSL PHP extension is required by Yii2.');
19 | }
20 |
21 | $params = getParams();
22 | $root = str_replace('\\', '/', __DIR__);
23 | $envs = require("$root/environments/index.php");
24 | $envNames = array_keys($envs);
25 |
26 | echo "Yii Application Initialization Tool v1.0\n\n";
27 |
28 | $envName = null;
29 | if (empty($params['env']) || $params['env'] === '1') {
30 | echo "Which environment do you want the application to be initialized in?\n\n";
31 | foreach ($envNames as $i => $name) {
32 | echo " [$i] $name\n";
33 | }
34 | echo "\n Your choice [0-" . (count($envs) - 1) . ', or "q" to quit] ';
35 | $answer = trim(fgets(STDIN));
36 |
37 | if (!ctype_digit($answer) || !in_array($answer, range(0, count($envs) - 1))) {
38 | echo "\n Quit initialization.\n";
39 | exit(0);
40 | }
41 |
42 | if (isset($envNames[$answer])) {
43 | $envName = $envNames[$answer];
44 | }
45 | } else {
46 | $envName = $params['env'];
47 | }
48 |
49 | if (!in_array($envName, $envNames)) {
50 | $envsList = implode(', ', $envNames);
51 | echo "\n $envName is not a valid environment. Try one of the following: $envsList. \n";
52 | exit(2);
53 | }
54 |
55 | $env = $envs[$envName];
56 |
57 | if (empty($params['env'])) {
58 | echo "\n Initialize the application under '{$envNames[$answer]}' environment? [yes|no] ";
59 | $answer = trim(fgets(STDIN));
60 | if (strncasecmp($answer, 'y', 1)) {
61 | echo "\n Quit initialization.\n";
62 | exit(0);
63 | }
64 | }
65 |
66 | echo "\n Start initialization ...\n\n";
67 | $files = getFileList("$root/environments/{$env['path']}");
68 | if (isset($env['skipFiles'])) {
69 | $skipFiles = $env['skipFiles'];
70 | array_walk($skipFiles, function(&$value) use($env, $root) { $value = "$root/$value"; });
71 | $files = array_diff($files, array_intersect_key($env['skipFiles'], array_filter($skipFiles, 'file_exists')));
72 | }
73 | $all = false;
74 | foreach ($files as $file) {
75 | if (!copyFile($root, "environments/{$env['path']}/$file", $file, $all, $params)) {
76 | break;
77 | }
78 | }
79 |
80 | $callbacks = ['setCookieValidationKey', 'setWritable', 'setExecutable', 'createSymlink'];
81 | foreach ($callbacks as $callback) {
82 | if (!empty($env[$callback])) {
83 | $callback($root, $env[$callback]);
84 | }
85 | }
86 |
87 | echo "\n ... initialization completed.\n\n";
88 |
89 | function getFileList($root, $basePath = '')
90 | {
91 | $files = [];
92 | $handle = opendir($root);
93 | while (($path = readdir($handle)) !== false) {
94 | if ($path === '.git' || $path === '.svn' || $path === '.' || $path === '..') {
95 | continue;
96 | }
97 | $fullPath = "$root/$path";
98 | $relativePath = $basePath === '' ? $path : "$basePath/$path";
99 | if (is_dir($fullPath)) {
100 | $files = array_merge($files, getFileList($fullPath, $relativePath));
101 | } else {
102 | $files[] = $relativePath;
103 | }
104 | }
105 | closedir($handle);
106 | return $files;
107 | }
108 |
109 | function copyFile($root, $source, $target, &$all, $params)
110 | {
111 | if (!is_file($root . '/' . $source)) {
112 | echo " skip $target ($source not exist)\n";
113 | return true;
114 | }
115 | if (is_file($root . '/' . $target)) {
116 | if (file_get_contents($root . '/' . $source) === file_get_contents($root . '/' . $target)) {
117 | echo " unchanged $target\n";
118 | return true;
119 | }
120 | if ($all) {
121 | echo " overwrite $target\n";
122 | } else {
123 | echo " exist $target\n";
124 | echo " ...overwrite? [Yes|No|All|Quit] ";
125 |
126 |
127 | $answer = !empty($params['overwrite']) ? $params['overwrite'] : trim(fgets(STDIN));
128 | if (!strncasecmp($answer, 'q', 1)) {
129 | return false;
130 | } else {
131 | if (!strncasecmp($answer, 'y', 1)) {
132 | echo " overwrite $target\n";
133 | } else {
134 | if (!strncasecmp($answer, 'a', 1)) {
135 | echo " overwrite $target\n";
136 | $all = true;
137 | } else {
138 | echo " skip $target\n";
139 | return true;
140 | }
141 | }
142 | }
143 | }
144 | file_put_contents($root . '/' . $target, file_get_contents($root . '/' . $source));
145 | return true;
146 | }
147 | echo " generate $target\n";
148 | @mkdir(dirname($root . '/' . $target), 0777, true);
149 | file_put_contents($root . '/' . $target, file_get_contents($root . '/' . $source));
150 | return true;
151 | }
152 |
153 | function getParams()
154 | {
155 | $rawParams = [];
156 | if (isset($_SERVER['argv'])) {
157 | $rawParams = $_SERVER['argv'];
158 | array_shift($rawParams);
159 | }
160 |
161 | $params = [];
162 | foreach ($rawParams as $param) {
163 | if (preg_match('/^--(\w+)(=(.*))?$/', $param, $matches)) {
164 | $name = $matches[1];
165 | $params[$name] = isset($matches[3]) ? $matches[3] : true;
166 | } else {
167 | $params[] = $param;
168 | }
169 | }
170 | return $params;
171 | }
172 |
173 | function setWritable($root, $paths)
174 | {
175 | foreach ($paths as $writable) {
176 | if (is_dir("$root/$writable")) {
177 | echo " chmod 0777 $writable\n";
178 | @chmod("$root/$writable", 0777);
179 | } else {
180 | echo "\n Error. Directory $writable does not exist. \n";
181 | }
182 | }
183 | }
184 |
185 | function setExecutable($root, $paths)
186 | {
187 | foreach ($paths as $executable) {
188 | echo " chmod 0755 $executable\n";
189 | @chmod("$root/$executable", 0755);
190 | }
191 | }
192 |
193 | function setCookieValidationKey($root, $paths)
194 | {
195 | foreach ($paths as $file) {
196 | echo " generate cookie validation key in $file\n";
197 | $file = $root . '/' . $file;
198 | $length = 32;
199 | $bytes = openssl_random_pseudo_bytes($length);
200 | $key = strtr(substr(base64_encode($bytes), 0, $length), '+/=', '_-.');
201 | $content = preg_replace('/(("|\')cookieValidationKey("|\')\s*=>\s*)(""|\'\')/', "\\1'$key'", file_get_contents($file));
202 | file_put_contents($file, $content);
203 | }
204 | }
205 |
206 | function createSymlink($root, $links) {
207 | foreach ($links as $link => $target) {
208 | echo " symlink " . $root . "/" . $target . " " . $root . "/" . $link . "\n";
209 | //first removing folders to avoid errors if the folder already exists
210 | @rmdir($root . "/" . $link);
211 | //next removing existing symlink in order to update the target
212 | if (is_link($root . "/" . $link)) {
213 | @unlink($root . "/" . $link);
214 | }
215 | @symlink($root . "/" . $target, $root . "/" . $link);
216 | }
217 | }
218 |
--------------------------------------------------------------------------------
/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 (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%init" %*
19 |
20 | @endlocal
21 |
--------------------------------------------------------------------------------
/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 | $gdMemo = $imagickMemo = 'Either GD PHP extension with FreeType support or ImageMagick PHP extension with PNG support is required for image CAPTCHA.';
27 | $gdOK = $imagickOK = false;
28 |
29 | if (extension_loaded('imagick')) {
30 | $imagick = new Imagick();
31 | $imagickFormats = $imagick->queryFormats('PNG');
32 | if (in_array('PNG', $imagickFormats)) {
33 | $imagickOK = true;
34 | } else {
35 | $imagickMemo = 'Imagick extension should be installed with PNG support in order to be used for image CAPTCHA.';
36 | }
37 | }
38 |
39 | if (extension_loaded('gd')) {
40 | $gdInfo = gd_info();
41 | if (!empty($gdInfo['FreeType Support'])) {
42 | $gdOK = true;
43 | } else {
44 | $gdMemo = 'GD extension should be installed with FreeType support in order to be used for image CAPTCHA.';
45 | }
46 | }
47 |
48 | /**
49 | * Adjust requirements according to your application specifics.
50 | */
51 | $requirements = array(
52 | // Database :
53 | array(
54 | 'name' => 'PDO extension',
55 | 'mandatory' => true,
56 | 'condition' => extension_loaded('pdo'),
57 | 'by' => 'All DB-related classes',
58 | ),
59 | array(
60 | 'name' => 'PDO SQLite extension',
61 | 'mandatory' => false,
62 | 'condition' => extension_loaded('pdo_sqlite'),
63 | 'by' => 'All DB-related classes',
64 | 'memo' => 'Required for SQLite database.',
65 | ),
66 | array(
67 | 'name' => 'PDO MySQL extension',
68 | 'mandatory' => false,
69 | 'condition' => extension_loaded('pdo_mysql'),
70 | 'by' => 'All DB-related classes',
71 | 'memo' => 'Required for MySQL database.',
72 | ),
73 | array(
74 | 'name' => 'PDO PostgreSQL extension',
75 | 'mandatory' => false,
76 | 'condition' => extension_loaded('pdo_pgsql'),
77 | 'by' => 'All DB-related classes',
78 | 'memo' => 'Required for PostgreSQL database.',
79 | ),
80 | // Cache :
81 | array(
82 | 'name' => 'Memcache extension',
83 | 'mandatory' => false,
84 | 'condition' => extension_loaded('memcache') || extension_loaded('memcached'),
85 | 'by' => 'MemCache',
86 | 'memo' => extension_loaded('memcached') ? 'To use memcached set MemCache::useMemcached to true
.' : ''
87 | ),
88 | array(
89 | 'name' => 'APC extension',
90 | 'mandatory' => false,
91 | 'condition' => extension_loaded('apc'),
92 | 'by' => 'ApcCache',
93 | ),
94 | // CAPTCHA:
95 | array(
96 | 'name' => 'GD PHP extension with FreeType support',
97 | 'mandatory' => false,
98 | 'condition' => $gdOK,
99 | 'by' => 'Captcha',
100 | 'memo' => $gdMemo,
101 | ),
102 | array(
103 | 'name' => 'ImageMagick PHP extension with PNG support',
104 | 'mandatory' => false,
105 | 'condition' => $imagickOK,
106 | 'by' => 'Captcha',
107 | 'memo' => $imagickMemo,
108 | ),
109 | // PHP ini :
110 | 'phpExposePhp' => array(
111 | 'name' => 'Expose PHP',
112 | 'mandatory' => false,
113 | 'condition' => $requirementsChecker->checkPhpIniOff("expose_php"),
114 | 'by' => 'Security reasons',
115 | 'memo' => '"expose_php" should be disabled at php.ini',
116 | ),
117 | 'phpAllowUrlInclude' => array(
118 | 'name' => 'PHP allow url include',
119 | 'mandatory' => false,
120 | 'condition' => $requirementsChecker->checkPhpIniOff("allow_url_include"),
121 | 'by' => 'Security reasons',
122 | 'memo' => '"allow_url_include" should be disabled at php.ini',
123 | ),
124 | 'phpSmtp' => array(
125 | 'name' => 'PHP mail SMTP',
126 | 'mandatory' => false,
127 | 'condition' => strlen(ini_get('SMTP')) > 0,
128 | 'by' => 'Email sending',
129 | 'memo' => 'PHP mail SMTP server required',
130 | ),
131 | );
132 | $requirementsChecker->checkYii()->check($requirements)->render();
133 |
--------------------------------------------------------------------------------
/tests/README.md:
--------------------------------------------------------------------------------
1 | This directory contains various tests for the advanced applications.
2 |
3 | Tests in `codeception` directory are developed with [Codeception PHP Testing Framework](http://codeception.com/).
4 |
5 | After creating and setting up the advanced application, follow these steps to prepare for the tests:
6 |
7 | 1. Install Codeception if it's not yet installed:
8 |
9 | ```
10 | composer global require "codeception/codeception=2.1.*" "codeception/specify=*" "codeception/verify=*"
11 | ```
12 |
13 | If you've never used Composer for global packages run `composer global status`. It should output:
14 |
15 | ```
16 | Changed current directory to
17 | ```
18 |
19 | Then add `/vendor/bin` to you `PATH` environment variable. Now you're able to use `codecept` from command
20 | line globally.
21 |
22 | 2. Install faker extension by running the following from template root directory where `composer.json` is:
23 |
24 | ```
25 | composer require --dev yiisoft/yii2-faker:*
26 | ```
27 |
28 | 3. Create a database for tests, adjust the `components['db']` configuration in `tests/codeception/config/config-local.php`,
29 | then update it by applying migrations:
30 |
31 | ```
32 | codeception/bin/yii migrate
33 | ```
34 |
35 | 4. In order to be able to run acceptance tests you need to start a webserver. The simplest way is to use PHP built in
36 | webserver. In the root directory where `common`, `frontend` etc. are execute the following:
37 |
38 | ```
39 | php -S localhost:8080
40 | ```
41 |
42 | 5. Now you can run the tests with the following commands, assuming you are in the `tests/codeception` directory:
43 |
44 | ```
45 | # frontend tests
46 | cd frontend
47 | codecept build
48 | codecept run
49 |
50 | # backend tests
51 |
52 | cd backend
53 | codecept build
54 | codecept run
55 |
56 | # etc.
57 | ```
58 |
59 | If you already have run `codecept build` for each application, you can skip that step and run all tests by a single `codecept run`.
60 |
--------------------------------------------------------------------------------
/tests/codeception.yml:
--------------------------------------------------------------------------------
1 | include:
2 | - codeception/common
3 | - codeception/console
4 | - codeception/backend
5 | - codeception/frontend
6 |
7 | paths:
8 | log: codeception/_output
9 |
10 | settings:
11 | colors: true
12 |
--------------------------------------------------------------------------------
/tests/codeception/_output/.gitignore:
--------------------------------------------------------------------------------
1 | *
2 | !.gitignore
3 |
--------------------------------------------------------------------------------
/tests/codeception/backend/.gitignore:
--------------------------------------------------------------------------------
1 | # these files are auto generated by codeception build
2 | /unit/UnitTester.php
3 | /functional/FunctionalTester.php
4 | /acceptance/AcceptanceTester.php
5 |
--------------------------------------------------------------------------------
/tests/codeception/backend/_bootstrap.php:
--------------------------------------------------------------------------------
1 | wantTo('ensure login page works');
12 |
13 | $loginPage = LoginPage::openBy($I);
14 |
15 | $I->amGoingTo('submit login form with no data');
16 | $loginPage->login('', '');
17 | if (method_exists($I, 'wait')) {
18 | $I->wait(3); // only for selenium
19 | }
20 | $I->expectTo('see validations errors');
21 | $I->see('Username cannot be blank.', '.help-block');
22 | $I->see('Password cannot be blank.', '.help-block');
23 |
24 | $I->amGoingTo('try to login with wrong credentials');
25 | $I->expectTo('see validations errors');
26 | $loginPage->login('admin', 'wrong');
27 | if (method_exists($I, 'wait')) {
28 | $I->wait(3); // only for selenium
29 | }
30 | $I->expectTo('see validations errors');
31 | $I->see('Incorrect username or password.', '.help-block');
32 |
33 | $I->amGoingTo('try to login with correct credentials');
34 | $loginPage->login('erau', 'password_0');
35 | if (method_exists($I, 'wait')) {
36 | $I->wait(3); // only for selenium
37 | }
38 | $I->expectTo('see that user is logged');
39 | $I->see('Logout (erau)', 'form button[type=submit]');
40 | $I->dontSeeLink('Login');
41 | $I->dontSeeLink('Signup');
42 | /** Uncomment if using WebDriver
43 | * $I->click('Logout (erau)');
44 | * $I->dontSeeLink('Logout (erau)');
45 | * $I->seeLink('Login');
46 | */
47 |
--------------------------------------------------------------------------------
/tests/codeception/backend/acceptance/_bootstrap.php:
--------------------------------------------------------------------------------
1 | wantTo('ensure login page works');
12 |
13 | $loginPage = LoginPage::openBy($I);
14 |
15 | $I->amGoingTo('submit login form with no data');
16 | $loginPage->login('', '');
17 | $I->expectTo('see validations errors');
18 | $I->see('Username cannot be blank.', '.help-block');
19 | $I->see('Password cannot be blank.', '.help-block');
20 |
21 | $I->amGoingTo('try to login with wrong credentials');
22 | $I->expectTo('see validations errors');
23 | $loginPage->login('admin', 'wrong');
24 | $I->expectTo('see validations errors');
25 | $I->see('Incorrect username or password.', '.help-block');
26 |
27 | $I->amGoingTo('try to login with correct credentials');
28 | $loginPage->login('erau', 'password_0');
29 | $I->expectTo('see that user is logged');
30 | $I->see('Logout (erau)', 'form button[type=submit]');
31 | $I->dontSeeLink('Login');
32 | $I->dontSeeLink('Signup');
33 |
--------------------------------------------------------------------------------
/tests/codeception/backend/functional/_bootstrap.php:
--------------------------------------------------------------------------------
1 | run();
24 | exit($exitCode);
25 |
--------------------------------------------------------------------------------
/tests/codeception/bin/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 (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" %*
19 |
20 | @endlocal
21 |
--------------------------------------------------------------------------------
/tests/codeception/common/.gitignore:
--------------------------------------------------------------------------------
1 | # these files are auto generated by codeception build
2 | /unit/UnitTester.php
3 | /functional/FunctionalTester.php
4 | /acceptance/AcceptanceTester.php
5 |
--------------------------------------------------------------------------------
/tests/codeception/common/_bootstrap.php:
--------------------------------------------------------------------------------
1 | actor->fillField('input[name="' . $loginForm->formName() . '[username]"]', $username);
25 | $this->actor->fillField('input[name="' . $loginForm->formName() . '[password]"]', $password);
26 | $this->actor->click('login-button');
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/tests/codeception/common/_support/FixtureHelper.php:
--------------------------------------------------------------------------------
1 | loadFixtures();
41 | }
42 |
43 | /**
44 | * Method is called after all suite tests run
45 | */
46 | public function _afterSuite()
47 | {
48 | $this->unloadFixtures();
49 | }
50 |
51 | /**
52 | * @inheritdoc
53 | */
54 | public function globalFixtures()
55 | {
56 | return [
57 | InitDbFixture::className(),
58 | ];
59 | }
60 |
61 | /**
62 | * @inheritdoc
63 | */
64 | public function fixtures()
65 | {
66 | return [
67 | 'user' => [
68 | 'class' => UserFixture::className(),
69 | 'dataFile' => '@tests/codeception/common/fixtures/data/init_login.php',
70 | ],
71 | ];
72 | }
73 | }
74 |
--------------------------------------------------------------------------------
/tests/codeception/common/codeception.yml:
--------------------------------------------------------------------------------
1 | namespace: tests\codeception\common
2 | actor: Tester
3 | paths:
4 | tests: .
5 | log: _output
6 | data: _data
7 | helpers: _support
8 | settings:
9 | bootstrap: _bootstrap.php
10 | suite_class: \PHPUnit_Framework_TestSuite
11 | colors: true
12 | memory_limit: 1024M
13 | log: true
14 |
--------------------------------------------------------------------------------
/tests/codeception/common/fixtures/UserFixture.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 |
--------------------------------------------------------------------------------
/tests/codeception/common/templates/fixtures/user.php:
--------------------------------------------------------------------------------
1 | getSecurity();
8 |
9 | return [
10 | 'username' => $faker->userName,
11 | 'email' => $faker->email,
12 | 'auth_key' => $security->generateRandomString(),
13 | 'password_hash' => $security->generatePasswordHash('password_' . $index),
14 | 'password_reset_token' => $security->generateRandomString() . '_' . time(),
15 | 'created_at' => time(),
16 | 'updated_at' => time(),
17 | ];
18 |
--------------------------------------------------------------------------------
/tests/codeception/common/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: UnitTester
7 |
--------------------------------------------------------------------------------
/tests/codeception/common/unit/DbTestCase.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 |
--------------------------------------------------------------------------------
/tests/codeception/common/unit/models/LoginFormTest.php:
--------------------------------------------------------------------------------
1 | [
25 | 'user' => [
26 | 'class' => 'yii\web\User',
27 | 'identityClass' => 'common\models\User',
28 | ],
29 | ],
30 | ]);
31 | }
32 |
33 | protected function tearDown()
34 | {
35 | Yii::$app->user->logout();
36 | parent::tearDown();
37 | }
38 |
39 | public function testLoginNoUser()
40 | {
41 | $model = new LoginForm([
42 | 'username' => 'not_existing_username',
43 | 'password' => 'not_existing_password',
44 | ]);
45 |
46 | $this->specify('user should not be able to login, when there is no identity', function () use ($model) {
47 | expect('model should not login user', $model->login())->false();
48 | expect('user should not be logged in', Yii::$app->user->isGuest)->true();
49 | });
50 | }
51 |
52 | public function testLoginWrongPassword()
53 | {
54 | $model = new LoginForm([
55 | 'username' => 'bayer.hudson',
56 | 'password' => 'wrong_password',
57 | ]);
58 |
59 | $this->specify('user should not be able to login with wrong password', function () use ($model) {
60 | expect('model should not login user', $model->login())->false();
61 | expect('error message should be set', $model->errors)->hasKey('password');
62 | expect('user should not be logged in', Yii::$app->user->isGuest)->true();
63 | });
64 | }
65 |
66 | public function testLoginCorrect()
67 | {
68 |
69 | $model = new LoginForm([
70 | 'username' => 'bayer.hudson',
71 | 'password' => 'password_0',
72 | ]);
73 |
74 | $this->specify('user should be able to login with correct credentials', function () use ($model) {
75 | expect('model should login user', $model->login())->true();
76 | expect('error message should not be set', $model->errors)->hasntKey('password');
77 | expect('user should be logged in', Yii::$app->user->isGuest)->false();
78 | });
79 | }
80 |
81 | /**
82 | * @inheritdoc
83 | */
84 | public function fixtures()
85 | {
86 | return [
87 | 'user' => [
88 | 'class' => UserFixture::className(),
89 | 'dataFile' => '@tests/codeception/common/unit/fixtures/data/models/user.php'
90 | ],
91 | ];
92 | }
93 | }
94 |
--------------------------------------------------------------------------------
/tests/codeception/config/.gitignore:
--------------------------------------------------------------------------------
1 | config-local.php
2 |
--------------------------------------------------------------------------------
/tests/codeception/config/acceptance.php:
--------------------------------------------------------------------------------
1 | 'app-common',
13 | 'basePath' => dirname(__DIR__),
14 | ]
15 | );
16 |
--------------------------------------------------------------------------------
/tests/codeception/config/config.php:
--------------------------------------------------------------------------------
1 | 'en-US',
7 | 'controllerMap' => [
8 | 'fixture' => [
9 | 'class' => 'yii\faker\FixtureController',
10 | 'fixtureDataPath' => '@tests/codeception/common/fixtures/data',
11 | 'templatePath' => '@tests/codeception/common/templates/fixtures',
12 | 'namespace' => 'tests\codeception\common\fixtures',
13 | ],
14 | ],
15 | 'components' => [
16 | 'db' => [
17 | 'dsn' => 'mysql:host=localhost;dbname=yii2_advanced_tests',
18 | ],
19 | 'mailer' => [
20 | 'useFileTransport' => true,
21 | ],
22 | 'urlManager' => [
23 | 'showScriptName' => true,
24 | ],
25 | ],
26 | ];
27 |
--------------------------------------------------------------------------------
/tests/codeception/config/console/unit.php:
--------------------------------------------------------------------------------
1 | [
7 | 'request' => [
8 | // it's not recommended to run functional tests with CSRF validation enabled
9 | 'enableCsrfValidation' => false,
10 | // but if you absolutely need it set cookie domain to localhost
11 | /*
12 | 'csrfCookie' => [
13 | 'domain' => 'localhost',
14 | ],
15 | */
16 | ],
17 | ],
18 | ];
--------------------------------------------------------------------------------
/tests/codeception/config/unit.php:
--------------------------------------------------------------------------------
1 | $value) {
24 | $inputType = $field === 'body' ? 'textarea' : 'input';
25 | $this->actor->fillField($inputType . '[name="' . $contactForm->formName() . '[' . $field . ']"]', $value);
26 | }
27 | $this->actor->click('contact-button');
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/tests/codeception/frontend/_pages/SignupPage.php:
--------------------------------------------------------------------------------
1 | $value) {
25 | $inputType = $field === 'body' ? 'textarea' : 'input';
26 | $this->actor->fillField($inputType . '[name="' . $signupForm->formName() . '[' . $field . ']"]', $value);
27 | }
28 | $this->actor->click('signup-button');
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/tests/codeception/frontend/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: AcceptanceTester
12 | modules:
13 | enabled:
14 | - PhpBrowser
15 | - tests\codeception\common\_support\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 | # PLEASE ADJUST IT TO THE ACTUAL ENTRY POINT WITHOUT PATH INFO
24 | url: http://localhost:8080
25 | # WebDriver:
26 | # url: http://localhost:8080
27 | # browser: firefox
28 | # restart: true
29 |
--------------------------------------------------------------------------------
/tests/codeception/frontend/acceptance/AboutCept.php:
--------------------------------------------------------------------------------
1 | wantTo('ensure that about works');
12 | AboutPage::openBy($I);
13 | $I->see('About', 'h1');
14 |
--------------------------------------------------------------------------------
/tests/codeception/frontend/acceptance/ContactCept.php:
--------------------------------------------------------------------------------
1 | wantTo('ensure that contact works');
12 |
13 | $contactPage = ContactPage::openBy($I);
14 |
15 | $I->see('Contact', 'h1');
16 |
17 | $I->amGoingTo('submit contact form with no data');
18 | $contactPage->submit([]);
19 | if (method_exists($I, 'wait')) {
20 | $I->wait(3); // only for selenium
21 | }
22 | $I->expectTo('see validations errors');
23 | $I->see('Contact', 'h1');
24 | $I->see('Name cannot be blank', '.help-block');
25 | $I->see('Email cannot be blank', '.help-block');
26 | $I->see('Subject cannot be blank', '.help-block');
27 | $I->see('Body cannot be blank', '.help-block');
28 | $I->see('The verification code is incorrect', '.help-block');
29 |
30 | $I->amGoingTo('submit contact form with not correct email');
31 | $contactPage->submit([
32 | 'name' => 'tester',
33 | 'email' => 'tester.email',
34 | 'subject' => 'test subject',
35 | 'body' => 'test content',
36 | 'verifyCode' => 'testme',
37 | ]);
38 | if (method_exists($I, 'wait')) {
39 | $I->wait(3); // only for selenium
40 | }
41 | $I->expectTo('see that email address is wrong');
42 | $I->dontSee('Name cannot be blank', '.help-block');
43 | $I->see('Email is not a valid email address.', '.help-block');
44 | $I->dontSee('Subject cannot be blank', '.help-block');
45 | $I->dontSee('Body cannot be blank', '.help-block');
46 | $I->dontSee('The verification code is incorrect', '.help-block');
47 |
48 | $I->amGoingTo('submit contact form with correct data');
49 | $contactPage->submit([
50 | 'name' => 'tester',
51 | 'email' => 'tester@example.com',
52 | 'subject' => 'test subject',
53 | 'body' => 'test content',
54 | 'verifyCode' => 'testme',
55 | ]);
56 | if (method_exists($I, 'wait')) {
57 | $I->wait(3); // only for selenium
58 | }
59 | $I->see('Thank you for contacting us. We will respond to you as soon as possible.');
60 |
--------------------------------------------------------------------------------
/tests/codeception/frontend/acceptance/HomeCept.php:
--------------------------------------------------------------------------------
1 | wantTo('ensure that home page works');
12 | $I->amOnPage(Yii::$app->homeUrl);
13 | $I->see('My Company');
14 | $I->seeLink('About');
15 | $I->click('About');
16 | $I->see('This is the About page.');
17 |
--------------------------------------------------------------------------------
/tests/codeception/frontend/acceptance/LoginCept.php:
--------------------------------------------------------------------------------
1 | wantTo('ensure login page works');
12 |
13 | $loginPage = LoginPage::openBy($I);
14 |
15 | $I->amGoingTo('submit login form with no data');
16 | $loginPage->login('', '');
17 | $I->expectTo('see validations errors');
18 | $I->see('Username cannot be blank.', '.help-block');
19 | $I->see('Password cannot be blank.', '.help-block');
20 |
21 | $I->amGoingTo('try to login with wrong credentials');
22 | $I->expectTo('see validations errors');
23 | $loginPage->login('admin', 'wrong');
24 | $I->expectTo('see validations errors');
25 | $I->see('Incorrect username or password.', '.help-block');
26 |
27 | $I->amGoingTo('try to login with correct credentials');
28 | $loginPage->login('erau', 'password_0');
29 | $I->expectTo('see that user is logged');
30 | $I->see('Logout (erau)', 'form button[type=submit]');
31 | $I->dontSeeLink('Login');
32 | $I->dontSeeLink('Signup');
33 | /** Uncomment if using WebDriver
34 | * $I->click('Logout (erau)');
35 | * $I->dontSeeLink('Logout (erau)');
36 | * $I->seeLink('Login');
37 | */
38 |
--------------------------------------------------------------------------------
/tests/codeception/frontend/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\FailEvent $event
34 | */
35 | public function _fail($event)
36 | {
37 | }
38 |
39 | /**
40 | * @param \tests\codeception\frontend\AcceptanceTester $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->see('Logout (tester)', 'form button[type=submit]');
81 | }
82 | }
83 |
--------------------------------------------------------------------------------
/tests/codeception/frontend/acceptance/_bootstrap.php:
--------------------------------------------------------------------------------
1 | wantTo('ensure that about works');
12 | AboutPage::openBy($I);
13 | $I->see('About', 'h1');
14 |
--------------------------------------------------------------------------------
/tests/codeception/frontend/functional/ContactCept.php:
--------------------------------------------------------------------------------
1 | wantTo('ensure that contact works');
12 |
13 | $contactPage = ContactPage::openBy($I);
14 |
15 | $I->see('Contact', 'h1');
16 |
17 | $I->amGoingTo('submit contact form with no data');
18 | $contactPage->submit([]);
19 | $I->expectTo('see validations errors');
20 | $I->see('Contact', 'h1');
21 | $I->see('Name cannot be blank', '.help-block');
22 | $I->see('Email cannot be blank', '.help-block');
23 | $I->see('Subject cannot be blank', '.help-block');
24 | $I->see('Body cannot be blank', '.help-block');
25 | $I->see('The verification code is incorrect', '.help-block');
26 |
27 | $I->amGoingTo('submit contact form with not correct email');
28 | $contactPage->submit([
29 | 'name' => 'tester',
30 | 'email' => 'tester.email',
31 | 'subject' => 'test subject',
32 | 'body' => 'test content',
33 | 'verifyCode' => 'testme',
34 | ]);
35 | $I->expectTo('see that email address is wrong');
36 | $I->dontSee('Name cannot be blank', '.help-block');
37 | $I->see('Email is not a valid email address.', '.help-block');
38 | $I->dontSee('Subject cannot be blank', '.help-block');
39 | $I->dontSee('Body cannot be blank', '.help-block');
40 | $I->dontSee('The verification code is incorrect', '.help-block');
41 |
42 | $I->amGoingTo('submit contact form with correct data');
43 | $contactPage->submit([
44 | 'name' => 'tester',
45 | 'email' => 'tester@example.com',
46 | 'subject' => 'test subject',
47 | 'body' => 'test content',
48 | 'verifyCode' => 'testme',
49 | ]);
50 | $I->see('Thank you for contacting us. We will respond to you as soon as possible.');
51 |
--------------------------------------------------------------------------------
/tests/codeception/frontend/functional/HomeCept.php:
--------------------------------------------------------------------------------
1 | wantTo('ensure that home page works');
12 | $I->amOnPage(Yii::$app->homeUrl);
13 | $I->see('My Company');
14 | $I->seeLink('About');
15 | $I->click('About');
16 | $I->see('This is the About page.');
17 |
--------------------------------------------------------------------------------
/tests/codeception/frontend/functional/LoginCept.php:
--------------------------------------------------------------------------------
1 | wantTo('ensure login page works');
12 |
13 | $loginPage = LoginPage::openBy($I);
14 |
15 | $I->amGoingTo('submit login form with no data');
16 | $loginPage->login('', '');
17 | $I->expectTo('see validations errors');
18 | $I->see('Username cannot be blank.', '.help-block');
19 | $I->see('Password cannot be blank.', '.help-block');
20 |
21 | $I->amGoingTo('try to login with wrong credentials');
22 | $I->expectTo('see validations errors');
23 | $loginPage->login('admin', 'wrong');
24 | $I->expectTo('see validations errors');
25 | $I->see('Incorrect username or password.', '.help-block');
26 |
27 | $I->amGoingTo('try to login with correct credentials');
28 | $loginPage->login('erau', 'password_0');
29 | $I->expectTo('see that user is logged');
30 | $I->see('Logout (erau)', 'form button[type=submit]');
31 | $I->dontSeeLink('Login');
32 | $I->dontSeeLink('Signup');
33 |
--------------------------------------------------------------------------------
/tests/codeception/frontend/functional/SignupCest.php:
--------------------------------------------------------------------------------
1 | loadFixtures();
27 | }
28 |
29 | /**
30 | * This method is called when test fails.
31 | * @param \tests\codeception\frontend\FunctionalTester $I
32 | */
33 | public function _failed($I)
34 | {
35 |
36 | }
37 |
38 | /**
39 | *
40 | * @param \tests\codeception\frontend\FunctionalTester $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 is created');
80 | $I->seeRecord('common\models\User', [
81 | 'username' => 'tester',
82 | 'email' => 'tester.email@example.com',
83 | ]);
84 |
85 | $I->expectTo('see that user logged in');
86 | $I->see('Logout (tester)', 'form button[type=submit]');
87 | }
88 | }
89 |
--------------------------------------------------------------------------------
/tests/codeception/frontend/functional/_bootstrap.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 |
--------------------------------------------------------------------------------
/tests/codeception/frontend/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 |
--------------------------------------------------------------------------------
/tests/codeception/frontend/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 sent', function () {
35 |
36 | $model = new PasswordResetRequestForm();
37 | $model->email = 'not-existing-email@example.com';
38 |
39 | expect('email not sent', $model->sendEmail())->false();
40 |
41 | });
42 |
43 | $this->specify('user is not active, message should not be sent', function () {
44 |
45 | $model = new PasswordResetRequestForm();
46 | $model->email = $this->user[1]['email'];
47 |
48 | expect('email not sent', $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' => '@tests/codeception/frontend/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 |
--------------------------------------------------------------------------------
/tests/codeception/frontend/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' => '@tests/codeception/frontend/unit/fixtures/data/models/user.php'
40 | ],
41 | ];
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/tests/codeception/frontend/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' => '@tests/codeception/frontend/unit/fixtures/data/models/user.php',
49 | ],
50 | ];
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/vagrant/config/.gitignore:
--------------------------------------------------------------------------------
1 | # local configuration
2 | vagrant-local.yml
--------------------------------------------------------------------------------
/vagrant/config/vagrant-local.example.yml:
--------------------------------------------------------------------------------
1 | # Your personal GitHub token
2 | github_token:
3 | # Read more: https://github.com/blog/1509-personal-api-tokens
4 | # You can generate it here: https://github.com/settings/tokens
5 |
6 | # Guest OS timezone
7 | timezone: Europe/London
8 |
9 | # Are we need check box updates for every 'vagrant up'?
10 | box_check_update: false
11 |
12 | # Virtual machine name
13 | machine_name: y2aa
14 |
15 | # Virtual machine IP
16 | ip: 192.168.83.137
17 |
18 | # Virtual machine CPU cores number
19 | cpus: 1
20 |
21 | # Virtual machine RAM
22 | memory: 512
23 |
--------------------------------------------------------------------------------
/vagrant/nginx/app.conf:
--------------------------------------------------------------------------------
1 | server {
2 | charset utf-8;
3 | client_max_body_size 128M;
4 |
5 | listen 80; ## listen for ipv4
6 | #listen [::]:80 default_server ipv6only=on; ## listen for ipv6
7 |
8 | server_name y2aa-frontend.dev;
9 | root /app/frontend/web/;
10 | index index.php;
11 |
12 | access_log /app/vagrant/nginx/log/frontend-access.log;
13 | error_log /app/vagrant/nginx/log/frontend-error.log;
14 |
15 | location / {
16 | # Redirect everything that isn't a real file to index.php
17 | try_files $uri $uri/ /index.php$is_args$args;
18 | }
19 |
20 | # uncomment to avoid processing of calls to non-existing static files by Yii
21 | #location ~ \.(js|css|png|jpg|gif|swf|ico|pdf|mov|fla|zip|rar)$ {
22 | # try_files $uri =404;
23 | #}
24 | #error_page 404 /404.html;
25 |
26 | location ~ \.php$ {
27 | include fastcgi_params;
28 | fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
29 | #fastcgi_pass 127.0.0.1:9000;
30 | fastcgi_pass unix:/var/run/php5-fpm.sock;
31 | try_files $uri =404;
32 | }
33 |
34 | location ~ /\.(ht|svn|git) {
35 | deny all;
36 | }
37 | }
38 |
39 | server {
40 | charset utf-8;
41 | client_max_body_size 128M;
42 |
43 | listen 80; ## listen for ipv4
44 | #listen [::]:80 default_server ipv6only=on; ## listen for ipv6
45 |
46 | server_name y2aa-backend.dev;
47 | root /app/backend/web/;
48 | index index.php;
49 |
50 | access_log /app/vagrant/nginx/log/backend-access.log;
51 | error_log /app/vagrant/nginx/log/backend-error.log;
52 |
53 | location / {
54 | # Redirect everything that isn't a real file to index.php
55 | try_files $uri $uri/ /index.php$is_args$args;
56 | }
57 |
58 | # uncomment to avoid processing of calls to non-existing static files by Yii
59 | #location ~ \.(js|css|png|jpg|gif|swf|ico|pdf|mov|fla|zip|rar)$ {
60 | # try_files $uri =404;
61 | #}
62 | #error_page 404 /404.html;
63 |
64 | location ~ \.php$ {
65 | include fastcgi_params;
66 | fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
67 | #fastcgi_pass 127.0.0.1:9000;
68 | fastcgi_pass unix:/var/run/php5-fpm.sock;
69 | try_files $uri =404;
70 | }
71 |
72 | location ~ /\.(ht|svn|git) {
73 | deny all;
74 | }
75 | }
76 |
--------------------------------------------------------------------------------
/vagrant/nginx/log/.gitignore:
--------------------------------------------------------------------------------
1 | # nginx logs
2 | backend-access.log
3 | backend-error.log
4 | frontend-access.log
5 | frontend-error.log
--------------------------------------------------------------------------------
/vagrant/provision/always-as-root.sh:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | #== Bash helpers ==
4 |
5 | function info {
6 | echo " "
7 | echo "--> $1"
8 | echo " "
9 | }
10 |
11 | #== Provision script ==
12 |
13 | info "Provision-script user: `whoami`"
14 |
15 | info "Restart web-stack"
16 | service php5-fpm restart
17 | service nginx restart
18 | service mysql restart
--------------------------------------------------------------------------------
/vagrant/provision/once-as-root.sh:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | #== Import script args ==
4 |
5 | timezone=$(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 "Allocate swap for MySQL 5.6"
20 | fallocate -l 2048M /swapfile
21 | chmod 600 /swapfile
22 | mkswap /swapfile
23 | swapon /swapfile
24 | echo '/swapfile none swap defaults 0 0' >> /etc/fstab
25 |
26 | info "Configure locales"
27 | update-locale LC_ALL="C"
28 | dpkg-reconfigure locales
29 |
30 | info "Configure timezone"
31 | echo ${timezone} | tee /etc/timezone
32 | dpkg-reconfigure --frontend noninteractive tzdata
33 |
34 | info "Prepare root password for MySQL"
35 | debconf-set-selections <<< "mysql-server-5.6 mysql-server/root_password password \"''\""
36 | debconf-set-selections <<< "mysql-server-5.6 mysql-server/root_password_again password \"''\""
37 | echo "Done!"
38 |
39 | info "Update OS software"
40 | apt-get update
41 | apt-get upgrade -y
42 |
43 | info "Install additional software"
44 | apt-get install -y git php5-curl php5-cli php5-intl php5-mysqlnd php5-gd php5-fpm nginx mysql-server-5.6
45 |
46 | info "Configure MySQL"
47 | sed -i "s/.*bind-address.*/bind-address = 0.0.0.0/" /etc/mysql/my.cnf
48 | echo "Done!"
49 |
50 | info "Configure PHP-FPM"
51 | sed -i 's/user = www-data/user = vagrant/g' /etc/php5/fpm/pool.d/www.conf
52 | sed -i 's/group = www-data/group = vagrant/g' /etc/php5/fpm/pool.d/www.conf
53 | sed -i 's/owner = www-data/owner = vagrant/g' /etc/php5/fpm/pool.d/www.conf
54 | echo "Done!"
55 |
56 | info "Configure NGINX"
57 | sed -i 's/user www-data/user vagrant/g' /etc/nginx/nginx.conf
58 | echo "Done!"
59 |
60 | info "Enabling site configuration"
61 | ln -s /app/vagrant/nginx/app.conf /etc/nginx/sites-enabled/app.conf
62 | echo "Done!"
63 |
64 | info "Initailize databases for MySQL"
65 | mysql -uroot <<< "CREATE DATABASE yii2advanced"
66 | mysql -uroot <<< "CREATE DATABASE yii2_advanced_tests"
67 | echo "Done!"
68 |
69 | info "Install composer"
70 | curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
--------------------------------------------------------------------------------
/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 plugins for composer"
24 | composer global require "fxp/composer-asset-plugin:~1.1.1" --no-progress
25 |
26 | info "Install codeception"
27 | composer global require "codeception/codeception=2.0.*" "codeception/specify=*" "codeception/verify=*" --no-progress
28 | echo 'export PATH=/home/vagrant/.config/composer/vendor/bin:$PATH' | tee -a /home/vagrant/.profile
29 |
30 | info "Install project dependencies"
31 | cd /app
32 | composer --no-progress --prefer-dist install
33 |
34 | info "Init project"
35 | ./init --env=Development --overwrite=y
36 |
37 | info "Apply migrations"
38 | ./yii migrate <<< "yes"
39 |
40 | info "Create bash-alias 'app' for vagrant user"
41 | echo 'alias app="cd /app"' | tee /home/vagrant/.bash_aliases
42 |
43 | info "Enabling colorized prompt for guest console"
44 | sed -i "s/#force_color_prompt=yes/force_color_prompt=yes/" /home/vagrant/.bashrc
--------------------------------------------------------------------------------
/yii:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env php
2 | run();
28 | exit($exitCode);
29 |
--------------------------------------------------------------------------------
/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 (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" %*
19 |
20 | @endlocal
21 |
--------------------------------------------------------------------------------