Skip to content

Commit

Permalink
feat(pay): 支付节点需要进行密码输入
Browse files Browse the repository at this point in the history
  • Loading branch information
medz committed Sep 7, 2018
1 parent b60c4d6 commit 348f1b9
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 0 deletions.
11 changes: 11 additions & 0 deletions app/Http/Controllers/APIs/V2/PurchaseController.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,24 @@

use Illuminate\Http\Request;
use Zhiyi\Plus\Models\PaidNode as PaidNodeModel;
use hiyi\Plus\Http\Middleware\VerifyUserPassword;
use Zhiyi\Plus\Models\WalletCharge as WalletChargeModel;
use Illuminate\Contracts\Cache\Repository as CacheContract;
use Zhiyi\Plus\Packages\Currency\Processes\User as UserProcess;
use Illuminate\Contracts\Routing\ResponseFactory as ResponseContract;

class PurchaseController extends Controller
{
/**
* Create the controller instance.
*/
public function __construct()
{
$this
->middleware(VerifyUserPassword::class)
->only(['pay', 'payByCurrency']);
}

/**
* 获取付费节点和当前用户的付费状态.
*
Expand Down
54 changes: 54 additions & 0 deletions app/Http/Middleware/VerifyUserPassword.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php

declare(strict_types=1);

namespace Zhiyi\Plus\Http\Middleware;

use Closure;
use Illuminate\Http\Request;
use Illuminate\Contracts\Auth\Guard;
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
use Symfony\Component\HttpKernel\Exception\UnauthorizedHttpException;

class VerifyUserPassword
{
/**
* The user guard.
* @var \Illuminate\Contracts\Auth\Guard
*/
protected $auth;

/**
* Creates a new instance of the middleware.
*
* @param Guard $auth
*/
public function __construct(Guard $auth)
{
$this->auth = $auth;
}

/**
* The middleware handler.
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
* @throws \Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException
* @throws \Symfony\Component\HttpKernel\Exception\UnauthorizedHttpException
*/
public function handle(Request $request, Closure $next)
{
if ($this->auth->guest()) {
throw new UnauthorizedHttpException('请先登录');
} elseif ($this->auth->getProvider()->validateCredentials(
$this->auth->user(),
[
'password' => $request->input('password')
]
)) {
return $next($request);
}

throw new AccessDeniedHttpException('密码验证错误');
}
}

0 comments on commit 348f1b9

Please sign in to comment.