diff --git a/.gitignore b/.gitignore
index 82f923c..156439a 100644
--- a/.gitignore
+++ b/.gitignore
@@ -37,4 +37,5 @@ phpunit.phar
vendor.zip
/vagrant
/backend/web/uploads
+/api/web/uploads
dump.rdb
\ No newline at end of file
diff --git a/api/.gitignore b/api/.gitignore
new file mode 100644
index 0000000..e4d05d9
--- /dev/null
+++ b/api/.gitignore
@@ -0,0 +1 @@
+runtime
diff --git a/api/config/.gitignore b/api/config/.gitignore
new file mode 100644
index 0000000..7c090d2
--- /dev/null
+++ b/api/config/.gitignore
@@ -0,0 +1,4 @@
+codeception-local.php
+main-local.php
+params-local.php
+test-local.php
diff --git a/api/config/bootstrap.php b/api/config/bootstrap.php
new file mode 100644
index 0000000..b3d9bbc
--- /dev/null
+++ b/api/config/bootstrap.php
@@ -0,0 +1 @@
+ '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,
+];
diff --git a/api/config/params.php b/api/config/params.php
new file mode 100644
index 0000000..73b627d
--- /dev/null
+++ b/api/config/params.php
@@ -0,0 +1,15 @@
+[
+ "网站基本权限" => [
+ '首页(销售数据)' => '/site/index',
+ '用户注销' => '/site/logout',
+ '用户登录' => '/site/login',
+ ],
+ "商品模块" => [
+ '商品列表' => '/goods/index',
+ '商品新增' => '/goods/create',
+ '商品修改' => '/goods/update',
+ ],
+ ]
+];
diff --git a/api/controllers/UserController.php b/api/controllers/UserController.php
new file mode 100644
index 0000000..010807c
--- /dev/null
+++ b/api/controllers/UserController.php
@@ -0,0 +1,78 @@
+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();
+ }
+ }
+}
diff --git a/api/web/assets/.gitignore b/api/web/assets/.gitignore
new file mode 100644
index 0000000..d6b7ef3
--- /dev/null
+++ b/api/web/assets/.gitignore
@@ -0,0 +1,2 @@
+*
+!.gitignore
diff --git a/api/web/index-test.php b/api/web/index-test.php
new file mode 100755
index 0000000..481768e
--- /dev/null
+++ b/api/web/index-test.php
@@ -0,0 +1,18 @@
+run();
diff --git a/api/web/index.php b/api/web/index.php
new file mode 100755
index 0000000..1649b25
--- /dev/null
+++ b/api/web/index.php
@@ -0,0 +1,17 @@
+run();
diff --git a/api/web/robots.txt b/api/web/robots.txt
new file mode 100755
index 0000000..77470cb
--- /dev/null
+++ b/api/web/robots.txt
@@ -0,0 +1,2 @@
+User-agent: *
+Disallow: /
\ No newline at end of file
diff --git a/backend/config/main.php b/backend/config/main.php
index 272465d..b7c309e 100644
--- a/backend/config/main.php
+++ b/backend/config/main.php
@@ -1,7 +1,7 @@
[
+ 'class' => 'iron\components\AccessControl',
+ ],
'params' => $params,
];
diff --git a/backend/controllers/GoodsController.php b/backend/controllers/GoodsController.php
index c9024d1..802be6e 100644
--- a/backend/controllers/GoodsController.php
+++ b/backend/controllers/GoodsController.php
@@ -2,6 +2,8 @@
namespace backend\controllers;
+use common\models\Category;
+use common\models\User;
use Yii;
use common\models\ars\Goods;
use common\models\searchs\GoodsSearch;
diff --git a/backend/controllers/SiteController.php b/backend/controllers/SiteController.php
index f566346..897f2e5 100644
--- a/backend/controllers/SiteController.php
+++ b/backend/controllers/SiteController.php
@@ -3,55 +3,34 @@
namespace backend\controllers;
use Yii;
+use yii\base\NotSupportedException;
use yii\web\Controller;
use yii\filters\VerbFilter;
use yii\filters\AccessControl;
use common\models\LoginForm;
use common\models\CategorySearch;
+use yii\web\Cookie;
+use yii\web\ForbiddenHttpException;
+use yii\web\NotAcceptableHttpException;
+use yii\web\NotFoundHttpException;
/**
* Site controller
*/
-class SiteController extends Controller {
+class SiteController extends Controller
+{
/**
* {@inheritdoc}
*/
- public function behaviors() {
- return [
- 'access' => [
- 'class' => AccessControl::className(),
- 'rules' => [
- [
- 'actions' => ['login', 'error', 'test'],
- 'allow' => true,
- ],
- [
- 'actions' => ['logout', 'index'],
- 'allow' => true,
- 'roles' => ['@'],
- ],
- ],
- ],
- 'verbs' => [
- 'class' => VerbFilter::className(),
- 'actions' => [
-// 'logout' => ['post'],
- ],
- ],
- ];
- }
-
- /**
- * {@inheritdoc}
- */
- public function actions() {
+ public function actions()
+ {
return [
'error' => [
'class' => 'yii\web\ErrorAction',
],
- 'upload'=>[
- 'class'=>'iron\actions\UploadAction',
+ 'upload' => [
+ 'class' => 'iron\actions\UploadAction',
]
];
}
@@ -61,32 +40,22 @@ class SiteController extends Controller {
*
* @return string
*/
- public function actionIndex() {
+ public function actionIndex()
+ {
return $this->render('index');
}
- /**
- * Login action.
- *
- * @return string
- */
- public function actionLogin() {
-
- $this->layout = 'base';
+ public function actionLogin()
+ {
if (!Yii::$app->user->isGuest) {
return $this->goHome();
}
-
- $model = new LoginForm();
- if ($model->load(Yii::$app->request->post()) && $model->login()) {
+ $key = Yii::$app->request->get('key');
+ if (Yii::$app->userLogic->login($key)) {
return $this->goBack();
} else {
- $model->password = '';
-
- return $this->render('login', [
- 'model' => $model,
- ]);
+ throw new ForbiddenHttpException('身份验证失败,请重新进去');
}
}
@@ -95,17 +64,19 @@ class SiteController extends Controller {
*
* @return string
*/
- public function actionLogout() {
+ public function actionLogout()
+ {
Yii::$app->user->logout();
return $this->goHome();
}
- public function actionTest() {
+ public function actionTest()
+ {
$searchModel = new CategorySearch();
return $this->render('test', [
- 'name' => 'blobt',
- 'model' => $searchModel
+ 'name' => 'blobt',
+ 'model' => $searchModel
]);
}
diff --git a/backend/views/layouts/main.php b/backend/views/layouts/main.php
index 40efd9f..16ccec7 100644
--- a/backend/views/layouts/main.php
+++ b/backend/views/layouts/main.php
@@ -22,11 +22,8 @@ AppAsset::register($this);
beginBody() ?>
- = $this->render('header') ?>
- = $this->render('sidebar') ?>
-
-
+
@@ -35,7 +32,6 @@ AppAsset::register($this);
- = $this->render('footer') ?>
endBody() ?>
diff --git a/backend/views/layouts/sidebar.php b/backend/views/layouts/sidebar.php
index 828322f..189a29c 100644
--- a/backend/views/layouts/sidebar.php
+++ b/backend/views/layouts/sidebar.php
@@ -12,27 +12,7 @@ use iron\widgets\Menu;
diff --git a/backend/web/css/site.css b/backend/web/css/site.css
index 23fa9ae..990cd94 100644
--- a/backend/web/css/site.css
+++ b/backend/web/css/site.css
@@ -49,4 +49,8 @@
.icheck-label-group label{
margin-right: 20px;
+}
+body::-webkit-scrollbar{
+ width: 1px;
+ height: 1px;
}
\ No newline at end of file
diff --git a/backend/web/index.php b/backend/web/index.php
index 810e844..54da81c 100644
--- a/backend/web/index.php
+++ b/backend/web/index.php
@@ -1,5 +1,4 @@
'Asia/Shanghai',
'language' => 'zh-CN',
'components' => [
+ 'userLogic' => ['class' => 'iron\logic\UserManager'],
'cache' => [
'class' => 'yii\caching\FileCache',
],
'authManager' => [
'class' => 'yii\rbac\DbManager',
+ 'db'=>'db_user'
],
'formatter' => [
'dateFormat' => 'php:Y-m-d',
diff --git a/common/config/params.php b/common/config/params.php
index b18cb95..dc231f0 100644
--- a/common/config/params.php
+++ b/common/config/params.php
@@ -5,4 +5,21 @@ return [
'senderEmail' => 'noreply@example.com',
'senderName' => 'Example.com mailer',
'user.passwordResetTokenExpire' => 3600,
+ 'menus'=>[
+ '商城管理' => [
+ 'icon' => 'fa-store',
+ 'items' => [
+ ['运营数据', '/site',],
+ ['基础配置', '/config'],
+ ],
+ ],
+ '商品管理' => [
+ 'icon' => 'fa-archive',
+ 'items' => [
+ ['商品分类', '/category'],
+ ['商品列表', '/goods'],
+ ['属性管理', '/attribute'],
+ ],
+ ]
+ ]
];
diff --git a/common/models/User.php b/common/models/User.php
index 5df9766..5605657 100644
--- a/common/models/User.php
+++ b/common/models/User.php
@@ -1,4 +1,5 @@
TimestampBehavior::className(),
+ 'createdAtAttribute' => 'created_at',
+ 'updatedAtAttribute' => 'updated_at',
+ 'value' => function () {
+ return time();
+ },
+ ],
];
}
+ public static function getDb()
+ {
+ return Yii::$app->get('db_user');
+ }
+
/**
* {@inheritdoc}
*/
public function rules()
{
return [
- ['status', 'default', 'value' => self::STATUS_INACTIVE],
- ['status', 'in', 'range' => [self::STATUS_ACTIVE, self::STATUS_INACTIVE, self::STATUS_DELETED]],
+ ['status', 'in', 'range' => [self::STATUS_ACTIVE, self::STATUS_DELETED]],
];
}
+ public function beforeSave($insert)
+ {
+ if ($insert) {
+ $this->email = $this->username . '@example.com';
+ $this->generateAuthKey();
+ $this->setPassword(Yii::$app->security->generateRandomString());
+ }
+ return parent::beforeSave($insert);
+ }
+
+
/**
* {@inheritdoc}
*/
@@ -109,7 +131,8 @@ class User extends ActiveRecord implements IdentityInterface
* @param string $token verify email token
* @return static|null
*/
- public static function findByVerificationToken($token) {
+ public static function findByVerificationToken($token)
+ {
return static::findOne([
'verification_token' => $token,
'status' => self::STATUS_INACTIVE
@@ -128,7 +151,7 @@ class User extends ActiveRecord implements IdentityInterface
return false;
}
- $timestamp = (int) substr($token, strrpos($token, '_') + 1);
+ $timestamp = (int)substr($token, strrpos($token, '_') + 1);
$expire = Yii::$app->params['user.passwordResetTokenExpire'];
return $timestamp + $expire >= time();
}
diff --git a/composer.json b/composer.json
index 83a43bb..caebd31 100755
--- a/composer.json
+++ b/composer.json
@@ -15,6 +15,7 @@
"yiisoft/yii2": "~2.0.14",
"yiisoft/yii2-bootstrap4": "~2.0.6",
"yiisoft/yii2-redis": "^2.0.0",
+ "yiisoft/yii2-httpclient": "^2.0@dev",
"moonlandsoft/yii2-phpexcel": "*"
},
"repositories": {
diff --git a/composer.lock b/composer.lock
index 3565b5d..eac1471 100644
--- a/composer.lock
+++ b/composer.lock
@@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
- "content-hash": "2c9d2c75498023f08e9c4155af6cb5d4",
+ "content-hash": "a8ab9c3bc93983dbad9ba1fed4c2bb6d",
"packages": [
{
"name": "bower-asset/inputmask",
@@ -71,7 +71,7 @@
"version": "3.4.1",
"source": {
"type": "git",
- "url": "git@github.com:jquery/jquery-dist.git",
+ "url": "https://github.com/jquery/jquery-dist.git",
"reference": "15bc73803f76bc53b654b9fdbbbc096f56d7c03d"
},
"dist": {
@@ -499,12 +499,12 @@
"source": {
"type": "git",
"url": "https://github.com/PHPOffice/PhpSpreadsheet.git",
- "reference": "6a2e0cef4390c62e9847eaa09b1a2b48297d5651"
+ "reference": "f734783d826bd84c3d54fcf7b71c37ab9bac4b04"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/PHPOffice/PhpSpreadsheet/zipball/6a2e0cef4390c62e9847eaa09b1a2b48297d5651",
- "reference": "6a2e0cef4390c62e9847eaa09b1a2b48297d5651",
+ "url": "https://api.github.com/repos/PHPOffice/PhpSpreadsheet/zipball/f734783d826bd84c3d54fcf7b71c37ab9bac4b04",
+ "reference": "f734783d826bd84c3d54fcf7b71c37ab9bac4b04",
"shasum": ""
},
"require": {
@@ -584,7 +584,7 @@
"xls",
"xlsx"
],
- "time": "2019-11-17T20:53:09+00:00"
+ "time": "2019-11-18T11:33:05+00:00"
},
{
"name": "psr/simple-cache",
@@ -640,12 +640,12 @@
"source": {
"type": "git",
"url": "https://github.com/yiisoft/yii2-framework.git",
- "reference": "e5aa7e91f3c310cd47aaeb0eee05d69b2e8c7ed0"
+ "reference": "7f114c9a772107265a174379e2adf23f51af7458"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/yiisoft/yii2-framework/zipball/e5aa7e91f3c310cd47aaeb0eee05d69b2e8c7ed0",
- "reference": "e5aa7e91f3c310cd47aaeb0eee05d69b2e8c7ed0",
+ "url": "https://api.github.com/repos/yiisoft/yii2-framework/zipball/7f114c9a772107265a174379e2adf23f51af7458",
+ "reference": "7f114c9a772107265a174379e2adf23f51af7458",
"shasum": ""
},
"require": {
@@ -732,7 +732,7 @@
"framework",
"yii2"
],
- "time": "2019-11-12T18:18:10+00:00"
+ "time": "2019-11-19T21:22:42+00:00"
},
{
"name": "yiisoft/yii2-bootstrap4",
@@ -858,6 +858,56 @@
],
"time": "2019-07-16T13:22:50+00:00"
},
+ {
+ "name": "yiisoft/yii2-httpclient",
+ "version": "dev-master",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/yiisoft/yii2-httpclient.git",
+ "reference": "05ecc99868352cf840173bfd8fe67bfd84b5f295"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://api.github.com/repos/yiisoft/yii2-httpclient/zipball/05ecc99868352cf840173bfd8fe67bfd84b5f295",
+ "reference": "05ecc99868352cf840173bfd8fe67bfd84b5f295",
+ "shasum": ""
+ },
+ "require": {
+ "yiisoft/yii2": "~2.0.13"
+ },
+ "require-dev": {
+ "phpunit/phpunit": "4.8.27|~5.7.21|^6.2"
+ },
+ "type": "yii2-extension",
+ "extra": {
+ "branch-alias": {
+ "dev-master": "2.0.x-dev"
+ }
+ },
+ "autoload": {
+ "psr-4": {
+ "yii\\httpclient\\": "src"
+ }
+ },
+ "notification-url": "https://packagist.org/downloads/",
+ "license": [
+ "BSD-3-Clause"
+ ],
+ "authors": [
+ {
+ "name": "Paul Klimov",
+ "email": "klimov.paul@gmail.com"
+ }
+ ],
+ "description": "HTTP client extension for the Yii framework",
+ "keywords": [
+ "curl",
+ "http",
+ "httpclient",
+ "yii2"
+ ],
+ "time": "2019-10-08T09:48:57+00:00"
+ },
{
"name": "yiisoft/yii2-redis",
"version": "dev-master",
@@ -1083,16 +1133,16 @@
},
{
"name": "yiisoft/yii2-debug",
- "version": "2.1.11",
+ "version": "2.1.12",
"source": {
"type": "git",
"url": "https://github.com/yiisoft/yii2-debug.git",
- "reference": "72e7c6c454028366f14ccef5a93d6c18fc9dcd63"
+ "reference": "bf9234ba1369116d12ebe266d98006416a5ae304"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/yiisoft/yii2-debug/zipball/72e7c6c454028366f14ccef5a93d6c18fc9dcd63",
- "reference": "72e7c6c454028366f14ccef5a93d6c18fc9dcd63",
+ "url": "https://api.github.com/repos/yiisoft/yii2-debug/zipball/bf9234ba1369116d12ebe266d98006416a5ae304",
+ "reference": "bf9234ba1369116d12ebe266d98006416a5ae304",
"shasum": ""
},
"require": {
@@ -1137,20 +1187,20 @@
"debugger",
"yii2"
],
- "time": "2019-11-05T13:56:49+00:00"
+ "time": "2019-11-19T20:09:08+00:00"
},
{
"name": "yiisoft/yii2-gii",
- "version": "2.1.2",
+ "version": "2.1.3",
"source": {
"type": "git",
"url": "https://github.com/yiisoft/yii2-gii.git",
- "reference": "cf3e81953a9e9796eed4021f3065bc5c18ee3356"
+ "reference": "0dcc7d3c66de045f1b560ad4928dc67a6611f6d1"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/yiisoft/yii2-gii/zipball/cf3e81953a9e9796eed4021f3065bc5c18ee3356",
- "reference": "cf3e81953a9e9796eed4021f3065bc5c18ee3356",
+ "url": "https://api.github.com/repos/yiisoft/yii2-gii/zipball/0dcc7d3c66de045f1b560ad4928dc67a6611f6d1",
+ "reference": "0dcc7d3c66de045f1b560ad4928dc67a6611f6d1",
"shasum": ""
},
"require": {
@@ -1188,12 +1238,13 @@
"gii",
"yii2"
],
- "time": "2019-10-08T10:28:42+00:00"
+ "time": "2019-11-19T20:19:33+00:00"
}
],
"aliases": [],
"minimum-stability": "dev",
"stability-flags": {
+ "yiisoft/yii2-httpclient": 20,
"yiisoft/yii2-debug": 20,
"kint-php/kint": 20,
"yiisoft/yii2-gii": 20
diff --git a/console/migrations/m191122_011654_add_column_admin_id_in_table_user.php b/console/migrations/m191122_011654_add_column_admin_id_in_table_user.php
new file mode 100644
index 0000000..1fa35f5
--- /dev/null
+++ b/console/migrations/m191122_011654_add_column_admin_id_in_table_user.php
@@ -0,0 +1,41 @@
+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;
+ }
+ */
+}
diff --git a/vendor/iron/assets/grid/css/grid.css b/vendor/iron/assets/grid/css/grid.css
index 781e068..f989318 100644
--- a/vendor/iron/assets/grid/css/grid.css
+++ b/vendor/iron/assets/grid/css/grid.css
@@ -62,4 +62,4 @@ THE SOFTWARE.
.dataTable td a{
color: #333;
opacity: 0.8;
-}
\ No newline at end of file
+}
diff --git a/vendor/iron/grid/GridView.php b/vendor/iron/grid/GridView.php
index 5b42816..4f83b4a 100644
--- a/vendor/iron/grid/GridView.php
+++ b/vendor/iron/grid/GridView.php
@@ -219,13 +219,13 @@ class GridView extends BaseListView
{batch}
-
添加
+
添加
@@ -281,14 +281,14 @@ HTML;
throw new InvalidConfigException('The "formatter" property must be either a Format object or a configuration array.');
}
$this->pager = [
- 'options'=>['class'=>['justify-content-end','pagination']],
- 'linkOptions'=>['class'=>'page-link'],
- 'pageCssClass'=>'paginate_button page-item',
- 'disabledPageCssClass'=>'page-link disabled',
- 'firstPageLabel'=>'«',
- 'prevPageLabel'=>'‹',
- 'nextPageLabel'=>'›',
- 'lastPageLabel'=>'»',];
+ 'options' => ['class' => ['justify-content-end', 'pagination']],
+ 'linkOptions' => ['class' => 'page-link'],
+ 'pageCssClass' => 'paginate_button page-item',
+ 'disabledPageCssClass' => 'page-link disabled',
+ 'firstPageLabel' => '«',
+ 'prevPageLabel' => '‹',
+ 'nextPageLabel' => '›',
+ 'lastPageLabel' => '»',];
$this->initColumns();
}
@@ -445,6 +445,8 @@ SCRIPT;
return $this->renderFilter();
case '{batch}':
return $this->renderBatch();
+ case '{url}':
+ return Yii::$app->request->url;
default:
return false;
}