Skip to content

Commit

Permalink
Merge pull request #903 from LuckyCyborg/master
Browse files Browse the repository at this point in the history
Complete the integration of Google ReCaptcha on Users Module
  • Loading branch information
daveismynamecom committed May 30, 2016
2 parents c2a6747 + c33c608 commit 7258d53
Show file tree
Hide file tree
Showing 19 changed files with 61 additions and 10 deletions.
1 change: 1 addition & 0 deletions app/Config.example.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@
* Setup the Google reCAPTCHA configuration
*/
Config::set('recaptcha', array(
'active' => false,
'siteKey' => '',
'secret' => '',
));
Expand Down
11 changes: 9 additions & 2 deletions app/Modules/Users/Controllers/Reminders.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Core\Controller;
use Core\View;
use Helpers\Url;
use Helpers\ReCaptcha;

use Hash;
use Input;
Expand Down Expand Up @@ -59,10 +60,16 @@ public function remind()
*/
public function postRemind()
{
$credentials = Input::only('email');

$error = array();

// Verify the reCAPTCHA
if(! ReCaptcha::check()) {
return Redirect::back()->with('error', $error[] = __d('users', 'Invalid reCAPTCHA submitted.'));
}

//
$credentials = Input::only('email');

switch ($response = Password::remind($credentials)) {
case Password::INVALID_USER:
return Redirect::back()->with('error', $error[] = __d('users', 'We can\'t find a User with that e-mail address.'));
Expand Down
7 changes: 7 additions & 0 deletions app/Modules/Users/Controllers/Users.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@

namespace App\Modules\Users\Controllers;

use Core\Config;
use Core\Controller;
use Core\View;
use Helpers\Url;
use Helpers\ReCaptcha;

use Auth;
use Hash;
Expand Down Expand Up @@ -61,6 +63,11 @@ public function postLogin()
{
$error = array();

// Verify the submitted reCAPTCHA
if(! ReCaptcha::check()) {
return Redirect::back()->with('error', $error[] = __d('users', 'Invalid reCAPTCHA submitted.'));
}

// Retrieve the Authentication credentials.
$credentials = Input::only('username', 'password');

Expand Down
1 change: 1 addition & 0 deletions app/Modules/Users/Language/Cz/messages.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
'Insert the current E-Mail' => '',
'Insert the current Password' => '',
'Insert the new Password' => '',
'Invalid reCAPTCHA submitted.' => '',
'Login' => '',
'Login to <b>{0}</b>' => '',
'Password' => '',
Expand Down
1 change: 1 addition & 0 deletions app/Modules/Users/Language/Da/messages.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
'Insert the current E-Mail' => '',
'Insert the current Password' => 'Indtast den nuværende kodeord',
'Insert the new Password' => 'Indtast det nye kodeord',
'Invalid reCAPTCHA submitted.' => '',
'Login' => '',
'Login to <b>{0}</b>' => '',
'Password' => 'Kodeord',
Expand Down
1 change: 1 addition & 0 deletions app/Modules/Users/Language/De/messages.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
'Insert the current E-Mail' => '',
'Insert the current Password' => '',
'Insert the new Password' => '',
'Invalid reCAPTCHA submitted.' => '',
'Login' => '',
'Login to <b>{0}</b>' => '',
'Password' => '',
Expand Down
1 change: 1 addition & 0 deletions app/Modules/Users/Language/En/messages.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
'Insert the current E-Mail' => '',
'Insert the current Password' => '',
'Insert the new Password' => '',
'Invalid reCAPTCHA submitted.' => '',
'Login' => '',
'Login to <b>{0}</b>' => '',
'Password' => '',
Expand Down
1 change: 1 addition & 0 deletions app/Modules/Users/Language/Es/messages.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
'Insert the current E-Mail' => '',
'Insert the current Password' => '',
'Insert the new Password' => '',
'Invalid reCAPTCHA submitted.' => '',
'Login' => '',
'Login to <b>{0}</b>' => '',
'Password' => '',
Expand Down
1 change: 1 addition & 0 deletions app/Modules/Users/Language/Fa/messages.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
'Insert the current E-Mail' => '',
'Insert the current Password' => 'رمزعبور فعلی را وارد کنید',
'Insert the new Password' => 'رمزعبور جدید را وارد کنید',
'Invalid reCAPTCHA submitted.' => '',
'Login' => '',
'Login to <b>{0}</b>' => '',
'Password' => 'رمزعبور',
Expand Down
1 change: 1 addition & 0 deletions app/Modules/Users/Language/Fr/messages.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
'Insert the current E-Mail' => '',
'Insert the current Password' => '',
'Insert the new Password' => '',
'Invalid reCAPTCHA submitted.' => '',
'Login' => '',
'Login to <b>{0}</b>' => '',
'Password' => '',
Expand Down
1 change: 1 addition & 0 deletions app/Modules/Users/Language/It/messages.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
'Insert the current E-Mail' => '',
'Insert the current Password' => '',
'Insert the new Password' => '',
'Invalid reCAPTCHA submitted.' => '',
'Login' => '',
'Login to <b>{0}</b>' => '',
'Password' => '',
Expand Down
1 change: 1 addition & 0 deletions app/Modules/Users/Language/Ja/messages.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
'Insert the current E-Mail' => '',
'Insert the current Password' => '',
'Insert the new Password' => '',
'Invalid reCAPTCHA submitted.' => '',
'Login' => '',
'Login to <b>{0}</b>' => '',
'Password' => '',
Expand Down
1 change: 1 addition & 0 deletions app/Modules/Users/Language/Nl/messages.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
'Insert the current E-Mail' => '',
'Insert the current Password' => '',
'Insert the new Password' => '',
'Invalid reCAPTCHA submitted.' => '',
'Login' => '',
'Login to <b>{0}</b>' => '',
'Password' => '',
Expand Down
1 change: 1 addition & 0 deletions app/Modules/Users/Language/Pl/messages.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
'Insert the current E-Mail' => '',
'Insert the current Password' => '',
'Insert the new Password' => '',
'Invalid reCAPTCHA submitted.' => '',
'Login' => '',
'Login to <b>{0}</b>' => '',
'Password' => '',
Expand Down
1 change: 1 addition & 0 deletions app/Modules/Users/Language/Ro/messages.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
'Insert the current E-Mail' => '',
'Insert the current Password' => '',
'Insert the new Password' => '',
'Invalid reCAPTCHA submitted.' => '',
'Login' => '',
'Login to <b>{0}</b>' => '',
'Password' => '',
Expand Down
1 change: 1 addition & 0 deletions app/Modules/Users/Language/Ru/messages.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
'Insert the current E-Mail' => '',
'Insert the current Password' => '',
'Insert the new Password' => '',
'Invalid reCAPTCHA submitted.' => '',
'Login' => '',
'Login to <b>{0}</b>' => '',
'Password' => '',
Expand Down
4 changes: 3 additions & 1 deletion app/Modules/Users/Views/Reminders/Remind.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,13 @@
<div class="form-group">
<p><input type="email" name="email" id="email" class="form-control input-lg col-xs-12 col-sm-12 col-md-12" placeholder="<?= __d('users', 'E-mail'); ?>"><br><br></p>
</div>
<?php $recaptchaSiteKey = Config::get('recaptcha.siteKey'); if (! empty($recaptchaSiteKey)) { ?>
<div class="row pull-right" style="margin-top: 10px; margin-right: 0;">
<div class="g-recaptcha" data-sitekey="<?= Config::get('recaptcha.siteKey'); ?>"></div>
<div class="g-recaptcha" data-sitekey="<?= $recaptchaSiteKey; ?>"></div>
</div>
<div class="clearfix"></div>
<hr>
<?php } ?>
<div class="row" style="margin-top: 22px;">
<div class="col-xs-6 col-sm-6 col-md-6">
<input type="submit" name="submit" class="btn btn-success col-sm-10" value="<?= __d('users', 'Send Reset Link'); ?>">
Expand Down
4 changes: 3 additions & 1 deletion app/Modules/Users/Views/Users/Login.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,13 @@
<p><label><input name="remember" type="checkbox"> <?= __d('users', 'Remember me'); ?></label></p>
</div>
<hr>
<?php $recaptchaSiteKey = Config::get('recaptcha.siteKey'); if (! empty($recaptchaSiteKey)) { ?>
<div class="row pull-right" style="margin-right: 0;">
<div class="g-recaptcha" data-sitekey="<?= Config::get('recaptcha.siteKey'); ?>"></div>
<div class="g-recaptcha" data-sitekey="<?= $recaptchaSiteKey; ?>"></div>
</div>
<div class="clearfix"></div>
<hr>
<?php } ?>
<div class="form-group" style="margin-top: 22px;">
<div class="col-xs-6 col-sm-6 col-md-6">
<input type="submit" name="submit" class="btn btn-success col-sm-8" value="<?= __d('users', 'Login'); ?>">
Expand Down
31 changes: 25 additions & 6 deletions system/Helpers/ReCaptcha.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ class ReCaptcha
*/
const GOOGLEHOST = 'https://www.google.com/recaptcha/api/siteverify';

private $active = true;

private $siteKey;
private $secret;

Expand All @@ -35,8 +37,22 @@ public function __construct()
//
$config = Config::get('recaptcha');

$this->recaptcha_siteKey = $config['siteKey'];
$this->recaptcha_secret = $config'secret'];
// Wheter is active or not.
$this->active = $config['active'];

// The Google keys
$this->siteKey = $config['siteKey'];
$this->secret = $config['secret'];
}

/**
* Get the Status
*
* @return string
*/
protected function isActive()
{
return $this->active;
}

/**
Expand Down Expand Up @@ -65,11 +81,14 @@ protected function getSecret()
* @param string $response
* @return boolean
*/
protected function checkResponse($response)
protected function check($response = null)
{
if (empty($response)) {
return false;
}
if(! $this->active) return true;

//
$response = $response ?: Request::input('g-recaptcha-response', '');

if (empty($response)) return false;

$google_url = sprintf('%s?secret=%s&response=%s&remoteip=%s',
self::GOOGLEHOST,
Expand Down

0 comments on commit 7258d53

Please sign in to comment.