Skip to content

Commit

Permalink
Merge pull request #7 from asundust/analysis-2QE52R
Browse files Browse the repository at this point in the history
Apply fixes from StyleCI
  • Loading branch information
asundust authored Aug 20, 2021
2 parents d85e5c6 + 5ddf1da commit 8827842
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 39 deletions.
38 changes: 19 additions & 19 deletions src/Http/Controllers/DcatAuthCaptchaController.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,9 @@ public function __construct()
$version = app()->make('\Mnabialek\LaravelVersion\Version');
$arr = explode('.', $version->get());
if ($arr[0] >= 8) {
$this->middleware(DcatAuthCaptchaThrottleMiddleware::class . ':' . $throttle)->only('postLogin');
$this->middleware(DcatAuthCaptchaThrottleMiddleware::class.':'.$throttle)->only('postLogin');
} else {
$this->middleware(DcatAuthCaptchaThrottleMiddlewareBelow8::class . ':' . $throttle)->only('postLogin');
$this->middleware(DcatAuthCaptchaThrottleMiddlewareBelow8::class.':'.$throttle)->only('postLogin');
}
}
}
Expand Down Expand Up @@ -178,7 +178,7 @@ public function getLogin(Content $content)
break;
}

return $content->full()->body(view(DcatAuthCaptchaServiceProvider::instance()->getName() . '::' . $this->captchaProvider . '.' . $this->providerStyles[$this->captchaProvider][$this->captchaStyle], [
return $content->full()->body(view(DcatAuthCaptchaServiceProvider::instance()->getName().'::'.$this->captchaProvider.'.'.$this->providerStyles[$this->captchaProvider][$this->captchaStyle], [
'captchaAppid' => $this->captchaAppid,
'captchaStyle' => $this->captchaStyle,
'extConfig' => $extConfig,
Expand All @@ -201,7 +201,7 @@ private function getGeetestStatus(): array
'new_captcha' => 1,
'user_id' => '',
];
$url = 'http://api.geetest.com/register.php?' . http_build_query($params);
$url = 'http://api.geetest.com/register.php?'.http_build_query($params);
$response = $this->captchaHttp()->get($url);
$statusCode = $response->getStatusCode();
$contents = $response->getBody()->getContents();
Expand All @@ -222,7 +222,7 @@ private function getGeetestStatus(): array
*/
private function geetestSuccessProcess($challenge): array
{
$challenge = md5($challenge . $this->captchaSecret);
$challenge = md5($challenge.$this->captchaSecret);
$result = [
'success' => 1,
'gt' => $this->captchaAppid,
Expand All @@ -241,7 +241,7 @@ private function geetestFailProcess(): array
{
$rnd1 = md5(rand(0, 100));
$rnd2 = md5(rand(0, 100));
$challenge = $rnd1 . substr($rnd2, 0, 2);
$challenge = $rnd1.substr($rnd2, 0, 2);
$result = [
'success' => 0,
'gt' => $this->captchaAppid,
Expand All @@ -264,10 +264,10 @@ private function getVerify5Token()
{
$params = [
'appid' => $this->captchaAppid,
'timestamp' => now()->timestamp . '000',
'timestamp' => now()->timestamp.'000',
];
$params['signature'] = $this->getSignature($this->captchaSecret, $params);
$url = 'https://' . DcatAuthCaptchaServiceProvider::setting('host') . '/openapi/getToken?' . http_build_query($params);
$url = 'https://'.DcatAuthCaptchaServiceProvider::setting('host').'/openapi/getToken?'.http_build_query($params);
$response = $this->captchaHttp()->get($url);
$statusCode = $response->getStatusCode();
$contents = $response->getBody()->getContents();
Expand Down Expand Up @@ -358,12 +358,12 @@ private function captchaValidateDingxiang(Request $request)
$params = [
'appKey' => $this->captchaAppid,
'constId' => $tokenArr[1],
'sign' => md5($this->captchaSecret . $tokenArr[0] . $this->captchaSecret),
'sign' => md5($this->captchaSecret.$tokenArr[0].$this->captchaSecret),
'token' => $tokenArr[0],
];

$url = 'https://cap.dingxiang-inc.com/api/tokenVerify';
$response = $this->captchaHttp()->get($url . '?' . http_build_query($params));
$response = $this->captchaHttp()->get($url.'?'.http_build_query($params));
$statusCode = $response->getStatusCode();
$contents = $response->getBody()->getContents();

Expand Down Expand Up @@ -495,7 +495,7 @@ private function captchaValidateRecaptcha(Request $request)
'remoteip' => $request->ip(),
];

$url = rtrim(DcatAuthCaptchaServiceProvider::setting('domain') ?? 'https://recaptcha.net') . '/recaptcha/api/siteverify';
$url = rtrim(DcatAuthCaptchaServiceProvider::setting('domain') ?? 'https://recaptcha.net').'/recaptcha/api/siteverify';
$response = $this->captchaHttp()->post($url, [
'form_params' => $params,
]);
Expand Down Expand Up @@ -544,7 +544,7 @@ private function captchaValidateTencent(Request $request)
];

$url = 'https://ssl.captcha.qq.com/ticket/verify';
$response = $this->captchaHttp()->get($url . '?' . http_build_query($params));
$response = $this->captchaHttp()->get($url.'?'.http_build_query($params));
$statusCode = $response->getStatusCode();
$contents = $response->getBody()->getContents();

Expand Down Expand Up @@ -578,10 +578,10 @@ private function captchaValidateVerify5(Request $request)
'host' => DcatAuthCaptchaServiceProvider::setting('host'),
'verifyid' => $token,
'token' => $verify5Token,
'timestamp' => now()->timestamp . '000',
'timestamp' => now()->timestamp.'000',
];
$params['signature'] = $this->getSignature($this->captchaSecret, $params);
$url = 'https://' . DcatAuthCaptchaServiceProvider::setting('host') . '/openapi/verify?' . http_build_query($params);
$url = 'https://'.DcatAuthCaptchaServiceProvider::setting('host').'/openapi/verify?'.http_build_query($params);
$response = $this->captchaHttp()->get($url);
$statusCode = $response->getStatusCode();
$contents = $response->getBody()->getContents();
Expand Down Expand Up @@ -660,7 +660,7 @@ private function captchaValidateWangyi(Request $request)
'user' => '',
'secretId' => $this->captchaSecret,
'version' => 'v2',
'timestamp' => now()->timestamp . '000',
'timestamp' => now()->timestamp.'000',
'nonce' => Str::random(),
];

Expand Down Expand Up @@ -713,7 +713,7 @@ private function captchaValidateYunpian(Request $request)
'secretId' => $this->captchaSecret,
'user' => '',
'version' => '1.0',
'timestamp' => now()->timestamp . '000',
'timestamp' => now()->timestamp.'000',
'nonce' => Str::random(),
];

Expand Down Expand Up @@ -749,7 +749,7 @@ private function getSignature($secretKey, $params): string
ksort($params);
$str = '';
foreach ($params as $key => $value) {
$str .= $key . $value;
$str .= $key.$value;
}
$str .= $secretKey;

Expand All @@ -764,7 +764,7 @@ private function getSignature($secretKey, $params): string
private function loginValidate(Request $request)
{
$credentials = $request->only([$this->username(), 'password']);
$remember = (bool)$request->input('remember', false);
$remember = (bool) $request->input('remember', false);

/** @var \Illuminate\Validation\Validator $validator */
$validator = Validator::make($credentials, [
Expand Down Expand Up @@ -804,7 +804,7 @@ private function captchaHttp(): Client
*/
private function toTrans($type): ?string
{
return DcatAuthCaptchaServiceProvider::trans('dcat-auth-captcha.messages.' . $type);
return DcatAuthCaptchaServiceProvider::trans('dcat-auth-captcha.messages.'.$type);
}

/**
Expand Down
10 changes: 5 additions & 5 deletions src/Http/Middleware/DcatAuthCaptchaThrottleMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ class DcatAuthCaptchaThrottleMiddleware extends ThrottleRequests
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param Closure $next
* @param array $limits
*
* @return \Symfony\Component\HttpFoundation\Response
*
* @throws \Illuminate\Http\Exceptions\ThrottleRequestsException
Expand Down Expand Up @@ -48,9 +47,10 @@ protected function handleRequest($request, Closure $next, array $limits)
* Create a 'too many attempts' exception.
*
* @param \Illuminate\Http\Request $request
* @param string $key
* @param int $maxAttempts
* @param callable|null $responseCallback
* @param string $key
* @param int $maxAttempts
* @param callable|null $responseCallback
*
* @return \Illuminate\Http\Exceptions\HttpResponseException|\Illuminate\Http\Exceptions\ThrottleRequestsException|\Illuminate\Http\JsonResponse
*/
protected function buildException($request, $key, $maxAttempts, $responseCallback = null)
Expand Down
13 changes: 7 additions & 6 deletions src/Http/Middleware/DcatAuthCaptchaThrottleMiddlewareBelow8.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,17 @@ class DcatAuthCaptchaThrottleMiddlewareBelow8 extends ThrottleRequests
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param Closure $next
* @param int|string $maxAttempts
* @param float|int $decayMinutes
* @param string $prefix
* @param int|string $maxAttempts
* @param float|int $decayMinutes
* @param string $prefix
*
* @return \Symfony\Component\HttpFoundation\Response
*
* @throws \Illuminate\Http\Exceptions\ThrottleRequestsException
*/
public function handle($request, Closure $next, $maxAttempts = 60, $decayMinutes = 1, $prefix = '')
{
$key = $prefix . $this->resolveRequestSignature($request);
$key = $prefix.$this->resolveRequestSignature($request);

$maxAttempts = $this->resolveMaxAttempts($request, $maxAttempts);

Expand All @@ -47,7 +47,8 @@ public function handle($request, Closure $next, $maxAttempts = 60, $decayMinutes
* Create a 'too many attempts' exception.
*
* @param string $key
* @param int $maxAttempts
* @param int $maxAttempts
*
* @return \Illuminate\Http\Exceptions\ThrottleRequestsException|\Illuminate\Http\JsonResponse
*/
protected function buildException($key, $maxAttempts)
Expand Down
18 changes: 9 additions & 9 deletions src/Setting.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,42 +27,42 @@ public function form()
];

$documentHelp = $this->toTrans('parameters_document');
$documentAddress = ' <a href="https://github.com/asundust/dcat-auth-captcha/blob/master/README.md#%E8%8E%B7%E5%8F%96%E5%AF%86%E9%92%A5%E5%8F%82%E6%95%B0%E9%85%8D%E7%BD%AE" target="_blank">' . $this->toTrans('document_address') . '</a>';
$documentAddress = ' <a href="https://github.com/asundust/dcat-auth-captcha/blob/master/README.md#%E8%8E%B7%E5%8F%96%E5%AF%86%E9%92%A5%E5%8F%82%E6%95%B0%E9%85%8D%E7%BD%AE" target="_blank">'.$this->toTrans('document_address').'</a>';

$this->select('provider', $this->toTrans('provider'))
->options($providers)
->required();
$this->text('appid', $this->toTrans('appid'))->required();
$this->text('secret', $this->toTrans('secret'))->required();
$this->text('style', $this->toTrans('style'))
->help($documentHelp . $documentAddress);
->help($documentHelp.$documentAddress);
$this->text('timeout', $this->toTrans('timeout'))
->help($this->toTrans('timeout_help'));
$this->text('secret_key', $this->toTrans('secret_key'))
->help($documentHelp . $documentAddress);
->help($documentHelp.$documentAddress);
$this->text('host', $this->toTrans('host'))
->help($documentHelp . $documentAddress);
->help($documentHelp.$documentAddress);
$this->text('domain', $this->toTrans('domain'))
->help($documentHelp . $documentAddress);
->help($documentHelp.$documentAddress);
$this->text('score', $this->toTrans('score'))
->help($documentHelp . $documentAddress);
->help($documentHelp.$documentAddress);
$this->textarea('ext_config', $this->toTrans('ext_config'))
->help($this->toTrans('tip_json'));
if (in_array(config('app.locale'), ['zh-CN', 'zh_CN'])) {
$throttleHref = 'https://learnku.com/docs/laravel/7.x/routing/7458#5c3711';
} else {
$throttleHref = 'https://laravel.com/docs/7.x/routing#rate-limiting';
}
$throttleDocumentAddress = ' <a href="' . $throttleHref . '" target="_blank">' . $this->toTrans('document_address') . '</a>';
$throttleDocumentAddress = ' <a href="'.$throttleHref.'" target="_blank">'.$this->toTrans('document_address').'</a>';
$this->text('login_try_throttle', $this->toTrans('login_try_throttle'))
->help($documentHelp . $throttleDocumentAddress);
->help($documentHelp.$throttleDocumentAddress);
}

/**
* @param $key
*/
public function toTrans($key): string
{
return $this->trans('dcat-auth-captcha.' . $key);
return $this->trans('dcat-auth-captcha.'.$key);
}
}

0 comments on commit 8827842

Please sign in to comment.