From c0e38d68fd360fff1247c58d7a9e48d33895316f Mon Sep 17 00:00:00 2001 From: xiaochong0302 Date: Tue, 7 Apr 2020 19:32:00 +0800 Subject: [PATCH] =?UTF-8?q?=E7=B2=BE=E7=AE=80auth?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Caches/AccessToken.php | 35 - app/Http/Admin/Controllers/Controller.php | 11 +- app/Http/Admin/Module.php | 4 +- app/Http/Admin/Services/AlipayTest.php | 8 +- app/Http/Admin/Services/AuthMenu.php | 8 +- app/Http/Admin/Services/PaymentTest.php | 9 +- app/Http/Admin/Services/Session.php | 4 +- app/Http/Admin/Services/WxpayTest.php | 12 +- app/Http/Admin/Views/index/index.volt | 2 +- app/Http/Admin/Views/order/show.volt | 3 +- app/Http/Api/Module.php | 4 +- app/Http/Api/Services/Login.php | 10 +- app/Http/Api/Services/Logout.php | 6 +- app/Http/Html5/Module.php | 4 +- app/Http/Web/Controllers/Controller.php | 14 +- app/Http/Web/Module.php | 4 +- app/Http/Web/Views/index/index.volt | 2 +- app/Library/Util/Password.php | 2 +- app/Models/AccessToken.php | 11 - app/Models/Account.php | 6 - app/Models/Category.php | 7 +- app/Models/Chapter.php | 12 +- app/Models/ChapterRead.php | 6 +- app/Models/Course.php | 1 - app/Models/Nav.php | 5 +- app/Models/Order.php | 2 - app/Models/RefreshToken.php | 3 +- app/Models/Refund.php | 2 - app/Models/Slide.php | 4 +- app/Models/Trade.php | 2 - app/Models/User.php | 1 - app/Providers/Router.php | 2 +- app/Providers/Session.php | 2 +- app/Services/{AuthUser.php => Auth.php} | 2 +- app/Services/{AuthUser => Auth}/Admin.php | 44 +- app/Services/Auth/Api.php | 89 ++ app/Services/Auth/Html5.php | 47 + app/Services/{AuthUser => Auth}/Web.php | 30 +- app/Services/AuthUser/Api.php | 64 - app/Services/AuthUser/Html5.php | 63 - .../Frontend/Account/PasswordReset.php | 2 +- app/Services/Frontend/Account/Register.php | 26 +- app/Services/Frontend/Service.php | 32 +- app/Services/VerifyCode.php | 4 + app/Traits/Auth.php | 4 +- app/Validators/Account.php | 39 +- app/Validators/User.php | 7 +- app/Validators/Validator.php | 11 +- bootstrap/HttpKernel.php | 2 +- composer.json | 1 + composer.lock | 1251 ++++++++++------- config/config.php.default | 7 +- config/errors.php | 2 +- 53 files changed, 1013 insertions(+), 922 deletions(-) delete mode 100644 app/Caches/AccessToken.php rename app/Services/{AuthUser.php => Auth.php} (83%) rename app/Services/{AuthUser => Auth}/Admin.php (62%) create mode 100644 app/Services/Auth/Api.php create mode 100644 app/Services/Auth/Html5.php rename app/Services/{AuthUser => Auth}/Web.php (56%) delete mode 100644 app/Services/AuthUser/Api.php delete mode 100644 app/Services/AuthUser/Html5.php diff --git a/app/Caches/AccessToken.php b/app/Caches/AccessToken.php deleted file mode 100644 index f2222b27..00000000 --- a/app/Caches/AccessToken.php +++ /dev/null @@ -1,35 +0,0 @@ -lifetime; - } - - public function getKey($id = null) - { - return "access_token:{$id}"; - } - - public function getContent($id = null) - { - $accessTokenRepo = new AccessTokenRepo(); - - $accessToken = $accessTokenRepo->findById($id); - - if (!$accessToken) { - return new \stdClass(); - } - - return $accessToken; - } - -} diff --git a/app/Http/Admin/Controllers/Controller.php b/app/Http/Admin/Controllers/Controller.php index 92e7a606..a391bc86 100644 --- a/app/Http/Admin/Controllers/Controller.php +++ b/app/Http/Admin/Controllers/Controller.php @@ -3,16 +3,17 @@ namespace App\Http\Admin\Controllers; use App\Models\Audit as AuditModel; -use App\Services\AuthUser\Admin as AdminAuthUser; +use App\Services\Auth\Admin as AdminAuth; use App\Traits\Response as ResponseTrait; use App\Traits\Security as SecurityTrait; use Phalcon\Mvc\Dispatcher; +use Yansongda\Supports\Collection; class Controller extends \Phalcon\Mvc\Controller { /** - * @var array + * @var Collection */ protected $authUser; @@ -112,11 +113,11 @@ class Controller extends \Phalcon\Mvc\Controller protected function getAuthUser() { /** - * @var AdminAuthUser $authUser + * @var AdminAuth $auth */ - $authUser = $this->getDI()->get('auth'); + $auth = $this->getDI()->get('auth'); - return $authUser->getAuthInfo(); + return $auth->getAuthInfo(); } } diff --git a/app/Http/Admin/Module.php b/app/Http/Admin/Module.php index d9090772..f07f31d3 100644 --- a/app/Http/Admin/Module.php +++ b/app/Http/Admin/Module.php @@ -2,7 +2,7 @@ namespace App\Http\Admin; -use App\Services\AuthUser\Admin as AdminAuthUser; +use App\Services\Auth\Admin as AdminAuth; use Phalcon\DiInterface; use Phalcon\Mvc\ModuleDefinitionInterface; use Phalcon\Mvc\View; @@ -27,7 +27,7 @@ class Module implements ModuleDefinitionInterface }); $di->setShared('auth', function () { - return new AdminAuthUser(); + return new AdminAuth(); }); } diff --git a/app/Http/Admin/Services/AlipayTest.php b/app/Http/Admin/Services/AlipayTest.php index e48c9b18..9aff02cd 100644 --- a/app/Http/Admin/Services/AlipayTest.php +++ b/app/Http/Admin/Services/AlipayTest.php @@ -19,18 +19,14 @@ class AlipayTest extends PaymentTest $qrcode = $alipayService->scan($trade); - $result = $qrcode ?: false; - - return $result; + return $qrcode ?: false; } public function status($tradeNo) { $alipayService = new AlipayService(); - $result = $alipayService->status($tradeNo); - - return $result; + return $alipayService->status($tradeNo); } public function cancel($tradeNo) diff --git a/app/Http/Admin/Services/AuthMenu.php b/app/Http/Admin/Services/AuthMenu.php index 0e0427b3..f5458fda 100644 --- a/app/Http/Admin/Services/AuthMenu.php +++ b/app/Http/Admin/Services/AuthMenu.php @@ -2,7 +2,7 @@ namespace App\Http\Admin\Services; -use App\Services\AuthUser\Admin as AdminAuthUser; +use App\Services\Auth\Admin as AdminAuth; use Phalcon\Mvc\User\Component; class AuthMenu extends Component @@ -115,11 +115,11 @@ class AuthMenu extends Component protected function getAuthInfo() { /** - * @var AdminAuthUser $authUser + * @var AdminAuth $auth */ - $authUser = $this->getDI()->get('auth'); + $auth = $this->getDI()->get('auth'); - return $authUser->getAuthInfo(); + return $auth->getAuthInfo(); } } diff --git a/app/Http/Admin/Services/PaymentTest.php b/app/Http/Admin/Services/PaymentTest.php index b485f475..458c5789 100644 --- a/app/Http/Admin/Services/PaymentTest.php +++ b/app/Http/Admin/Services/PaymentTest.php @@ -4,6 +4,7 @@ namespace App\Http\Admin\Services; use App\Models\Order as OrderModel; use App\Models\Trade as TradeModel; +use App\Services\Auth\Admin as AdminAuth; abstract class PaymentTest extends Service { @@ -21,15 +22,17 @@ abstract class PaymentTest extends Service public function createOrder() { /** - * @var object $authUser + * @var AdminAuth $auth */ - $authUser = $this->getDI()->get('auth')->getAuthInfo(); + $auth = $this->getDI()->get('auth'); + + $authUser = $auth->getAuthInfo(); $order = new OrderModel(); $order->subject = '测试 - 支付测试0.01元'; $order->amount = 0.01; - $order->user_id = $authUser->id; + $order->user_id = $authUser['id']; $order->item_type = OrderModel::ITEM_TEST; $order->create(); diff --git a/app/Http/Admin/Services/Session.php b/app/Http/Admin/Services/Session.php index 846eafee..04917606 100644 --- a/app/Http/Admin/Services/Session.php +++ b/app/Http/Admin/Services/Session.php @@ -2,7 +2,7 @@ namespace App\Http\Admin\Services; -use App\Services\AuthUser as AuthUserService; +use App\Services\Auth as AuthService; use App\Validators\Account as AccountValidator; use App\Validators\Security as SecurityValidator; @@ -10,7 +10,7 @@ class Session extends Service { /** - * @var AuthUserService + * @var AuthService */ protected $auth; diff --git a/app/Http/Admin/Services/WxpayTest.php b/app/Http/Admin/Services/WxpayTest.php index 04628706..14c26bc2 100644 --- a/app/Http/Admin/Services/WxpayTest.php +++ b/app/Http/Admin/Services/WxpayTest.php @@ -16,27 +16,21 @@ class WxpayTest extends PaymentTest $qrcode = $wxpayService->scan($trade); - $result = $qrcode ?: false; - - return $result; + return $qrcode ?: false; } public function status($tradeNo) { $wxpayService = new WxpayService(); - $result = $wxpayService->status($tradeNo); - - return $result; + return $wxpayService->status($tradeNo); } public function cancel($tradeNo) { $wxpayService = new WxpayService(); - $response = $wxpayService->close($tradeNo); - - return $response; + return $wxpayService->close($tradeNo); } } diff --git a/app/Http/Admin/Views/index/index.volt b/app/Http/Admin/Views/index/index.volt index e3d3857d..e6fd7d7d 100644 --- a/app/Http/Admin/Views/index/index.volt +++ b/app/Http/Admin/Views/index/index.volt @@ -29,7 +29,7 @@