Пример #1
0
 public function loginAction()
 {
     $form = new \Phalcon\Forms\Form();
     $form->add($user = new \Phalcon\Forms\Element\Email('user'));
     $form->add($pass = new \Phalcon\Forms\Element\Password('password'));
     $form->add($twoFactorAuth = new \Phalcon\Forms\Element\Numeric('token'));
     $user->addValidator(new PresenceOf(['message' => 'Username is required.']));
     $pass->addValidator(new PresenceOf(['message' => 'Password is required.']));
     $twoFactorAuth->addValidator(new PresenceOf(['message' => 'Token is required.']));
     $this->view->setVar('form', $form);
     if ($this->request->isPost() && $form->isValid($this->request->getPost())) {
         if (!$this->security->checkToken()) {
             $this->flash->error('The form security token was invalid. Please submit the form again.');
             $this->cleanUpRequest();
             return false;
         }
         $this->tryLogin($this->request->getPost());
     }
     $this->cleanUpRequest();
 }
Пример #2
0
 private function buildLoginForm()
 {
     $form = new \Phalcon\Forms\Form();
     $form->add(new \Phalcon\Forms\Element\Text('email'));
     $form->add(new \Phalcon\Forms\Element\Password('password'));
     $form->add(new \Phalcon\Forms\Element\Check('remember'));
     $form->add(new \Phalcon\Forms\Element\Submit('Login'));
     return $form;
 }
Пример #3
0
<?php

require_once 'src/Recaptcha.php';
require_once 'src/RecaptchaValidator.php';
use Fizz\Phalcon\Recaptcha;
use Fizz\Phalcon\RecaptchaValidator;
// setting up config & di
$config = new Phalcon\Config(array("recaptcha" => array('publicKey' => '[...your pub key goes here...]', 'secretKey' => '[...your priv key goes here...]', 'jsApiUrl' => 'https://www.google.com/recaptcha/api.js', 'verifyUrl' => 'https://www.google.com/recaptcha/api/siteverify')));
$di = new Phalcon\DI\FactoryDefault();
$di->set('config', $config);
// creating form and recaptcha adding recaptcha to the form
$form = new Phalcon\Forms\Form();
$form->setDI($di);
$recaptcha = new Recaptcha('recaptcha');
$recaptcha->addValidator(new RecaptchaValidator(array('message' => "Are you human? (custom message)")));
$form->add($recaptcha);
// example of validation)
$post = array('g_recaptcha_response' => 'abzfoobar');
if ($form->isValid($post)) {
    echo 'ok';
} else {
    print_r($form->getMessages());
}