示例#1
0
 public function check()
 {
     $this->setView('reclaim/index');
     if (Session::isLoggedIn()) {
         return Error::set('You\'re logged in!');
     }
     $this->view['valid'] = true;
     $this->view['publicKey'] = Config::get('recaptcha:publicKey');
     if (empty($_POST['recaptcha_challenge_field']) || empty($_POST['recaptcha_response_field'])) {
         return Error::set('We could not find the captcha validation fields!');
     }
     $recaptcha = Recaptcha::check($_POST['recaptcha_challenge_field'], $_POST['recaptcha_response_field']);
     if (is_string($recaptcha)) {
         return Error::set(Recaptcha::$errors[$recaptcha]);
     }
     if (empty($_POST['username']) || empty($_POST['password'])) {
         return Error::set('All forms are required.');
     }
     $reclaims = new reclaims(ConnectionFactory::get('mongo'));
     $good = $reclaims->authenticate($_POST['username'], $_POST['password']);
     if (!$good) {
         return Error::set('Invalid username/password.');
     }
     $reclaims->import($_POST['username'], $_POST['password']);
     $users = new users(ConnectionFactory::get('mongo'));
     $users->authenticate($_POST['username'], $_POST['password']);
     header('Location: ' . Url::format('/'));
 }
 public function checkRecaptcha(Model $model, $field)
 {
     App::uses('Recaptcha', 'Recaptcha.Lib');
     if (!class_exists('Recaptcha')) {
         throw new InternalErrorException(__('Recaptcha library not found'));
     }
     try {
         return Recaptcha::check($model->data[$model->alias]['recaptcha_challenge_field'], $model->data[$model->alias]['recaptcha_response_field']);
     } catch (Exception $e) {
         return false;
     }
 }
示例#3
0
 public function isValid()
 {
     if (!isset($this->controller->request->data[$this->model])) {
         return false;
     }
     $data = $this->controller->request->data[$this->model];
     if (!isset($data['recaptcha_challenge_field']) || !isset($data['recaptcha_response_field'])) {
         return false;
     }
     App::uses('Recaptcha', 'Recaptcha.Lib');
     if (!class_exists('Recaptcha')) {
         throw new InternalErrorException(__('Recaptcha library not found'));
     }
     try {
         return Recaptcha::check($data['recaptcha_challenge_field'], $data['recaptcha_response_field']);
     } catch (Exception $e) {
         return false;
     }
 }
示例#4
0
 public function login()
 {
     $this->view['captcha'] = false;
     $key = 'invalidLogin_' . $_SERVER['REMOTE_ADDR'];
     if (apc_exists($key)) {
         $value = apc_fetch($key);
         if ($value > 3) {
             $this->view['publicKey'] = Config::get('recaptcha:publicKey');
             $this->view['captcha'] = true;
         }
         if ($value > 15) {
             return Error::set('No.  Bad boy.');
         }
     }
     if (!isset($_POST['username']) || !isset($_POST['password'])) {
         return;
     }
     $username = empty($_POST['username']) ? null : $_POST['username'];
     $password = empty($_POST['password']) ? null : $_POST['password'];
     if ($this->view['captcha'] && $value != 4) {
         if (empty($_POST['recaptcha_challenge_field']) || empty($_POST['recaptcha_response_field'])) {
             return Error::set('We could not find the captcha validation fields!');
         }
         $recaptcha = Recaptcha::check($_POST['recaptcha_challenge_field'], $_POST['recaptcha_response_field']);
         if (is_string($recaptcha)) {
             return Error::set(Recaptcha::$errors[$recaptcha]);
         }
     }
     $users = new users(ConnectionFactory::get('mongo'));
     $good = $users->authenticate($username, $password);
     if (is_string($good)) {
         if (!apc_exists($key)) {
             apc_store($key, 2, 300);
         } else {
             apc_inc($key, 1);
         }
         return Error::set($good);
     }
     Log::login($good['_id']);
     header('Location: ' . Url::format('/'));
 }
示例#5
0
use Tectonic\Shift\Modules\Identity\Users\Contracts\UserRepositoryInterface;
/**
 * A collection of additional validators for global use.
 *
 * @authors Kirk Bushell
 * @date 25th November 2014
 */
/**
 * Only really applies to the email field. Checks to see whether or not the email address
 * is unique to the account the user is signing up for.
 *
 * @param string $attribute Not used.
 * @param string $email
 * @return boolean
 */
Validator::extend('unique_account', function ($attribute, $email) {
    $userRepository = App::make(UserRepositoryInterface::class);
    return !$userRepository->getByEmailAndAccount($email, CurrentAccount::get());
});
/**
 * The following validator uses the recaptcha library to check the response from the
 * google servers and returns boolean true or false based on that response.
 *
 * @param string $attribute
 * @param string $value
 * @param array $params
 * @return boolean
 */
Validator::extend('recaptcha', function ($attribute, $value, $params) {
    return Recaptcha::check(Request::ip(), $value);
});