Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
N
no-captcha
Project overview
Project overview
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
CENTER-TBI
no-captcha
Commits
1c6c59ef
Commit
1c6c59ef
authored
Sep 07, 2015
by
Nguyen Van Anh
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
PSR2
parent
ae2c86af
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
203 additions
and
205 deletions
+203
-205
src/Facades/NoCaptcha.php
src/Facades/NoCaptcha.php
+14
-10
src/NoCaptcha.php
src/NoCaptcha.php
+130
-124
src/NoCaptchaServiceProvider.php
src/NoCaptchaServiceProvider.php
+57
-66
src/config/captcha.php
src/config/captcha.php
+2
-5
No files found.
src/Facades/NoCaptcha.php
View file @
1c6c59ef
<?php
namespace
Anhskohbo\NoCaptcha\Facades
;
<?php
use
Illuminate\Support\Facades\Facade
;
namespace
Anhskohbo\NoCaptcha\Facades
;
class
NoCaptcha
extends
Facade
{
use
Illuminate\Support\Facades\Facade
;
class
NoCaptcha
extends
Facade
{
/**
* Get the registered name of the component.
*
* @return string
*/
protected
static
function
getFacadeAccessor
()
{
return
'captcha'
;
}
protected
static
function
getFacadeAccessor
()
{
return
'captcha'
;
}
}
src/NoCaptcha.php
View file @
1c6c59ef
<?php
namespace
Anhskohbo\NoCaptcha
;
<?php
use
Symfony\Component\HttpFoundation\Request
;
namespace
Anhskohbo\NoCaptcha
;
class
NoCaptcha
{
use
Symfony\Component\HttpFoundation\Request
;
class
NoCaptcha
{
const
CLIENT_API
=
'https://www.google.com/recaptcha/api.js'
;
const
VERIFY_URL
=
'https://www.google.com/recaptcha/api/siteverify'
;
/**
* //
* The recaptcha secret key.
*
* @var string
*/
protected
$secret
;
/**
* //
* The recaptcha sitekey key.
*
* @var string
*/
protected
$sitekey
;
/**
* //
* NoCaptcha.
*
* @param string $secret
* @param string $sitekey
...
...
@@ -34,7 +36,7 @@ class NoCaptcha {
}
/**
* //
* Render HTML captcha.
*
* @return string
*/
...
...
@@ -49,29 +51,33 @@ class NoCaptcha {
}
/**
* //
* Verify no-captcha response.
*
* @param string $response
* @param string $clientIp
*
* @return bool
*/
public
function
verifyResponse
(
$response
,
$clientIp
=
null
)
{
if
(
empty
(
$response
))
return
false
;
if
(
empty
(
$response
))
{
return
false
;
}
$response
=
$this
->
sendRequestVerify
([
'secret'
=>
$this
->
secret
,
'response'
=>
$response
,
'remoteip'
=>
$clientIp
'remoteip'
=>
$clientIp
,
]);
return
isset
(
$response
[
'success'
])
&&
$response
[
'success'
]
===
true
;
}
/**
* //
* Verify no-captcha response by Symfony Request.
*
* @param Request $request
*
* @return bool
*/
public
function
verifyRequest
(
Request
$request
)
...
...
@@ -83,7 +89,7 @@ class NoCaptcha {
}
/**
* //
* Get recaptcha js link.
*
* @return string
*/
...
...
@@ -93,9 +99,10 @@ class NoCaptcha {
}
/**
* //
* Send verify request.
*
* @param array $query
*
* @return array
*/
protected
function
sendRequestVerify
(
array
$query
=
[])
...
...
@@ -108,21 +115,20 @@ class NoCaptcha {
}
/**
* //
* Build HTML attributes.
*
* @param array $attributes
*
* @return string
*/
protected
function
buildAttributes
(
array
$attributes
)
{
$html
=
[];
foreach
(
$attributes
as
$key
=>
$value
)
{
foreach
(
$attributes
as
$key
=>
$value
)
{
$html
[]
=
$key
.
'="'
.
$value
.
'"'
;
}
return
count
(
$html
)
?
' '
.
implode
(
' '
,
$html
)
:
''
;
}
}
src/NoCaptchaServiceProvider.php
View file @
1c6c59ef
<?php
namespace
Anhskohbo\NoCaptcha
;
<?php
use
Illuminate\Support\ServiceProvider
;
namespace
Anhskohbo\NoCaptcha
;
class
NoCaptchaServiceProvider
extends
ServiceProvider
{
use
Illuminate\Support\ServiceProvider
;
class
NoCaptchaServiceProvider
extends
ServiceProvider
{
/**
* Indicates if loading of the provider is deferred.
*
...
...
@@ -13,8 +15,6 @@ class NoCaptchaServiceProvider extends ServiceProvider {
/**
* Bootstrap the application events.
*
* @return void
*/
public
function
boot
()
{
...
...
@@ -22,24 +22,19 @@ class NoCaptchaServiceProvider extends ServiceProvider {
$this
->
bootConfig
();
$app
[
'validator'
]
->
extend
(
'captcha'
,
function
(
$attribute
,
$value
)
use
(
$app
)
{
$app
[
'validator'
]
->
extend
(
'captcha'
,
function
(
$attribute
,
$value
)
use
(
$app
)
{
return
$app
[
'captcha'
]
->
verifyResponse
(
$value
,
$app
[
'request'
]
->
getClientIp
());
});
if
(
$app
->
bound
(
'form'
))
{
$app
[
'form'
]
->
macro
(
'captcha'
,
function
(
$attributes
=
[])
use
(
$app
)
{
if
(
$app
->
bound
(
'form'
))
{
$app
[
'form'
]
->
macro
(
'captcha'
,
function
(
$attributes
=
[])
use
(
$app
)
{
return
$app
[
'captcha'
]
->
display
(
$attributes
,
$app
->
getLocale
());
});
}
}
/**
* //
*
* @return void
* Booting configure.
*/
protected
function
bootConfig
()
{
...
...
@@ -52,13 +47,10 @@ class NoCaptchaServiceProvider extends ServiceProvider {
/**
* Register the service provider.
*
* @return void
*/
public
function
register
()
{
$this
->
app
->
bind
(
'captcha'
,
function
(
$app
)
{
$this
->
app
->
bind
(
'captcha'
,
function
(
$app
)
{
return
new
NoCaptcha
(
$app
[
'config'
][
'captcha.secret'
],
$app
[
'config'
][
'captcha.sitekey'
]
...
...
@@ -75,5 +67,4 @@ class NoCaptchaServiceProvider extends ServiceProvider {
{
return
[
'captcha'
];
}
}
src/config/captcha.php
View file @
1c6c59ef
<?php
return
[
'secret'
=>
env
(
'NOCAPTCHA_SECRET'
),
'sitekey'
=>
env
(
'NOCAPTCHA_SITEKEY'
),
];
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment