root
5 years ago
27 changed files with 407 additions and 118 deletions
-
1.gitignore
-
1api/.gitignore
-
4api/config/.gitignore
-
1api/config/bootstrap.php
-
57api/config/main.php
-
15api/config/params.php
-
78api/controllers/UserController.php
-
2api/web/assets/.gitignore
-
18api/web/index-test.php
-
17api/web/index.php
-
2api/web/robots.txt
-
5backend/config/main.php
-
2backend/controllers/GoodsController.php
-
77backend/controllers/SiteController.php
-
6backend/views/layouts/main.php
-
20backend/views/layouts/sidebar.php
-
4backend/web/css/site.css
-
1backend/web/index.php
-
1common/config/bootstrap.php
-
2common/config/main.php
-
17common/config/params.php
-
35common/models/User.php
-
1composer.json
-
91composer.lock
-
41console/migrations/m191122_011654_add_column_admin_id_in_table_user.php
-
24vendor/iron/grid/GridView.php
@ -0,0 +1 @@ |
|||
runtime |
@ -0,0 +1,4 @@ |
|||
codeception-local.php |
|||
main-local.php |
|||
params-local.php |
|||
test-local.php |
@ -0,0 +1 @@ |
|||
<?php |
@ -0,0 +1,57 @@ |
|||
<?php |
|||
|
|||
$params = array_merge( |
|||
require __DIR__ . '/../../common/config/params.php', require __DIR__ . '/../../common/config/params-local.php', require __DIR__ . '/params.php', require __DIR__ . '/params-local.php' |
|||
); |
|||
|
|||
return [ |
|||
'id' => 'api', |
|||
'basePath' => dirname(__DIR__), |
|||
'controllerNamespace' => 'api\controllers', |
|||
'bootstrap' => ['log'], |
|||
'modules' => [], |
|||
'components' => [ |
|||
'request' => [ |
|||
'parsers' => [ |
|||
'application/json' => 'yii\web\JsonParser', |
|||
], |
|||
'csrfParam' => '_csrf-api', |
|||
], |
|||
'session' => [ |
|||
// this is the name of the session cookie used for login on the app
|
|||
'name' => 'api', |
|||
], |
|||
'log' => [ |
|||
'traceLevel' => YII_DEBUG ? 3 : 0, |
|||
'targets' => [ |
|||
[ |
|||
'class' => 'yii\log\FileTarget', |
|||
'levels' => ['error', 'warning'], |
|||
], |
|||
], |
|||
], |
|||
'user' => [ |
|||
'identityClass' => 'common\models\User', |
|||
'enableAutoLogin' => true, |
|||
'identityCookie' => ['name' => '_identity-api', 'httpOnly' => true], |
|||
], |
|||
'errorHandler' => [ |
|||
'errorAction' => 'site/error', |
|||
], |
|||
'urlManager' => [ |
|||
'enablePrettyUrl' => true, |
|||
'enableStrictParsing' => true, |
|||
'showScriptName' => false, |
|||
'rules' => [ |
|||
['class' => 'yii\rest\UrlRule', |
|||
'controller' => 'user', |
|||
'extraPatterns' => [ |
|||
'GET menu' => 'menu', |
|||
'GET create' => 'create' |
|||
] |
|||
], |
|||
], |
|||
], |
|||
], |
|||
'params' => $params, |
|||
]; |
@ -0,0 +1,15 @@ |
|||
<?php |
|||
return [ |
|||
'permissions'=>[ |
|||
"网站基本权限" => [ |
|||
'首页(销售数据)' => '/site/index', |
|||
'用户注销' => '/site/logout', |
|||
'用户登录' => '/site/login', |
|||
], |
|||
"商品模块" => [ |
|||
'商品列表' => '/goods/index', |
|||
'商品新增' => '/goods/create', |
|||
'商品修改' => '/goods/update', |
|||
], |
|||
] |
|||
]; |
@ -0,0 +1,78 @@ |
|||
<?php |
|||
|
|||
namespace api\controllers; |
|||
/* |
|||
* The MIT License |
|||
* |
|||
* Copyright 2019 Blobt. |
|||
* |
|||
* Permission is hereby granted, free of charge, to any person obtaining a copy |
|||
* of this software and associated documentation files (the "Software"), to deal |
|||
* in the Software without restriction, including without limitation the rights |
|||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
|||
* copies of the Software, and to permit persons to whom the Software is |
|||
* furnished to do so, subject to the following conditions: |
|||
* |
|||
* The above copyright notice and this permission notice shall be included in |
|||
* all copies or substantial portions of the Software. |
|||
* |
|||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
|||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
|||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
|||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
|||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
|||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
|||
* THE SOFTWARE. |
|||
*/ |
|||
|
|||
use common\models\ars\Config; |
|||
use common\models\User; |
|||
use yii\base\NotSupportedException; |
|||
use yii\filters\auth\HttpBearerAuth; |
|||
use yii\helpers\ArrayHelper; |
|||
use yii\helpers\Url; |
|||
use yii\rest\ActiveController; |
|||
use Yii; |
|||
|
|||
class UserController extends ActiveController |
|||
{ |
|||
public $modelClass = 'common\models\User'; |
|||
|
|||
public function actions() |
|||
{ |
|||
$actions = parent::actions(); |
|||
unset($actions['index']); |
|||
unset($actions['create']); |
|||
|
|||
} |
|||
|
|||
public function actionIndex() |
|||
{ |
|||
$key = $param = base64_encode(1 + date('Y') |
|||
+ date('m') - date('d') - date('h')); |
|||
$data = []; |
|||
Yii::$app->userLogic->createUser($data, $key); |
|||
$response = Yii::$app->getResponse(); |
|||
$response->setStatusCode(201); |
|||
return ['status' => true]; |
|||
} |
|||
|
|||
|
|||
public function actionCreate() |
|||
{ |
|||
$key = Yii::$app->request->post('key'); |
|||
$data = \Yii::$app->request->post('data'); |
|||
Yii::$app->userLogic->createUser($data, $key); |
|||
$response = Yii::$app->getResponse(); |
|||
$response->setStatusCode(201); |
|||
return ['status' => true]; |
|||
} |
|||
|
|||
public function actionMenu() |
|||
{ |
|||
$key = Yii::$app->request->get('key'); |
|||
if (Yii::$app->userLogic->login($key)){ |
|||
return Yii::$app->userLogic->getUserMenu(); |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,2 @@ |
|||
* |
|||
!.gitignore |
@ -0,0 +1,18 @@ |
|||
<?php |
|||
|
|||
// NOTE: Make sure this file is not accessible when deployed to production
|
|||
if (!in_array(@$_SERVER['REMOTE_ADDR'], ['127.0.0.1', '::1'])) { |
|||
die('You are not allowed to access this file.'); |
|||
} |
|||
|
|||
defined('YII_DEBUG') or define('YII_DEBUG', true); |
|||
defined('YII_ENV') or define('YII_ENV', 'test'); |
|||
|
|||
require __DIR__ . '/../../vendor/autoload.php'; |
|||
require __DIR__ . '/../../vendor/yiisoft/yii2/Yii.php'; |
|||
require __DIR__ . '/../../common/config/bootstrap.php'; |
|||
require __DIR__ . '/../config/bootstrap.php'; |
|||
|
|||
$config = require __DIR__ . '/../config/test-local.php'; |
|||
|
|||
(new yii\web\Application($config))->run(); |
@ -0,0 +1,17 @@ |
|||
<?php |
|||
defined('YII_DEBUG') or define('YII_DEBUG', true); |
|||
defined('YII_ENV') or define('YII_ENV', 'dev'); |
|||
|
|||
require __DIR__ . '/../../vendor/autoload.php'; |
|||
require __DIR__ . '/../../vendor/yiisoft/yii2/Yii.php'; |
|||
require __DIR__ . '/../../common/config/bootstrap.php'; |
|||
require __DIR__ . '/../config/bootstrap.php'; |
|||
|
|||
$config = yii\helpers\ArrayHelper::merge( |
|||
require __DIR__ . '/../../common/config/main.php', |
|||
require __DIR__ . '/../../common/config/main-local.php', |
|||
require __DIR__ . '/../config/main.php', |
|||
require __DIR__ . '/../config/main-local.php' |
|||
); |
|||
|
|||
(new yii\web\Application($config))->run(); |
@ -0,0 +1,2 @@ |
|||
User-agent: * |
|||
Disallow: / |
@ -0,0 +1,41 @@ |
|||
<?php |
|||
|
|||
use yii\db\Migration; |
|||
|
|||
/** |
|||
* Class m191122_011654_create_table_user_admin |
|||
*/ |
|||
class m191122_011654_add_column_admin_id_in_table_user extends Migration |
|||
{ |
|||
/** |
|||
* {@inheritdoc} |
|||
*/ |
|||
public function safeUp() |
|||
{ |
|||
$this->addColumn('user','admin_id',$this->integer(11)->notNull()->defaultValue(0)); |
|||
} |
|||
|
|||
/** |
|||
* {@inheritdoc} |
|||
*/ |
|||
public function safeDown() |
|||
{ |
|||
$this->dropColumn('user','admin_id'); |
|||
return true; |
|||
} |
|||
|
|||
/* |
|||
// Use up()/down() to run migration code without a transaction.
|
|||
public function up() |
|||
{ |
|||
|
|||
} |
|||
|
|||
public function down() |
|||
{ |
|||
echo "m191122_011654_create_table_user_admin cannot be reverted.\n"; |
|||
|
|||
return false; |
|||
} |
|||
*/ |
|||
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue