From 7134a2c666e7860e66b40a38ba1dc4f42c4d184a Mon Sep 17 00:00:00 2001 From: koogua Date: Fri, 17 Sep 2021 16:51:16 +0800 Subject: [PATCH 01/16] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E8=AF=BE=E7=A8=8B?= =?UTF-8?q?=E5=88=97=E8=A1=A8=E7=9B=B4=E6=92=AD=E7=8A=B6=E6=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Http/Home/Views/course/show_catalog.volt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Http/Home/Views/course/show_catalog.volt b/app/Http/Home/Views/course/show_catalog.volt index d6502be6..e7ed78b3 100644 --- a/app/Http/Home/Views/course/show_catalog.volt +++ b/app/Http/Home/Views/course/show_catalog.volt @@ -66,7 +66,7 @@ {%- endmacro %} {%- macro live_status_info(lesson) %} - {% if lesson.attrs.start_time < time() and lesson.attrs.end_time > time() %} + {% if lesson.attrs.stream.status == 'active' %} {{ date('m月d日 H:i',lesson.attrs.start_time) }} 直播中 {% elseif lesson.attrs.start_time > time() %} {{ date('m月d日 H:i',lesson.attrs.start_time) }} 倒计时 From 416a671f3f594bbd1ab119db4c13099ae442bd3f Mon Sep 17 00:00:00 2001 From: koogua Date: Fri, 8 Oct 2021 17:31:39 +0800 Subject: [PATCH 02/16] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E8=BF=9B=E5=85=A5?= =?UTF-8?q?=E7=9B=B4=E6=92=AD=E9=97=B4=E6=B6=88=E6=81=AFid=E7=BC=BA?= =?UTF-8?q?=E5=A4=B1=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Services/Logic/Live/LiveChapter.php | 1 + 1 file changed, 1 insertion(+) diff --git a/app/Services/Logic/Live/LiveChapter.php b/app/Services/Logic/Live/LiveChapter.php index a66cb377..8efa260d 100644 --- a/app/Services/Logic/Live/LiveChapter.php +++ b/app/Services/Logic/Live/LiveChapter.php @@ -83,6 +83,7 @@ class LiveChapter extends LogicService Gateway::bindUid($clientId, $user->id); $message = kg_json_encode([ + 'id' => kg_uniqid(), 'type' => 'new_user', 'user' => [ 'id' => $user->id, From 878b8c4e5406ed43d704e39788274ca29912aba0 Mon Sep 17 00:00:00 2001 From: koogua Date: Sat, 9 Oct 2021 09:47:40 +0800 Subject: [PATCH 03/16] =?UTF-8?q?=EF=BC=91=EF=BC=8E=E4=BF=AE=E6=AD=A3?= =?UTF-8?q?=E8=8E=B7=E5=8F=96answer=E6=9D=83=E9=99=90=E5=88=A4=E6=96=AD?= =?UTF-8?q?=E9=97=AE=E9=A2=98=20=EF=BC=92=EF=BC=8Eorder=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=E8=A1=A5=E5=85=85=E7=BC=BA=E5=A4=B1=E6=9D=83=E9=99=90=E5=88=A4?= =?UTF-8?q?=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Http/Api/Controllers/AnswerController.php | 2 +- app/Http/Api/Controllers/OrderController.php | 4 ++++ app/Http/Home/Controllers/AnswerController.php | 2 +- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/app/Http/Api/Controllers/AnswerController.php b/app/Http/Api/Controllers/AnswerController.php index d49ed3ae..2a52ac9c 100644 --- a/app/Http/Api/Controllers/AnswerController.php +++ b/app/Http/Api/Controllers/AnswerController.php @@ -35,7 +35,7 @@ class AnswerController extends Controller $this->notFound(); } - $approved = $answer['published'] != AnswerModel::PUBLISH_APPROVED; + $approved = $answer['published'] == AnswerModel::PUBLISH_APPROVED; $owned = $answer['me']['owned'] == 1; if (!$approved && !$owned) { diff --git a/app/Http/Api/Controllers/OrderController.php b/app/Http/Api/Controllers/OrderController.php index cd5fb1f3..866dff0f 100644 --- a/app/Http/Api/Controllers/OrderController.php +++ b/app/Http/Api/Controllers/OrderController.php @@ -33,6 +33,10 @@ class OrderController extends Controller $this->notFound(); } + if ($order['me']['owned'] == 0) { + $this->forbidden(); + } + return $this->jsonSuccess(['order' => $order]); } diff --git a/app/Http/Home/Controllers/AnswerController.php b/app/Http/Home/Controllers/AnswerController.php index a833382b..663ff936 100644 --- a/app/Http/Home/Controllers/AnswerController.php +++ b/app/Http/Home/Controllers/AnswerController.php @@ -61,7 +61,7 @@ class AnswerController extends Controller $this->notFound(); } - $approved = $answer['published'] != AnswerModel::PUBLISH_APPROVED; + $approved = $answer['published'] == AnswerModel::PUBLISH_APPROVED; $owned = $answer['me']['owned'] == 1; if (!$approved && !$owned) { From a699fdba1f092210d195a90685193201f78ba654 Mon Sep 17 00:00:00 2001 From: koogua Date: Mon, 18 Oct 2021 09:50:49 +0800 Subject: [PATCH 04/16] =?UTF-8?q?=E4=BF=AE=E5=A4=8Doauth=E7=99=BB=E5=BD=95?= =?UTF-8?q?code=20reused=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Http/Home/Controllers/ConnectController.php | 1 - app/Http/Home/Controllers/PublicController.php | 7 +++---- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/app/Http/Home/Controllers/ConnectController.php b/app/Http/Home/Controllers/ConnectController.php index 395556b3..29c5d8a6 100644 --- a/app/Http/Home/Controllers/ConnectController.php +++ b/app/Http/Home/Controllers/ConnectController.php @@ -132,7 +132,6 @@ class ConnectController extends Controller } } - $openUser = $service->getOpenUserInfo($code, $state, $provider); $connect = $service->getConnectRelation($openUser['id'], $openUser['provider']); if ($this->authUser->id > 0) { diff --git a/app/Http/Home/Controllers/PublicController.php b/app/Http/Home/Controllers/PublicController.php index 1cb5a608..e96a5675 100644 --- a/app/Http/Home/Controllers/PublicController.php +++ b/app/Http/Home/Controllers/PublicController.php @@ -56,13 +56,12 @@ class PublicController extends \Phalcon\Mvc\Controller */ public function shareAction() { - $id = $this->request->getQuery('id', 'int', 0); - $type = $this->request->getQuery('type', 'string', 'course'); - $referer = $this->request->getQuery('referer', 'int', 0); + $id = $this->request->getQuery('id', 'int'); + $type = $this->request->getQuery('type', 'string'); $service = new ShareUrlService(); - $location = $service->handle($id, $type, $referer); + $location = $service->handle($id, $type); return $this->response->redirect($location, true); } From d03999ebf35e03472174e234f0f06565458bd475 Mon Sep 17 00:00:00 2001 From: koogua Date: Mon, 18 Oct 2021 18:56:53 +0800 Subject: [PATCH 05/16] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E9=A6=96=E9=A1=B5?= =?UTF-8?q?=E7=BC=93=E5=AD=98=E8=99=9A=E6=8B=9F=E7=94=A8=E6=88=B7=E6=95=B0?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Caches/IndexFeaturedCourseList.php | 9 ++++++++- app/Caches/IndexFreeCourseList.php | 9 ++++++++- app/Caches/IndexNewCourseList.php | 9 ++++++++- app/Caches/IndexSimpleFeaturedCourseList.php | 9 ++++++++- app/Caches/IndexSimpleFreeCourseList.php | 9 ++++++++- app/Caches/IndexSimpleNewCourseList.php | 9 ++++++++- app/Caches/IndexSimpleVipCourseList.php | 9 ++++++++- app/Caches/IndexVipCourseList.php | 9 ++++++++- 8 files changed, 64 insertions(+), 8 deletions(-) diff --git a/app/Caches/IndexFeaturedCourseList.php b/app/Caches/IndexFeaturedCourseList.php index 9ef38676..db32e861 100644 --- a/app/Caches/IndexFeaturedCourseList.php +++ b/app/Caches/IndexFeaturedCourseList.php @@ -65,6 +65,13 @@ class IndexFeaturedCourseList extends Cache $categoryCourses = []; foreach ($courses as $course) { + + $userCount = $course->user_count; + + if ($course->fake_user_count > $course->user_count) { + $userCount = $course->fake_user_count; + } + $categoryCourses[] = [ 'id' => $course->id, 'title' => $course->title, @@ -73,7 +80,7 @@ class IndexFeaturedCourseList extends Cache 'vip_price' => $course->vip_price, 'model' => $course->model, 'level' => $course->level, - 'user_count' => $course->user_count, + 'user_count' => $userCount, 'lesson_count' => $course->lesson_count, ]; } diff --git a/app/Caches/IndexFreeCourseList.php b/app/Caches/IndexFreeCourseList.php index ecd23215..23e1c41e 100644 --- a/app/Caches/IndexFreeCourseList.php +++ b/app/Caches/IndexFreeCourseList.php @@ -65,6 +65,13 @@ class IndexFreeCourseList extends Cache $categoryCourses = []; foreach ($courses as $course) { + + $userCount = $course->user_count; + + if ($course->fake_user_count > $course->user_count) { + $userCount = $course->fake_user_count; + } + $categoryCourses[] = [ 'id' => $course->id, 'title' => $course->title, @@ -73,7 +80,7 @@ class IndexFreeCourseList extends Cache 'vip_price' => $course->vip_price, 'model' => $course->model, 'level' => $course->level, - 'user_count' => $course->user_count, + 'user_count' => $userCount, 'lesson_count' => $course->lesson_count, ]; } diff --git a/app/Caches/IndexNewCourseList.php b/app/Caches/IndexNewCourseList.php index 1049d2c2..33bb9b32 100644 --- a/app/Caches/IndexNewCourseList.php +++ b/app/Caches/IndexNewCourseList.php @@ -65,6 +65,13 @@ class IndexNewCourseList extends Cache $categoryCourses = []; foreach ($courses as $course) { + + $userCount = $course->user_count; + + if ($course->fake_user_count > $course->user_count) { + $userCount = $course->fake_user_count; + } + $categoryCourses[] = [ 'id' => $course->id, 'title' => $course->title, @@ -73,7 +80,7 @@ class IndexNewCourseList extends Cache 'vip_price' => $course->vip_price, 'model' => $course->model, 'level' => $course->level, - 'user_count' => $course->user_count, + 'user_count' => $userCount, 'lesson_count' => $course->lesson_count, ]; } diff --git a/app/Caches/IndexSimpleFeaturedCourseList.php b/app/Caches/IndexSimpleFeaturedCourseList.php index f3588fed..32801d99 100644 --- a/app/Caches/IndexSimpleFeaturedCourseList.php +++ b/app/Caches/IndexSimpleFeaturedCourseList.php @@ -42,6 +42,13 @@ class IndexSimpleFeaturedCourseList extends Cache $result = []; foreach ($courses as $course) { + + $userCount = $course->user_count; + + if ($course->fake_user_count > $course->user_count) { + $userCount = $course->fake_user_count; + } + $result[] = [ 'id' => $course->id, 'title' => $course->title, @@ -50,7 +57,7 @@ class IndexSimpleFeaturedCourseList extends Cache 'vip_price' => $course->vip_price, 'model' => $course->model, 'level' => $course->level, - 'user_count' => $course->user_count, + 'user_count' => $userCount, 'lesson_count' => $course->lesson_count, ]; } diff --git a/app/Caches/IndexSimpleFreeCourseList.php b/app/Caches/IndexSimpleFreeCourseList.php index a37e8779..9a71dbb7 100644 --- a/app/Caches/IndexSimpleFreeCourseList.php +++ b/app/Caches/IndexSimpleFreeCourseList.php @@ -42,6 +42,13 @@ class IndexSimpleFreeCourseList extends Cache $result = []; foreach ($courses as $course) { + + $userCount = $course->user_count; + + if ($course->fake_user_count > $course->user_count) { + $userCount = $course->fake_user_count; + } + $result[] = [ 'id' => $course->id, 'title' => $course->title, @@ -50,7 +57,7 @@ class IndexSimpleFreeCourseList extends Cache 'vip_price' => $course->vip_price, 'model' => $course->model, 'level' => $course->level, - 'user_count' => $course->user_count, + 'user_count' => $userCount, 'lesson_count' => $course->lesson_count, ]; } diff --git a/app/Caches/IndexSimpleNewCourseList.php b/app/Caches/IndexSimpleNewCourseList.php index b43166a9..a498fac7 100644 --- a/app/Caches/IndexSimpleNewCourseList.php +++ b/app/Caches/IndexSimpleNewCourseList.php @@ -42,6 +42,13 @@ class IndexSimpleNewCourseList extends Cache $result = []; foreach ($courses as $course) { + + $userCount = $course->user_count; + + if ($course->fake_user_count > $course->user_count) { + $userCount = $course->fake_user_count; + } + $result[] = [ 'id' => $course->id, 'title' => $course->title, @@ -50,7 +57,7 @@ class IndexSimpleNewCourseList extends Cache 'vip_price' => $course->vip_price, 'model' => $course->model, 'level' => $course->level, - 'user_count' => $course->user_count, + 'user_count' => $userCount, 'lesson_count' => $course->lesson_count, ]; } diff --git a/app/Caches/IndexSimpleVipCourseList.php b/app/Caches/IndexSimpleVipCourseList.php index d4474287..7162d431 100644 --- a/app/Caches/IndexSimpleVipCourseList.php +++ b/app/Caches/IndexSimpleVipCourseList.php @@ -42,6 +42,13 @@ class IndexSimpleVipCourseList extends Cache $result = []; foreach ($courses as $course) { + + $userCount = $course->user_count; + + if ($course->fake_user_count > $course->user_count) { + $userCount = $course->fake_user_count; + } + $result[] = [ 'id' => $course->id, 'title' => $course->title, @@ -50,7 +57,7 @@ class IndexSimpleVipCourseList extends Cache 'vip_price' => $course->vip_price, 'model' => $course->model, 'level' => $course->level, - 'user_count' => $course->user_count, + 'user_count' => $userCount, 'lesson_count' => $course->lesson_count, ]; } diff --git a/app/Caches/IndexVipCourseList.php b/app/Caches/IndexVipCourseList.php index 163bff1f..4d8d78a6 100644 --- a/app/Caches/IndexVipCourseList.php +++ b/app/Caches/IndexVipCourseList.php @@ -65,6 +65,13 @@ class IndexVipCourseList extends Cache $categoryCourses = []; foreach ($courses as $course) { + + $userCount = $course->user_count; + + if ($course->fake_user_count > $course->user_count) { + $userCount = $course->fake_user_count; + } + $categoryCourses[] = [ 'id' => $course->id, 'title' => $course->title, @@ -73,7 +80,7 @@ class IndexVipCourseList extends Cache 'vip_price' => $course->vip_price, 'model' => $course->model, 'level' => $course->level, - 'user_count' => $course->user_count, + 'user_count' => $userCount, 'lesson_count' => $course->lesson_count, ]; } From 402ae2468b7d491c246136a74e36768fe13b84d0 Mon Sep 17 00:00:00 2001 From: koogua Date: Tue, 19 Oct 2021 20:21:04 +0800 Subject: [PATCH 06/16] =?UTF-8?q?1.=E6=B8=85=E7=90=86=E5=88=86=E4=BA=AB?= =?UTF-8?q?=E9=93=BE=E6=8E=A5=E5=8F=82=E6=95=B0=202.=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E8=B4=A6=E5=8F=B7=E6=B3=9B=E6=BB=A5=E7=99=BB=E5=BD=95=E6=A3=80?= =?UTF-8?q?=E6=9F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Http/Home/Views/article/show.volt | 2 +- app/Http/Home/Views/chapter/live/active.volt | 2 +- app/Http/Home/Views/chapter/read.volt | 2 +- app/Http/Home/Views/chapter/vod.volt | 2 +- app/Http/Home/Views/course/show.volt | 2 +- app/Http/Home/Views/question/show.volt | 2 +- app/Http/Home/Views/user/show.volt | 2 +- app/Library/AppInfo.php | 2 +- app/Models/UserSession.php | 21 +++++++++ app/Models/UserToken.php | 21 +++++++++ app/Repos/UserSession.php | 18 +++++++- app/Repos/UserToken.php | 17 +++++++- app/Services/Auth/Api.php | 2 +- app/Services/Auth/Home.php | 2 +- app/Validators/Account.php | 34 +++++++++++++++ config/errors.php | 1 + db/migrations/20211019093522.php | 46 ++++++++++++++++++++ 17 files changed, 166 insertions(+), 12 deletions(-) create mode 100644 db/migrations/20211019093522.php diff --git a/app/Http/Home/Views/article/show.volt b/app/Http/Home/Views/article/show.volt index 62fa935f..9941b176 100644 --- a/app/Http/Home/Views/article/show.volt +++ b/app/Http/Home/Views/article/show.volt @@ -97,7 +97,7 @@ - {% set share_url = full_url({'for':'home.share'},{'id':article.id,'type':'article','referer':auth_user.id}) %} + {% set share_url = full_url({'for':'home.share'},{'id':article.id,'type':'article'}) %} {% set qrcode_url = url({'for':'home.qrcode'},{'text':share_url}) %}
diff --git a/app/Http/Home/Views/chapter/live/active.volt b/app/Http/Home/Views/chapter/live/active.volt index 82cd87ee..663240e9 100644 --- a/app/Http/Home/Views/chapter/live/active.volt +++ b/app/Http/Home/Views/chapter/live/active.volt @@ -57,7 +57,7 @@
- {% set share_url = full_url({'for':'home.share'},{'id':chapter.id,'type':'chapter','referer':auth_user.id}) %} + {% set share_url = full_url({'for':'home.share'},{'id':chapter.id,'type':'chapter'}) %} {% set qrcode_url = url({'for':'home.qrcode'},{'text':share_url}) %}
diff --git a/app/Http/Home/Views/chapter/read.volt b/app/Http/Home/Views/chapter/read.volt index 746a7bb0..0813b106 100644 --- a/app/Http/Home/Views/chapter/read.volt +++ b/app/Http/Home/Views/chapter/read.volt @@ -43,7 +43,7 @@
- {% set share_url = full_url({'for':'home.share'},{'id':chapter.id,'type':'chapter','referer':auth_user.id}) %} + {% set share_url = full_url({'for':'home.share'},{'id':chapter.id,'type':'chapter'}) %} {% set qrcode_url = url({'for':'home.qrcode'},{'text':share_url}) %}
diff --git a/app/Http/Home/Views/chapter/vod.volt b/app/Http/Home/Views/chapter/vod.volt index 5c5953f1..1b054626 100644 --- a/app/Http/Home/Views/chapter/vod.volt +++ b/app/Http/Home/Views/chapter/vod.volt @@ -43,7 +43,7 @@
- {% set share_url = full_url({'for':'home.share'},{'id':chapter.id,'type':'chapter','referer':auth_user.id}) %} + {% set share_url = full_url({'for':'home.share'},{'id':chapter.id,'type':'chapter'}) %} {% set qrcode_url = url({'for':'home.qrcode'},{'text':share_url}) %}
diff --git a/app/Http/Home/Views/course/show.volt b/app/Http/Home/Views/course/show.volt index 5f6ee021..a9472cb7 100644 --- a/app/Http/Home/Views/course/show.volt +++ b/app/Http/Home/Views/course/show.volt @@ -94,7 +94,7 @@
- {% set share_url = full_url({'for':'home.share'},{'id':course.id,'type':'course','referer':auth_user.id}) %} + {% set share_url = full_url({'for':'home.share'},{'id':course.id,'type':'course'}) %} {% set qrcode_url = url({'for':'home.qrcode'},{'text':share_url}) %}
diff --git a/app/Http/Home/Views/question/show.volt b/app/Http/Home/Views/question/show.volt index e7d9f36b..d8b3bbc1 100644 --- a/app/Http/Home/Views/question/show.volt +++ b/app/Http/Home/Views/question/show.volt @@ -97,7 +97,7 @@
- {% set share_url = full_url({'for':'home.share'},{'id':question.id,'type':'question','referer':auth_user.id}) %} + {% set share_url = full_url({'for':'home.share'},{'id':question.id,'type':'question'}) %} {% set qrcode_url = url({'for':'home.qrcode'},{'text':share_url}) %}
diff --git a/app/Http/Home/Views/user/show.volt b/app/Http/Home/Views/user/show.volt index f39aa5ff..599caf83 100644 --- a/app/Http/Home/Views/user/show.volt +++ b/app/Http/Home/Views/user/show.volt @@ -96,7 +96,7 @@
- {% set share_url = full_url({'for':'home.share'},{'id':user.id,'type':'user','referer':auth_user.id}) %} + {% set share_url = full_url({'for':'home.share'},{'id':user.id,'type':'user'}) %} {% set qrcode_url = url({'for':'home.qrcode'},{'text':share_url}) %}
diff --git a/app/Library/AppInfo.php b/app/Library/AppInfo.php index fed579d7..184af632 100644 --- a/app/Library/AppInfo.php +++ b/app/Library/AppInfo.php @@ -16,7 +16,7 @@ class AppInfo protected $link = 'https://koogua.com'; - protected $version = '1.4.6'; + protected $version = '1.4.7'; public function __get($name) { diff --git a/app/Models/UserSession.php b/app/Models/UserSession.php index 5b6074a5..7b55481d 100644 --- a/app/Models/UserSession.php +++ b/app/Models/UserSession.php @@ -7,6 +7,8 @@ namespace App\Models; +use Phalcon\Mvc\Model\Behavior\SoftDelete; + class UserSession extends Model { @@ -45,6 +47,13 @@ class UserSession extends Model */ public $client_ip = ''; + /** + * 删除标识 + * + * @var int + */ + public $deleted = 0; + /** * 过期时间 * @@ -71,6 +80,18 @@ class UserSession extends Model return 'kg_user_session'; } + public function initialize() + { + parent::initialize(); + + $this->addBehavior( + new SoftDelete([ + 'field' => 'deleted', + 'value' => 1, + ]) + ); + } + public function beforeCreate() { $this->create_time = time(); diff --git a/app/Models/UserToken.php b/app/Models/UserToken.php index aad991e6..5ddda172 100644 --- a/app/Models/UserToken.php +++ b/app/Models/UserToken.php @@ -7,6 +7,8 @@ namespace App\Models; +use Phalcon\Mvc\Model\Behavior\SoftDelete; + class UserToken extends Model { @@ -45,6 +47,13 @@ class UserToken extends Model */ public $client_ip = ''; + /** + * 删除标识 + * + * @var int + */ + public $deleted = 0; + /** * 过期时间 * @@ -71,6 +80,18 @@ class UserToken extends Model return 'kg_user_token'; } + public function initialize() + { + parent::initialize(); + + $this->addBehavior( + new SoftDelete([ + 'field' => 'deleted', + 'value' => 1, + ]) + ); + } + public function beforeCreate() { $this->create_time = time(); diff --git a/app/Repos/UserSession.php b/app/Repos/UserSession.php index 2ea25a8d..26f1b542 100644 --- a/app/Repos/UserSession.php +++ b/app/Repos/UserSession.php @@ -18,10 +18,26 @@ class UserSession extends Repository * @param int $userId * @return ResultsetInterface|Resultset|UserSessionModel[] */ - public function findByUserId($userId) + public function findUserActiveSessions($userId) { return UserSessionModel::query() ->where('user_id = :user_id:', ['user_id' => $userId]) + ->andWhere('deleted = 0') + ->execute(); + } + + /** + * @param int $userId + * @param int $minutes + * @return ResultsetInterface|Resultset|UserSessionModel[] + */ + public function findUserRecentSessions($userId, $minutes = 10) + { + $createTime = time() - $minutes * 60; + + return UserSessionModel::query() + ->where('user_id = :user_id:', ['user_id' => $userId]) + ->andWhere('create_time > :create_time:', ['create_time' => $createTime]) ->execute(); } diff --git a/app/Repos/UserToken.php b/app/Repos/UserToken.php index d6730027..056d8358 100644 --- a/app/Repos/UserToken.php +++ b/app/Repos/UserToken.php @@ -18,11 +18,26 @@ class UserToken extends Repository * @param int $userId * @return ResultsetInterface|Resultset|UserTokenModel[] */ - public function findByUserId($userId) + public function findUserActiveTokens($userId) { return UserTokenModel::query() ->where('user_id = :user_id:', ['user_id' => $userId]) ->execute(); } + /** + * @param int $userId + * @param int $minutes + * @return ResultsetInterface|Resultset|UserTokenModel[] + */ + public function findUserRecentTokens($userId, $minutes = 10) + { + $createTime = time() - $minutes * 60; + + return UserTokenModel::query() + ->where('user_id = :user_id:', ['user_id' => $userId]) + ->andWhere('create_time > :create_time:', ['create_time' => $createTime]) + ->execute(); + } + } diff --git a/app/Services/Auth/Api.php b/app/Services/Auth/Api.php index afd99c84..71084950 100644 --- a/app/Services/Auth/Api.php +++ b/app/Services/Auth/Api.php @@ -76,7 +76,7 @@ class Api extends AuthService { $repo = new UserTokenRepo(); - $records = $repo->findByUserId($userId); + $records = $repo->findUserActiveTokens($userId); if ($records->count() == 0) return; diff --git a/app/Services/Auth/Home.php b/app/Services/Auth/Home.php index 0cc50cc9..9db3e691 100644 --- a/app/Services/Auth/Home.php +++ b/app/Services/Auth/Home.php @@ -65,7 +65,7 @@ class Home extends AuthService $repo = new UserSessionRepo(); - $records = $repo->findByUserId($userId); + $records = $repo->findUserActiveSessions($userId); if ($records->count() == 0) return; diff --git a/app/Validators/Account.php b/app/Validators/Account.php index 095bcdfa..91a7b9de 100644 --- a/app/Validators/Account.php +++ b/app/Validators/Account.php @@ -12,13 +12,19 @@ use App\Exceptions\Forbidden as ForbiddenException; use App\Library\Utils\Password as PasswordUtil; use App\Library\Validators\Common as CommonValidator; use App\Models\Account as AccountModel; +use App\Models\Client as ClientModel; use App\Models\User as UserModel; use App\Repos\Account as AccountRepo; use App\Repos\User as UserRepo; +use App\Repos\UserSession as UserSessionRepo; +use App\Repos\UserToken as UserTokenRepo; +use App\Traits\Client as ClientTrait; class Account extends Validator { + use ClientTrait; + public function checkAccount($name) { $account = null; @@ -175,6 +181,34 @@ class Account extends Validator if ($locked && !$expired) { throw new ForbiddenException('account.locked'); } + + $this->checkFloodLogin($user->id); + } + + public function checkFloodLogin($userId) + { + $clientIp = $this->getClientIp(); + $clientType = $this->getClientType(); + + if ($clientType == ClientModel::TYPE_PC) { + $repo = new UserSessionRepo(); + $records = $repo->findUserRecentSessions($userId, 10); + } else { + $repo = new UserTokenRepo(); + $records = $repo->findUserRecentTokens($userId, 10); + } + + if ($records->count() == 0) return; + + $clientIps = array_column($records->toArray(), 'client_ip'); + + $countValues = array_count_values($clientIps); + + foreach ($countValues as $ip => $count) { + if ($clientIp == $ip && $count > 4) { + throw new ForbiddenException('account.flood_login'); + } + } } } diff --git a/config/errors.php b/config/errors.php index 53a22bf1..35aa2658 100644 --- a/config/errors.php +++ b/config/errors.php @@ -47,6 +47,7 @@ $error['captcha.invalid_code'] = '无效的验证码'; */ $error['account.not_found'] = '账号不存在'; $error['account.locked'] = '账号被锁定,无法登录'; +$error['account.flood_login'] = '帐号泛滥登录'; $error['account.login_pwd_incorrect'] = '登录密码不正确'; $error['account.invalid_login_name'] = '无效的登录名'; $error['account.invalid_email'] = '无效的电子邮箱'; diff --git a/db/migrations/20211019093522.php b/db/migrations/20211019093522.php new file mode 100644 index 00000000..5946d094 --- /dev/null +++ b/db/migrations/20211019093522.php @@ -0,0 +1,46 @@ +alterUserSessionTable(); + $this->alterUserTokenTable(); + } + + protected function alterUserSessionTable() + { + $this->table('kg_user_session') + ->addColumn('deleted', 'integer', [ + 'null' => false, + 'default' => '0', + 'limit' => MysqlAdapter::INT_REGULAR, + 'signed' => false, + 'comment' => '删除标识', + 'after' => 'client_ip', + ])->save(); + } + + protected function alterUserTokenTable() + { + $this->table('kg_user_token') + ->addColumn('deleted', 'integer', [ + 'null' => false, + 'default' => '0', + 'limit' => MysqlAdapter::INT_REGULAR, + 'signed' => false, + 'comment' => '删除标识', + 'after' => 'client_ip', + ])->save(); + } + +} From 9c8882bac6128d117177a5ff3fef36a19b9e2533 Mon Sep 17 00:00:00 2001 From: koogua Date: Fri, 31 Dec 2021 09:37:38 +0800 Subject: [PATCH 07/16] =?UTF-8?q?=E7=9F=AD=E4=BF=A1=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0region=E9=80=89=E9=A1=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- db/migrations/20211231013226.php | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 db/migrations/20211231013226.php diff --git a/db/migrations/20211231013226.php b/db/migrations/20211231013226.php new file mode 100644 index 00000000..a3f35979 --- /dev/null +++ b/db/migrations/20211231013226.php @@ -0,0 +1,27 @@ +handleSmsSetting(); + } + + protected function handleSmsSetting() + { + $row = + [ + [ + 'section' => 'sms', + 'item_key' => 'region', + 'item_value' => 'ap-guangzhou', + ] + ]; + + $this->table('kg_setting')->insert($row)->save(); + } + +} From c13b45d991de25c185c9dbcf51d46ed4dbaa788a Mon Sep 17 00:00:00 2001 From: koogua Date: Fri, 31 Dec 2021 14:13:42 +0800 Subject: [PATCH 08/16] =?UTF-8?q?=20=E8=A1=A5=E5=85=85=E8=AF=BE=E7=A8=8B?= =?UTF-8?q?=E5=88=86=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Http/Admin/Views/course/list.volt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/Http/Admin/Views/course/list.volt b/app/Http/Admin/Views/course/list.volt index d17e17f9..6be67842 100644 --- a/app/Http/Admin/Views/course/list.volt +++ b/app/Http/Admin/Views/course/list.volt @@ -4,6 +4,7 @@ {{ partial('macros/course') }} + {% set category_url = url({'for':'admin.course.category'}) %} {% set add_url = url({'for':'admin.course.add'}) %} {% set search_url = url({'for':'admin.course.search'}) %} @@ -14,6 +15,9 @@
+ + 分类管理 + 添加课程 From 70c876778914fa9cfd592928e3aa7ec2944ab95a Mon Sep 17 00:00:00 2001 From: koogua Date: Wed, 23 Mar 2022 09:44:35 +0800 Subject: [PATCH 09/16] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E9=AA=8C=E8=AF=81?= =?UTF-8?q?=E7=A0=81=E5=85=B3=E9=97=AD=E5=90=8E=E5=85=83=E7=B4=A0=E6=9C=AA?= =?UTF-8?q?=E5=AE=9A=E4=B9=89=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- public/static/home/js/captcha.login.js | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/public/static/home/js/captcha.login.js b/public/static/home/js/captcha.login.js index 05a10ee3..6586617e 100644 --- a/public/static/home/js/captcha.login.js +++ b/public/static/home/js/captcha.login.js @@ -2,17 +2,19 @@ layui.use(['jquery'], function () { var $ = layui.jquery; - var captcha = new TencentCaptcha( - $('#captcha-btn')[0], - $('#captcha-btn').data('app-id'), - function (res) { - if (res.ret === 0) { - $('#ticket').val(res.ticket); - $('#rand').val(res.randstr); - $('#captcha-block').hide(); - $('#submit-btn').removeClass('layui-btn-disabled').removeAttr('disabled'); + if ($('#captcha-btn').length > 0) { + var captcha = new TencentCaptcha( + $('#captcha-btn')[0], + $('#captcha-btn').data('app-id'), + function (res) { + if (res.ret === 0) { + $('#ticket').val(res.ticket); + $('#rand').val(res.randstr); + $('#captcha-block').hide(); + $('#submit-btn').removeClass('layui-btn-disabled').removeAttr('disabled'); + } } - } - ); + ); + } }); \ No newline at end of file From d59d52b77113d7cb30723eb5cbeb03a716c4f512 Mon Sep 17 00:00:00 2001 From: koogua Date: Wed, 23 Mar 2022 09:52:55 +0800 Subject: [PATCH 10/16] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E9=AA=8C=E8=AF=81?= =?UTF-8?q?=E7=A0=81=E5=85=B3=E9=97=AD=E5=90=8E=E5=8F=B0=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Http/Home/Services/Account.php | 12 ++++++++++-- app/Services/Logic/Verify/MailCode.php | 9 +++++++-- app/Services/Logic/Verify/SmsCode.php | 9 +++++++-- 3 files changed, 24 insertions(+), 6 deletions(-) diff --git a/app/Http/Home/Services/Account.php b/app/Http/Home/Services/Account.php index 929c30ac..8516bcad 100644 --- a/app/Http/Home/Services/Account.php +++ b/app/Http/Home/Services/Account.php @@ -53,9 +53,17 @@ class Account extends Service $validator->checkIfAllowLogin($user); - $validator = new CaptchaValidator(); + $captcha = $this->getSettings('captcha'); - $validator->checkCode($post['ticket'], $post['rand']); + /** + * 验证码是一次性的,放到最后检查,减少第三方调用 + */ + if ($captcha['enabled'] == 1) { + + $validator = new CaptchaValidator(); + + $validator->checkCode($post['ticket'], $post['rand']); + } $this->auth->saveAuthInfo($user); diff --git a/app/Services/Logic/Verify/MailCode.php b/app/Services/Logic/Verify/MailCode.php index 9a04d1dc..d3cb7768 100644 --- a/app/Services/Logic/Verify/MailCode.php +++ b/app/Services/Logic/Verify/MailCode.php @@ -23,9 +23,14 @@ class MailCode extends LogicService $post['email'] = $validator->checkEmail($post['email']); - $validator = new CaptchaValidator(); + $captcha = $this->getSettings('captcha'); - $validator->checkCode($post['ticket'], $post['rand']); + if ($captcha['enabled'] == 1) { + + $validator = new CaptchaValidator(); + + $validator->checkCode($post['ticket'], $post['rand']); + } $service = new MailVerifyService(); diff --git a/app/Services/Logic/Verify/SmsCode.php b/app/Services/Logic/Verify/SmsCode.php index c97dbd56..adcbb080 100644 --- a/app/Services/Logic/Verify/SmsCode.php +++ b/app/Services/Logic/Verify/SmsCode.php @@ -23,9 +23,14 @@ class SmsCode extends LogicService $post['phone'] = $validator->checkPhone($post['phone']); - $validator = new CaptchaValidator(); + $captcha = $this->getSettings('captcha'); - $validator->checkCode($post['ticket'], $post['rand']); + if ($captcha['enabled'] == 1) { + + $validator = new CaptchaValidator(); + + $validator->checkCode($post['ticket'], $post['rand']); + } $service = new SmsVerifyService(); From e272bfc585b9d87456451b8b4f492fd8e6b7e4bd Mon Sep 17 00:00:00 2001 From: koogua Date: Tue, 24 May 2022 10:15:43 +0800 Subject: [PATCH 11/16] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E7=89=88=E6=9C=AC?= =?UTF-8?q?=E5=8F=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Library/AppInfo.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Library/AppInfo.php b/app/Library/AppInfo.php index 036f5fac..72dc5be5 100644 --- a/app/Library/AppInfo.php +++ b/app/Library/AppInfo.php @@ -16,7 +16,7 @@ class AppInfo protected $link = 'https://koogua.com'; - protected $version = '1.5.2'; + protected $version = '1.5.3'; public function __get($name) { From 34da1deae6326ce1e7b6ab7038a97bd70aee0f3d Mon Sep 17 00:00:00 2001 From: koogua Date: Thu, 7 Jul 2022 16:28:17 +0800 Subject: [PATCH 12/16] =?UTF-8?q?1.=E4=BF=AE=E6=AD=A3=E9=97=AE=E9=A2=98?= =?UTF-8?q?=E5=88=86=E7=B1=BB=E5=88=97=E8=A1=A8=E6=9F=A5=E8=AF=A2=E6=9D=A1?= =?UTF-8?q?=E4=BB=B6=202.=E5=8F=91=E8=B4=A7=E5=A2=9E=E5=8A=A0noMatchedHand?= =?UTF-8?q?ler?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 4 ++++ app/Builders/QuestionList.php | 8 ++++---- app/Console/Tasks/DeliverTask.php | 8 ++++++++ app/Http/Admin/Services/Question.php | 2 +- 4 files changed, 17 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ae1935b3..23a7aba5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +### [v1.5.5](https://gitee.com/koogua/course-tencent-cloud/releases/v1.5.5)(2022-07-15) + +- 修正获分类查询条件 + ### [v1.5.4](https://gitee.com/koogua/course-tencent-cloud/releases/v1.5.4)(2022-06-15) - 增加migration助手SettingTrait diff --git a/app/Builders/QuestionList.php b/app/Builders/QuestionList.php index 10a40a3c..aeabd0e8 100644 --- a/app/Builders/QuestionList.php +++ b/app/Builders/QuestionList.php @@ -23,15 +23,15 @@ class QuestionList extends Builder return $questions; } - public function handleCategories(array $articles) + public function handleCategories(array $questions) { $categories = $this->getCategories(); - foreach ($articles as $key => $article) { - $articles[$key]['category'] = $categories[$article['category_id']] ?? new \stdClass(); + foreach ($questions as $key => $article) { + $questions[$key]['category'] = $categories[$article['category_id']] ?? new \stdClass(); } - return $articles; + return $questions; } public function handleUsers(array $questions) diff --git a/app/Console/Tasks/DeliverTask.php b/app/Console/Tasks/DeliverTask.php index aec87f1d..de42c7ea 100644 --- a/app/Console/Tasks/DeliverTask.php +++ b/app/Console/Tasks/DeliverTask.php @@ -58,6 +58,9 @@ class DeliverTask extends Task case OrderModel::ITEM_VIP: $this->handleVipOrder($order); break; + default: + $this->noMatchedHandler($order); + break; } $order->status = OrderModel::STATUS_FINISHED; @@ -153,6 +156,11 @@ class DeliverTask extends Task $this->closePendingOrders($user->id); } + protected function noMatchedHandler(OrderModel $order) + { + throw new \RuntimeException("No Matched Handler For Order: {$order->id}"); + } + protected function closePendingOrders($userId) { $orders = $this->findUserPendingOrders($userId); diff --git a/app/Http/Admin/Services/Question.php b/app/Http/Admin/Services/Question.php index ac514eda..71caa2b8 100644 --- a/app/Http/Admin/Services/Question.php +++ b/app/Http/Admin/Services/Question.php @@ -46,7 +46,7 @@ class Question extends Service $categoryRepo = new CategoryRepo(); return $categoryRepo->findAll([ - 'type' => CategoryModel::TYPE_ARTICLE, + 'type' => CategoryModel::TYPE_QUESTION, 'level' => 1, 'published' => 1, 'deleted' => 0, From 175737f27420bd44da136002316833055c8d9cb9 Mon Sep 17 00:00:00 2001 From: koogua Date: Fri, 15 Jul 2022 10:28:08 +0800 Subject: [PATCH 13/16] =?UTF-8?q?1.=E5=A2=9E=E5=8A=A0=E6=B8=85=E7=90=86dem?= =?UTF-8?q?o=E6=95=B0=E6=8D=AE=E8=84=9A=E6=9C=AC=202.=E7=94=A8=E6=88=B7?= =?UTF-8?q?=E8=AF=BE=E7=A8=8B=E5=88=97=E8=A1=A8=E5=A2=9E=E5=8A=A0=E8=A7=92?= =?UTF-8?q?=E8=89=B2=E9=99=90=E5=AE=9A=203.=E7=B2=BE=E7=AE=80=E6=A8=A1?= =?UTF-8?q?=E5=9D=97=E5=8A=A0=E8=BD=BD=E5=92=8C=E8=B7=AF=E7=94=B1=E6=89=AB?= =?UTF-8?q?=E6=8F=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Console/Tasks/CleanDemoDataTask.php | 126 ++++++++++++++++++++++++ app/Services/Logic/User/CourseList.php | 2 + bootstrap/HttpKernel.php | 25 +++-- config/routes.php | 32 ++---- 4 files changed, 148 insertions(+), 37 deletions(-) create mode 100644 app/Console/Tasks/CleanDemoDataTask.php diff --git a/app/Console/Tasks/CleanDemoDataTask.php b/app/Console/Tasks/CleanDemoDataTask.php new file mode 100644 index 00000000..b53f97a1 --- /dev/null +++ b/app/Console/Tasks/CleanDemoDataTask.php @@ -0,0 +1,126 @@ +isDemoEnv()) { + + $this->truncateTables(); + $this->createRootUser(); + $this->cleanSearchIndex(); + $this->cleanCache(); + + } else { + + echo '------ access denied ------' . PHP_EOL; + } + } + + protected function truncateTables() + { + echo '------ start truncate tables ------' . PHP_EOL; + + $excludeTables = [ + 'kg_area', 'kg_migration', 'kg_nav', 'kg_page', + 'kg_reward', 'kg_role', 'kg_setting', 'kg_vip', + ]; + + $tables = $this->db->listTables(); + + foreach ($tables as $table) { + if (!in_array($table, $excludeTables)) { + $this->db->execute("TRUNCATE TABLE {$table}"); + } + } + + echo '------ end truncate tables ------' . PHP_EOL; + } + + protected function createRootUser() + { + echo '------ start create root user ------' . PHP_EOL; + + $account = new AccountModel(); + + $account->create([ + 'id' => 10000, + 'email' => '10000@163.com', + 'password' => '1a1e4568f1a3740b8853a8a16e29bc87', + 'salt' => 'MbZWxN3L', + 'create_time' => time(), + ]); + + $userRepo = new UserRepo(); + + $user = $userRepo->findById($account->id); + + $user->update([ + 'admin_role' => 1, + 'edu_role' => 2, + ]); + + echo '------ end create root user ------' . PHP_EOL; + } + + protected function cleanCache() + { + $util = new IndexCourseCacheUtil(); + $util->rebuild(); + + $slideListCache = new IndexSlideListCache(); + $slideListCache->rebuild(); + + $categoryListCache = new CategoryListCache(); + $categoryTreeListCache = new CategoryTreeListCache(); + + foreach (CategoryModel::types() as $key => $value) { + $categoryListCache->rebuild($key); + $categoryTreeListCache->rebuild($key); + } + } + + protected function cleanSearchIndex() + { + $articleIndexTask = new ArticleIndexTask(); + $articleIndexTask->cleanAction(); + + $courseIndexTask = new CourseIndexTask(); + $courseIndexTask->cleanAction(); + + $groupIndexTask = new GroupIndexTask(); + $groupIndexTask->cleanAction(); + + $questionIndexTask = new QuestionIndexTask(); + $questionIndexTask->cleanAction(); + + $userIndexTask = new UserIndexTask(); + $userIndexTask->cleanAction(); + } + + protected function isDemoEnv() + { + $userRepo = new UserRepo(); + + $user = $userRepo->findById(100015); + + return $user ? true : false; + } + +} diff --git a/app/Services/Logic/User/CourseList.php b/app/Services/Logic/User/CourseList.php index d6fca26f..88b78fbd 100644 --- a/app/Services/Logic/User/CourseList.php +++ b/app/Services/Logic/User/CourseList.php @@ -9,6 +9,7 @@ namespace App\Services\Logic\User; use App\Builders\CourseUserList as CourseUserListBuilder; use App\Library\Paginator\Query as PagerQuery; +use App\Models\CourseUser as CourseUserModel; use App\Repos\CourseUser as CourseUserRepo; use App\Services\Logic\Service as LogicService; use App\Services\Logic\UserTrait; @@ -27,6 +28,7 @@ class CourseList extends LogicService $params = $pagerQuery->getParams(); $params['user_id'] = $user->id; + $params['role_type'] = CourseUserModel::ROLE_STUDENT; $params['deleted'] = 0; $sort = $pagerQuery->getSort(); diff --git a/bootstrap/HttpKernel.php b/bootstrap/HttpKernel.php index 00ea375c..06aa8ba4 100644 --- a/bootstrap/HttpKernel.php +++ b/bootstrap/HttpKernel.php @@ -105,20 +105,17 @@ class HttpKernel extends Kernel protected function registerModules() { - $modules = [ - 'api' => [ - 'className' => 'App\Http\Api\Module', - 'path' => app_path('Http/Api/Module.php'), - ], - 'admin' => [ - 'className' => 'App\Http\Admin\Module', - 'path' => app_path('Http/Admin/Module.php'), - ], - 'home' => [ - 'className' => 'App\Http\Home\Module', - 'path' => app_path('Http/Home/Module.php'), - ], - ]; + $aliases = ['api', 'home', 'admin']; + + $modules = []; + + foreach ($aliases as $alias) { + $moduleName = ucfirst($alias); + $modules[$alias] = [ + 'className' => 'App\Http\\' . $moduleName . '\Module', + 'path' => app_path('Http/' . $moduleName . '/Module.php'), + ]; + } $this->app->registerModules($modules); } diff --git a/config/routes.php b/config/routes.php index 5a6ab2c7..a8c49855 100644 --- a/config/routes.php +++ b/config/routes.php @@ -19,30 +19,16 @@ $router->notFound([ 'action' => 'show404', ]); -$webFiles = scandir(app_path('Http/Home/Controllers')); +$modules = ['api', 'home', 'admin']; -foreach ($webFiles as $file) { - if (strpos($file, 'Controller.php')) { - $className = str_replace('Controller.php', '', $file); - $router->addModuleResource('home', 'App\Http\Home\Controllers\\' . $className); - } -} - -$apiFiles = scandir(app_path('Http/Api/Controllers')); - -foreach ($apiFiles as $file) { - if (strpos($file, 'Controller.php')) { - $className = str_replace('Controller.php', '', $file); - $router->addModuleResource('api', 'App\Http\Api\Controllers\\' . $className); - } -} - -$adminFiles = scandir(app_path('Http/Admin/Controllers')); - -foreach ($adminFiles as $file) { - if (strpos($file, 'Controller.php')) { - $className = str_replace('Controller.php', '', $file); - $router->addModuleResource('admin', 'App\Http\Admin\Controllers\\' . $className); +foreach ($modules as $module) { + $moduleName = ucfirst($module); + $files = scandir(app_path('Http/' . $moduleName . '/Controllers')); + foreach ($files as $file) { + if (strpos($file, 'Controller.php')) { + $className = str_replace('Controller.php', '', $file); + $router->addModuleResource($module, 'App\Http\\' . $moduleName . '\Controllers\\' . $className); + } } } From f5719c2ee732de9ebc10285c2dcab60a3e181ac3 Mon Sep 17 00:00:00 2001 From: koogua Date: Fri, 15 Jul 2022 17:35:22 +0800 Subject: [PATCH 14/16] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E5=B8=90=E5=8F=B7?= =?UTF-8?q?=E9=94=81=E5=AE=9A=E5=90=8E=E8=BF=98=E8=83=BD=E7=99=BB=E5=BD=95?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Validators/Account.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/Validators/Account.php b/app/Validators/Account.php index b8ed0f0e..004c8045 100644 --- a/app/Validators/Account.php +++ b/app/Validators/Account.php @@ -177,10 +177,10 @@ class Account extends Validator public function checkIfAllowLogin(UserModel $user) { - $locked = $user->locked == 1; - $expired = $user->lock_expiry_time > time(); + $case1 = $user->locked == 1; + $case2 = $user->lock_expiry_time > time(); - if ($locked && !$expired) { + if ($case1 && $case2) { throw new ForbiddenException('account.locked'); } From dc85029241f1dddc510a2094fbf21e84c838596e Mon Sep 17 00:00:00 2001 From: koogua Date: Fri, 22 Jul 2022 16:03:43 +0800 Subject: [PATCH 15/16] =?UTF-8?q?1.=E4=BC=98=E5=8C=96CsrfToken=202.?= =?UTF-8?q?=E5=8E=BB=E9=99=A4=E6=97=A0=E5=AE=9E=E9=99=85=E4=BD=9C=E7=94=A8?= =?UTF-8?q?=E7=9A=84OptimizeTable=E8=84=9A=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Console/Tasks/OptimizeTableTask.php | 139 ------------------------ app/Library/CsrfToken.php | 17 ++- config/config.default.php | 5 + scheduler.php | 3 - 4 files changed, 20 insertions(+), 144 deletions(-) delete mode 100644 app/Console/Tasks/OptimizeTableTask.php diff --git a/app/Console/Tasks/OptimizeTableTask.php b/app/Console/Tasks/OptimizeTableTask.php deleted file mode 100644 index 97f3e2ac..00000000 --- a/app/Console/Tasks/OptimizeTableTask.php +++ /dev/null @@ -1,139 +0,0 @@ -optimizeUserSessionTable(); - $this->optimizeUserTokenTable(); - $this->optimizeImMessageTable(); - $this->optimizeLearningTable(); - $this->optimizeTaskTable(); - } - - protected function optimizeUserSessionTable() - { - $sessionModel = new UserSessionModel(); - - $tableName = $sessionModel->getSource(); - - if (UserSessionModel::count() < 1000000) { - echo sprintf('no need to optimize table: %s', $tableName) . PHP_EOL; - return; - } - - echo sprintf('------ start optimize table: %s ------', $tableName) . PHP_EOL; - - $this->db->delete($tableName, 'expire_time < :expire_time', [ - 'expire_time' => strtotime('-3 days'), - ]); - - $this->db->execute("OPTIMIZE TABLE {$tableName}"); - - echo sprintf('------ end optimize table: %s ------', $tableName) . PHP_EOL; - } - - protected function optimizeUserTokenTable() - { - $tokenModel = new UserTokenModel(); - - $tableName = $tokenModel->getSource(); - - if (UserTokenModel::count() < 1000000) { - echo sprintf('no need to optimize table: %s', $tableName) . PHP_EOL; - return; - } - - echo sprintf('------ start optimize table: %s ------', $tableName) . PHP_EOL; - - $this->db->delete($tableName, 'expire_time < :expire_time', [ - 'expire_time' => strtotime('-3 days'), - ]); - - $this->db->execute("OPTIMIZE TABLE {$tableName}"); - - echo sprintf('------ end optimize table: %s ------', $tableName) . PHP_EOL; - } - - protected function optimizeImMessageTable() - { - $messageModel = new ImMessageModel(); - - $tableName = $messageModel->getSource(); - - if (ImMessageModel::count() < 1000000) { - echo sprintf('no need to optimize table: %s', $tableName) . PHP_EOL; - return; - } - - echo sprintf('------ start optimize table: %s ------', $tableName) . PHP_EOL; - - $this->db->delete($tableName, 'create_time < :create_time', [ - 'create_time' => strtotime('-6 months'), - ]); - - $this->db->execute("OPTIMIZE TABLE {$tableName}"); - - echo sprintf('------ end optimize table: %s ------', $tableName) . PHP_EOL; - } - - protected function optimizeLearningTable() - { - $learningModel = new LearningModel(); - - $tableName = $learningModel->getSource(); - - if (LearningModel::count() < 1000000) { - echo sprintf('no need to optimize table: %s', $tableName) . PHP_EOL; - return; - } - - echo sprintf('------ start optimize table: %s ------', $tableName) . PHP_EOL; - - $this->db->delete($tableName, 'create_time < :create_time', [ - 'create_time' => strtotime('-6 months'), - ]); - - $this->db->execute("OPTIMIZE TABLE {$tableName}"); - - echo sprintf('------ end optimize table: %s ------', $tableName) . PHP_EOL; - } - - protected function optimizeTaskTable() - { - $taskModel = new TaskModel(); - - $tableName = $taskModel->getSource(); - - if (TaskModel::count() < 1000000) { - echo sprintf('no need to optimize table: %s', $tableName) . PHP_EOL; - return; - } - - echo sprintf('------ start optimize table: %s ------', $tableName) . PHP_EOL; - - $this->db->delete($tableName, 'create_time < :create_time AND status > :status', [ - 'create_time' => strtotime('-6 months'), - 'status' => TaskModel::STATUS_PENDING, - ]); - - $this->db->execute("OPTIMIZE TABLE {$tableName}"); - - echo sprintf('------ end optimize table: %s ------', $tableName) . PHP_EOL; - } - -} \ No newline at end of file diff --git a/app/Library/CsrfToken.php b/app/Library/CsrfToken.php index 323a4175..e5ba0e95 100644 --- a/app/Library/CsrfToken.php +++ b/app/Library/CsrfToken.php @@ -7,6 +7,7 @@ namespace App\Library; +use Phalcon\Config; use Phalcon\Crypt; use Phalcon\Di; use Phalcon\Text; @@ -19,7 +20,7 @@ class CsrfToken */ protected $crypt; - protected $lifetime = 600; + protected $lifetime = 86400; protected $delimiter = '@@'; @@ -33,7 +34,7 @@ class CsrfToken public function getToken() { $content = [ - time() + $this->lifetime, + $this->getExpiredTime(), $this->fixed, Text::random(8), ]; @@ -62,4 +63,16 @@ class CsrfToken return true; } + protected function getExpiredTime() + { + /** + * @var $config Config + */ + $config = Di::getDefault()->getShared('config'); + + $lifetime = $config->path('csrf_token.lifetime') ?: $this->lifetime; + + return $lifetime + time(); + } + } \ No newline at end of file diff --git a/config/config.default.php b/config/config.default.php index 924f027d..41836295 100644 --- a/config/config.default.php +++ b/config/config.default.php @@ -117,6 +117,11 @@ $config['metadata']['lifetime'] = 7 * 86400; */ $config['annotation']['lifetime'] = 7 * 86400; +/** + * CsrfToken有效期(秒) + */ +$config['csrf_token']['lifetime'] = 86400; + /** * 允许跨域 */ diff --git a/scheduler.php b/scheduler.php index 70217971..6ff34493 100644 --- a/scheduler.php +++ b/scheduler.php @@ -99,7 +99,4 @@ $scheduler->php($script, $bin, ['--task' => 'sitemap', '--action' => 'main']) $scheduler->php($script, $bin, ['--task' => 'teacher_live_notice', '--action' => 'provide']) ->daily(4, 7); -$scheduler->php($script, $bin, ['--task' => 'optimize_table', '--action' => 'main']) - ->weekly(6, 5, 3); - $scheduler->run(); From 0b161d52bb4b5acbc5b052ee5a0c7bbfe2a77696 Mon Sep 17 00:00:00 2001 From: koogua Date: Wed, 27 Jul 2022 15:51:43 +0800 Subject: [PATCH 16/16] =?UTF-8?q?v1.5.5=E5=8F=91=E5=B8=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 9 ++++++++- app/Library/AppInfo.php | 2 +- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 23a7aba5..3ebb7d15 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,13 @@ -### [v1.5.5](https://gitee.com/koogua/course-tencent-cloud/releases/v1.5.5)(2022-07-15) +### [v1.5.5](https://gitee.com/koogua/course-tencent-cloud/releases/v1.5.5)(2022-07-27) - 修正获分类查询条件 +- 修正锁定账户还能登录的问题 +- 发货增加noMatchedHandler +- 增加demo数据清理脚本 +- 用户课程列表增加角色限定条件 +- 精简模块加载和路由扫描 +- 优化CsrfToken +- 去除无实质作用的数据表优化 ### [v1.5.4](https://gitee.com/koogua/course-tencent-cloud/releases/v1.5.4)(2022-06-15) diff --git a/app/Library/AppInfo.php b/app/Library/AppInfo.php index 1ead1181..d15bff8a 100644 --- a/app/Library/AppInfo.php +++ b/app/Library/AppInfo.php @@ -16,7 +16,7 @@ class AppInfo protected $link = 'https://koogua.com'; - protected $version = '1.5.4'; + protected $version = '1.5.5'; public function __get($name) {