public function getForm($hasCaptcha, $url = '', $captchaPath = '')
 {
     if (!$this->form) {
         $form = new Form();
         $txtUser = new Element\Text('username');
         $txtUser->setLabel('User Name')->setAttribute('class', 'form-control')->setAttribute('placeholder', 'User name');
         $password = new Element\Password('password');
         $password->setLabel('Password')->setAttribute('class', 'form-control')->setAttribute('placeholder', 'Password');
         $remember = new Element\Checkbox('remember');
         $remember->setLabel('Save authentication?')->setAttribute('class', 'form-control');
         if ($hasCaptcha) {
             $captchaImage = new Image();
             $captchaImage->setFont('./data/font/CAMBRIA.TTC')->setWidth(200)->setHeight(60)->setDotNoiseLevel(40)->setLineNoiseLevel(4)->setExpiration(90);
             $captchaImage->setImgUrl($url);
             $captchaImage->setImgDir($captchaPath);
             $captcha = new Element\Captcha('isHuman');
             $captcha->setCaptcha($captchaImage)->setAttributes(array('class' => 'form-control'));
             $form->add($captcha);
         }
         $form->setAttribute('class', 'form-horizontal');
         $form->add($txtUser);
         $form->add($password);
         $form->add($remember);
         $this->form = $form;
     }
     return $this->form;
 }
 public function prepareElements($topicList, $categoryList, $captchaOptions)
 {
     // repurpose $topicList and $categoryList
     $topics = array('---' => 'Choose');
     foreach ($topicList as $item) {
         $topics[$item->item] = $item->item;
     }
     $categories = array('---' => 'Choose');
     foreach ($categoryList as $item) {
         $categories[$item->item] = $item->item;
     }
     $author = new Element\Hidden('author');
     $category1 = new Element\Text('category');
     $category1->setLabel('Category')->setAttribute('title', 'Enter a category: i.e. zf2 or use the dropdown list below')->setAttribute('size', 16)->setAttribute('maxlength', 16);
     $category2 = new Element\Select('selectCategory');
     $category2->setValueOptions($categories);
     $topic1 = new Element\Text('topic');
     $topic1->setLabel('Topic')->setAttribute('title', 'Enter a topic code: i.e. zf2f-2013-02-25 or use the dropdown list below')->setAttribute('size', 60)->setAttribute('maxlength', 254);
     $topic2 = new Element\Select('selectTopic');
     $topic2->setValueOptions($topics);
     $title = new Element\Text('title');
     $title->setLabel('Title')->setAttribute('title', 'Enter a suitable title for this posting')->setAttribute('size', 60)->setAttribute('maxlength', 254);
     $body = new Element\Textarea('body');
     $body->setLabel('Body')->setAttribute('title', 'Enter the body for this posting')->setAttribute('rows', 4)->setAttribute('cols', 60);
     $captcha = new Element\Captcha('captcha');
     $captchaAdapter = new Captcha\Image();
     $captchaAdapter->setWordlen(4)->setOptions($captchaOptions);
     $captcha->setCaptcha($captchaAdapter)->setLabel('Help us to prevent SPAM!')->setAttribute('class', 'captchaStyle')->setAttribute('title', 'Help to prevent SPAM');
     $submit = new Element\Submit('submit');
     $submit->setAttribute('value', 'Post')->setAttribute('title', 'Click here when done');
     $this->add($author)->add($topic1)->add($topic2)->add($category1)->add($category2)->add($title)->add($body)->add($captcha)->add($submit);
 }
Example #3
0
 /**
  * Init Module form
  *
  * @return void
  */
 public function init()
 {
     $showEmail = new Element\Checkbox('show_email');
     $showEmail->setLabel('Show email');
     $showEmail->setAttribute('required', 'required')->setAttribute('id', 'show-email');
     $username = new Element\Text('username');
     $username->setLabel('Username');
     $username->setAttribute('required', 'required')->setAttribute('id', 'username');
     $email = new Element\Text('email');
     $email->setLabel('Email');
     $email->setAttribute('required', 'required')->setAttribute('id', 'email');
     $message = new Element\Textarea('message');
     $message->setLabel('Message');
     $message->setAttribute('required', 'required')->setAttribute('id', 'message');
     $captchaImage = new CaptchaImage(array('font' => GC_PUBLIC_PATH . '/backend/fonts/arial.ttf', 'width' => 250, 'height' => 50, 'dotNoiseLevel' => 40, 'lineNoiseLevel' => 3));
     $captchaImage->setImgDir(GC_PUBLIC_PATH . '/frontend/tmp');
     $captchaImage->setImgUrl('/frontend/tmp');
     $captcha = new Element\Captcha('captcha');
     $captcha->setLabel('Please verify you are human')->setCaptcha($captchaImage)->setAttribute('required', 'required')->setAttribute('id', 'captcha');
     $this->add($showEmail);
     $this->add($username);
     $this->add($email);
     $this->add($message);
     $this->add($captcha);
     $inputFilterFactory = new InputFilterFactory();
     $inputFilter = $inputFilterFactory->createInputFilter(array('show_email' => array('name' => 'show_email', 'required' => false), 'username' => array('name' => 'username', 'required' => true), 'email' => array('name' => 'email', 'required' => true, 'validators' => array(array('name' => 'email_address'))), 'message' => array('name' => 'message', 'required' => true), 'captcha' => $captcha->getInputSpecification()));
     $this->setInputFilter($inputFilter);
 }
Example #4
0
 public function buildForm()
 {
     $this->setAttribute('method', 'POST');
     $category = new Select('category');
     $category->setLabel('Category')->setValueOptions(array_combine($this->getCategories(), $this->getCategories()));
     $title = new Text('title');
     $title->setLabel('Title')->setAttributes(array('size' => 50, 'maxLength' => 128, 'required' => 'required', 'placeholder' => 'Title', 'title' => 'Title'));
     $photo = new Text('photo_filename');
     $photo->setLabel('Photo')->setAttribute('maxlength', 1024)->setAttribute('placeholder', 'Enter a valid image file URL');
     $name = new Text('contact_name');
     $name->setLabel('Contact Name')->setAttribute('title', 'Contact Name')->setAttribute('size', 50)->setAttribute('maxlength', 255);
     $email = new Email('contact_email');
     $email->setLabel('Contact Email')->setAttribute('title', 'Contact Email')->setAttribute('size', 50)->setAttribute('maxlength', 255);
     $phone = new Text('contact_phone');
     $phone->setLabel('Contact Phone Number')->setAttribute('title', 'Contact Phone Number')->setAttribute('size', 20)->setAttribute('maxlength', 32);
     $city = new Select('cityCode');
     $city->setLabel('Nearest City')->setValueOptions(array_combine(self::$cityCodes, self::$cityCodes))->setAttribute('id', 'cityCode');
     $price = new Text('price');
     $price->setLabel('Price')->setAttribute('title', 'Price as nnn.nn')->setAttribute('size', 16)->setAttribute('maxlength', 16);
     $expires = new Radio('expires');
     $expires->setLabel('Expires')->setAttribute('title', 'The expiration date from today')->setAttribute('class', 'expiresButton')->setValueOptions($this->getExpireDays());
     $deleteCode = new Text('delete_code');
     $deleteCode->setLabel('Delete Code')->setAttribute('title', 'Delete code for this item')->setAttribute('size', 16)->setAttribute('maxlength', 16);
     $description = new Textarea('description');
     $description->setLabel('Description')->setAttribute('title', 'Description')->setAttribute('rows', 5)->setAttribute('cols', 80);
     $captchaAdapter = new ImageCaptcha();
     $captchaAdapter->setWordlen(4)->setOptions($this->captchaOptions);
     $captcha = new Captcha('captcha');
     $captcha->setCaptcha($captchaAdapter)->setLabel('Help us to prevent SPAM!')->setAttribute('class', 'captchaStyle')->setAttribute('title', 'Help us to prevent SPAM');
     $submit = new Submit('submit');
     $submit->setAttribute('value', 'Post');
     $this->add($category)->add($title)->add($photo)->add($name)->add($email)->add($phone)->add($city)->add($price)->add($expires)->add($deleteCode)->add($description)->add($captcha)->add($submit);
 }
Example #5
0
 public static function isValid($id, $word)
 {
     $captcha = new CaptchaImage();
     if ($captcha->isValid(array('id' => $id, 'input' => $word))) {
         return true;
     }
     return false;
 }
 /**
  * Add form elements and attributes
  */
 public function init()
 {
     $this->setName('Login');
     $this->setAttribute('method', 'post');
     $this->add(array('name' => 'email', 'type' => 'text', 'options' => array('label' => $this->translate('E-Mail Address')), 'validators' => array(array('name' => 'EmailAddress'))));
     $captchaImage = new CaptchaImage(array('font' => $_SERVER['DOCUMENT_ROOT'] . '/fonts/arial.ttf', 'width' => 200, 'height' => 80, 'dotNoiseLevel' => 40, 'lineNoiseLevel' => 3));
     $captchaImage->setImgDir($_SERVER['DOCUMENT_ROOT'] . '/captcha');
     $captchaImage->setImgUrl('/captcha');
     $this->add(array('type' => 'Zend\\Form\\Element\\Captcha', 'name' => 'captcha', 'options' => array('label' => $this->translate('Please verify you are human'), 'captcha' => $captchaImage)));
     $this->add(new Element\Csrf('security'));
     $this->add(array('name' => 'submit', 'attributes' => array('class' => 'btn btn-large btn-primary', 'type' => 'submit', 'value' => $this->translate('Request password reset'))));
 }
Example #7
0
 public function __construct($urlcaptcha = null)
 {
     parent::__construct('contact');
     $this->setAttribute('method', 'post');
     $dirdata = './data';
     $captchaImage = new CaptchaImage(array('font' => $dirdata . '/fonts/arial.ttf', 'width' => 250, 'height' => 100, 'dotNoiseLevel' => 40, 'lineNoiseLevel' => 3));
     $captchaImage->setImgDir($dirdata . '/captcha');
     $captchaImage->setImgUrl($urlcaptcha);
     $this->add(array('type' => 'Zend\\Form\\Element\\Captcha', 'name' => 'captcha', 'options' => array('label' => 'Retape ce que tu vois dans la photo', 'captcha' => $captchaImage)));
     $this->add(array('name' => 'message', 'type' => 'textarea', 'options' => array('label' => 'Votre message'), 'attributes' => array('class' => "ckeditor")));
     $this->add(['name' => 'email', 'type' => 'Zend\\Form\\Element\\Text', 'attributes' => ['class' => 'form-control'], 'options' => ['type' => 'text', 'label' => 'E-mail']]);
     $this->add(array('name' => 'submit', 'attributes' => array('type' => 'submit', 'value' => 'commenter', "class" => "btn btn-info")));
 }
Example #8
0
 public function init()
 {
     $this->setAttribute('method', 'post');
     $this->setAttribute('role', 'form');
     $this->add(['type' => 'Zend\\Form\\Element\\Text', 'name' => 'name', 'options' => ['label' => 'NAME', 'object_manager' => $this->objectManager], 'attributes' => ['required' => true, 'min' => 3, 'max' => 30, 'size' => 30, 'placeholder' => 'ENTER_NAME']]);
     $this->add(['type' => 'Zend\\Form\\Element\\Email', 'name' => 'email', 'options' => ['label' => 'EMAIL', 'object_manager' => $this->objectManager], 'attributes' => ['required' => true, 'min' => 3, 'size' => 30, 'placeholder' => '*****@*****.**']]);
     $this->add(['type' => 'Zend\\Form\\Element\\Text', 'name' => 'subject', 'options' => ['label' => 'SUBJECT', 'object_manager' => $this->objectManager], 'attributes' => ['required' => true, 'min' => 3, 'size' => 30, 'placeholder' => 'ENTER_SUBJECT']]);
     $this->add(['type' => 'Zend\\Form\\Element\\Textarea', 'name' => 'message', 'options' => ['label' => 'MESSAGE', 'object_manager' => $this->objectManager], 'attributes' => ['required' => true, 'rows' => 8, 'cols' => 70, 'placeholder' => 'ENTER_MESSAGE']]);
     $captchaImage = new CaptchaImage(['font' => 'public/layouts/default/front/fonts/arial.ttf', 'width' => 180, 'height' => 50, 'size' => 30, 'fsize' => 20, 'dotNoiseLevel' => 10, 'lineNoiseLevel' => 2]);
     $captchaImage->setImgDir('./public/userfiles/captcha');
     $captchaImage->setImgUrl('/userfiles/captcha');
     $this->add(['type' => 'Zend\\Form\\Element\\Captcha', 'name' => 'captcha', 'attributes' => ['class' => 'captcha-input', 'size' => 30, 'placeholder' => 'ENTER_CAPTCHA'], 'options' => ['label' => 'CAPTCHA', 'captcha' => $captchaImage]]);
     $this->add(['name' => 'submit', 'attributes' => ['type' => 'submit', 'id' => 'submitbutton', 'value' => 'SEND']]);
     $this->add(['type' => 'Zend\\Form\\Element\\Csrf', 'name' => 's', 'options' => ['csrf_options' => ['timeout' => 320]]]);
 }
Example #9
0
 public function __construct($height = null, $width = null, $options = null)
 {
     parent::__construct();
     $this->height = !empty($height) ? $height : $this->height;
     $this->width = !empty($width) ? $width : $this->width;
     $this->imgDir = !empty($options['imgDir']) ? $options['imgDir'] : $this->imgDir;
     $this->imgUrl = !empty($options['imgUrl']) ? $options['imgUrl'] : $this->imgUrl;
     $this->font = !empty($options['font']) ? $options['font'] : $this->font;
     $this->fsize = !empty($options['fsize']) ? $options['fsize'] : $this->fsize;
     $this->wordlen = !empty($options['wordlen']) ? $options['wordlen'] : $this->wordlen;
     $this->dotNoiseLevel = !empty($options['dotNoiseLevel']) ? $options['dotNoiseLevel'] : $this->dotNoiseLevel;
     $this->lineNoiseLevel = !empty($options['lineNoiseLevel']) ? $options['lineNoiseLevel'] : $this->lineNoiseLevel;
     $this->expiration = !empty($options['expiration']) ? $options['expiration'] : $this->expiration;
     $this->setImgDir($this->imgDir);
     $this->setImgUrl($this->imgUrl);
     $this->setFont($this->font);
     $this->setFontSize($this->fsize);
     $this->setWordlen($this->wordlen);
     $this->setWidth($this->width);
     $this->setHeight($this->height);
     $this->setDotNoiseLevel($this->dotNoiseLevel);
     $this->setLineNoiseLevel($this->lineNoiseLevel);
     $this->setExpiration($this->expiration);
     // parent::$VN = array("t");
     // parent::$CN = array("r");
     $this->generate();
 }
Example #10
0
 public function init()
 {
     $this->setAttribute('method', 'post');
     $this->setAttribute('action', '/registration/processregistration');
     $this->setAttribute('role', 'form');
     $this->add(['type' => 'Zend\\Form\\Element\\Text', 'name' => 'name', 'options' => ['label' => 'NAME', 'object_manager' => $this->objectManager], 'attributes' => ['required' => true, 'placeholder' => 'ENTER_NAME', 'min' => 3, 'max' => 20, 'size' => 30]]);
     $this->add(['type' => 'Zend\\Form\\Element\\Password', 'name' => 'password', 'options' => ['label' => 'PASSWORD', 'object_manager' => $this->objectManager], 'attributes' => ['required' => true, 'placeholder' => 'PASSWORD', 'min' => 8, 'size' => 30]]);
     $this->add(['type' => 'Zend\\Form\\Element\\Password', 'name' => 'repeatpw', 'options' => ['label' => 'REPEAT_PASSWORD', 'object_manager' => $this->objectManager], 'attributes' => ['required' => true, 'placeholder' => 'REPEAT_PASSWORD', 'size' => 30]]);
     $this->add(['type' => 'Zend\\Form\\Element\\Email', 'name' => 'email', 'options' => ['label' => 'EMAIL', 'object_manager' => $this->objectManager], 'attributes' => ['required' => true, 'min' => 3, 'size' => 30, 'placeholder' => '*****@*****.**']]);
     $captchaImage = new CaptchaImage(['font' => 'public/layouts/default/front/fonts/arial.ttf', 'width' => 180, 'height' => 50, 'size' => 30, 'fsize' => 20, 'dotNoiseLevel' => 10, 'lineNoiseLevel' => 2]);
     $captchaImage->setImgDir('./public/userfiles/captcha');
     $captchaImage->setImgUrl('/userfiles/captcha');
     $this->add(['type' => 'Zend\\Form\\Element\\Captcha', 'name' => 'captcha', 'attributes' => ['class' => 'captcha-input', 'placeholder' => 'ENTER_CAPTCHA', 'size' => 30], 'options' => ['label' => 'CAPTCHA', 'captcha' => $captchaImage]]);
     $this->add(['type' => 'Zend\\Form\\Element\\Csrf', 'name' => 's', 'options' => ['csrf_options' => ['timeout' => 320]]]);
     $this->add(['name' => 'register', 'attributes' => ['type' => 'submit', 'id' => 'submitbutton', 'value' => 'SIGN_UP']]);
 }
 public function __construct()
 {
     parent::__construct();
     $this->setAttribute('method', 'post');
     $this->setAttribute('class', 'panel-body');
     $mail = new Email('email');
     $mail->setLabel('email');
     $mail->setAttribute('class', 'form-control');
     $this->add($mail);
     $captcha = new Captcha('register_captcha');
     $imageAdapter = new Image(['font' => __DIR__ . '/../../fonts/arial.ttf']);
     $imageAdapter->setHeight(100);
     $imageAdapter->setWidth(400);
     $imageAdapter->setFontSize(48);
     $imageAdapter->setDotNoiseLevel(400);
     $imageAdapter->setLineNoiseLevel(40);
     $captcha->setCaptcha($imageAdapter);
     $captcha->setLabel('enter.text.from.the.picture');
     $captcha->setAttribute('class', 'form-control');
     $this->add($captcha);
     $submit = new Submit('send');
     $submit->setValue('send');
     $submit->setAttribute('class', 'btn btn-primary');
     $this->add($submit);
 }
 public function __construct($useOldPassword = true)
 {
     parent::__construct();
     $this->setAttribute('method', 'post');
     $this->setAttribute('class', 'panel-body');
     if ($useOldPassword) {
         $oldPassword = new Password('oldPassword');
         $oldPassword->setLabel('old.password');
         $oldPassword->setAttribute('class', 'form-control');
         $this->add($oldPassword);
     }
     $password = new Password('password');
     $password->setLabel('password');
     $password->setAttribute('class', 'form-control');
     $this->add($password);
     $password2 = new Password('password2');
     $password2->setLabel('repeat.password');
     $password2->setAttribute('class', 'form-control');
     $this->add($password2);
     $captcha = new Captcha('register_captcha');
     $imageAdapter = new Image(['font' => __DIR__ . '/../../fonts/arial.ttf']);
     $imageAdapter->setHeight(100);
     $imageAdapter->setWidth(400);
     $imageAdapter->setFontSize(48);
     $imageAdapter->setDotNoiseLevel(400);
     $imageAdapter->setLineNoiseLevel(40);
     $captcha->setCaptcha($imageAdapter);
     $captcha->setLabel('enter.text.from.the.picture');
     $captcha->setAttribute('class', 'form-control');
     $this->add($captcha);
     $submit = new Submit('save');
     $submit->setValue('save');
     $submit->setAttribute('class', 'btn btn-primary');
     $this->add($submit);
 }
Example #13
0
 public function buildForm()
 {
     $this->setAttributes(array('id' => 'delete-form', 'method' => 'post'));
     $listingsId = new Element\Text('listings_id');
     $listingsId->setLabel('ID do Post');
     $listingsId->setAttributes(array('class' => 'form-control'));
     $deleteCode = new Element\Text('delete_code');
     $deleteCode->setAttribute('class', 'form-control');
     $deleteCode->setLabel('Código de deleção');
     $captcha = new Element\Captcha('captcha');
     $captchaAdapter = new ImageCaptcha(array('font' => './public/fonts/arial.ttf', 'imgDir' => './public/img/captcha', 'imgUrl' => '/img/captcha'));
     $captchaAdapter->setWordlen(4);
     $captcha->setCaptcha($captchaAdapter)->setLabel('Você é um ser humano ou um robô?')->setAttribute('class', 'captchaStyle')->setAttribute('title', 'Você é um ser humano ou um robô?');
     $csrf = new Element\Csrf('security');
     $submit = new Element\Submit('submit');
     $submit->setAttributes(array('class' => 'btn btn-default', 'value' => 'Enviar formulário'));
     $this->add($listingsId)->add($deleteCode)->add($captcha)->add($csrf)->add($submit);
 }
Example #14
0
 public function __construct()
 {
     $laFonts = array('Starjout.ttf', 'Sofia-Regular.ttf');
     $lnFont = mt_rand(0, count($laFonts) - 1);
     $laBg = array('nature.png');
     $lnBg = mt_rand(0, count($laBg) - 1);
     $lsLayoutDir = BASE_DIR . DS . 'layout' . DS . 'theme' . DS . 'captcha';
     $laOptions = array('font' => $lsLayoutDir . DS . 'font' . DS . $laFonts[$lnFont], 'width' => 200, 'height' => 100, 'dotNoiseLevel' => 80, 'lineNoiseLevel' => 5, 'imgDir' => CLIENT_DIR . DS . 'data' . DS . 'temp', 'imgUrl' => '/data/temp', 'startImage' => $lsLayoutDir . DS . 'img' . DS . $laBg[$lnBg]);
     parent::__construct($laOptions);
 }
Example #15
0
 public function novoAction()
 {
     $this->captcha = new Captcha();
     $this->captcha->setFont(getcwd() . "/../www/imobiliaria/fonts/Ubuntu-C.ttf");
     $this->captcha->setImgDir(getcwd() . "/../www/imobiliaria/img");
     $this->captcha->setWordlen(3);
     $this->captcha->setDotNoiseLevel(0);
     //echo "captcha ".  $this->captcha->getSession()->word;
     return new ViewModel(array("captcha" => $this->captcha->generate(), "idCaptcha" => $this->captcha->getWord()));
 }
 /**
  * Categories will be retrieved from the service manager
  * @param array $captchaOptions
  */
 public function buildForm()
 {
     /******************************************************************
      * Isto é um exemplo de como realizar a configurações do formulario,
      * O importante é registrar o campos do formulário pedidos no exercícios
      **********************************************************************/
     // form tag attributes
     $this->setAttribute('method', 'POST');
     // define elements
     $category = new Element\Select('category');
     $category->setLabel('Category')->setValueOptions(array_combine($this->getCategories(), $this->getCategories()));
     $title = new Element\Text('title');
     $title->setLabel('Title')->setAttributes(array('size' => 60, 'maxLength' => 128, 'required' => 'required', 'placeholder' => 'Listing header'));
     $photo = new Element\Text('photo_filename');
     $photo->setLabel('Photo')->setAttribute('maxlength', 1024)->setAttribute('placeholder', 'Enter URL of a JPG');
     $price = new Element\Text('price');
     $price->setLabel('Price')->setAttribute('title', 'Enter price as nnn.nn')->setAttribute('size', 16)->setAttribute('maxlength', 16)->setAttribute('placeholder', 'Enter some value');
     $expires = new Element\Radio('expires');
     $expires->setLabel('Expires')->setAttribute('title', 'The expiration date will be calculated from today')->setAttribute('class', 'expiresButton')->setValueOptions($this->getExpireDays());
     $city = new Element\Text('cityCode');
     $city->setLabel('Nearest City')->setAttribute('title', 'Select the city of the item')->setAttribute('id', 'cityCode')->setAttribute('placeholder', 'Start typing and choose the city');
     $name = new Element\Text('contact_name');
     $name->setLabel('Contact Name')->setAttribute('title', 'Enter the name of the person to contact for this item')->setAttribute('size', 40)->setAttribute('maxlength', 255);
     $phone = new Element\Text('contact_phone');
     $phone->setLabel('Contact Phone Number')->setAttribute('title', 'Enter the phone number of the person to contact for this item')->setAttribute('size', 20)->setAttribute('maxlength', 32);
     $email = new Element\Email('contact_email');
     $email->setLabel('Contact Email')->setAttribute('title', 'Enter the email address of the person to contact for this item')->setAttribute('size', 40)->setAttribute('maxlength', 255);
     $description = new Element\Textarea('description');
     $description->setLabel('Description')->setAttribute('title', 'Enter a suitable description for this posting')->setAttribute('rows', 4)->setAttribute('cols', 80);
     $delCode = new Element\Text('delete_code');
     $delCode->setLabel('Delete Code')->setAttribute('title', 'Enter the delete code for this item')->setAttribute('size', 16)->setAttribute('maxlength', 16);
     $captcha = new Element\Captcha('captcha');
     $captchaAdapter = new ImageCaptcha();
     $captchaAdapter->setWordlen(4)->setOptions($this->captchaOptions);
     $captcha->setCaptcha($captchaAdapter)->setLabel('Help us to prevent SPAM!')->setAttribute('class', 'captchaStyle')->setAttribute('title', 'Help to prevent SPAM');
     $submit = new Element\Submit('submit');
     $submit->setAttribute('value', 'Post');
     $this->add($category)->add($title)->add($photo)->add($price)->add($expires)->add($city)->add($name)->add($phone)->add($email)->add($description)->add($delCode)->add($captcha)->add($submit);
 }
Example #17
0
 public function __construct($urlcaptcha = null)
 {
     parent::__construct('User Register Form');
     $this->setAttribute('method', 'post');
     $this->add(array('name' => 'username', 'type' => 'Zend\\Form\\Element\\Text', 'options' => array('label' => '帳號'), 'attributes' => array('type' => 'text')));
     $this->add(array('name' => 'first_name', 'type' => 'Zend\\Form\\Element\\Text', 'options' => array('label' => '姓')));
     $this->add(array('name' => 'last_name', 'type' => 'Zend\\Form\\Element\\Text', 'options' => array('label' => '名')));
     $this->add(array('type' => 'Zend\\Form\\Element\\Text', 'name' => 'birthday', 'options' => array('label' => '生日', 'description' => '請輸入西元年月日,例: 2000-1-1')));
     $this->add(array('name' => 'sex', 'type' => 'Zend\\Form\\Element\\Select', 'options' => array('label' => '性別', 'value_options' => array('' => '請選擇', 'male' => '男', 'female' => '女'))));
     $this->add(array('type' => 'Zend\\Form\\Element\\Email', 'name' => 'email', 'options' => array('label' => '電子郵件')));
     $this->add(array('name' => 'password', 'options' => array('label' => '密碼'), 'attributes' => array('type' => 'password', 'placeholder' => '請輸入您的密碼')));
     $this->add(array('name' => 're_password', 'options' => array('label' => '確認密碼'), 'attributes' => array('type' => 'password', 'placeholder' => '再輸入一次密碼')));
     $this->add(new Element\Csrf('security'));
     $dirdata = './data';
     $captchaImage = new CaptchaImage(array('font' => $dirdata . '/fonts/arial.ttf', 'width' => 200, 'height' => 80, 'wordlen' => 5, 'dotNoiseLevel' => 40, 'lineNoiseLevel' => 8));
     $captchaImage->setImgDir($dirdata . '/captcha');
     $captchaImage->setImgUrl($urlcaptcha);
     $captcha = new Element\Captcha('captcha');
     $captcha->setCaptcha($captchaImage);
     $captcha->setLabel('請輸入驗證碼');
     $this->add($captcha);
     $this->add(array('name' => 'submit', 'attributes' => array('type' => 'submit', 'value' => '註冊', 'class' => 'btn btn-primary')));
 }
 /**
  * {@inheritdoc}
  */
 public function buildView(FormView $view, FormInterface $form, array $options)
 {
     $sessionKey = sprintf('%s_zend_captcha_session_key_%s', $form->getParent()->getName(), $form->getName());
     $captcha = new Image();
     if (isset($options['suffix'])) {
         $captcha->setSuffix($options['suffix']);
     }
     if (isset($options['height'])) {
         $captcha->setHeight($options['height']);
     }
     if (isset($options['width'])) {
         $captcha->setWidth($options['width']);
     }
     if (isset($options['img_alt'])) {
         $captcha->setImgAlt($options['img_alt']);
     }
     if (isset($options['font_size'])) {
         $captcha->setFontSize($options['font_size']);
     }
     if (isset($options['dot_noise_level'])) {
         $captcha->setDotNoiseLevel($options['dot_noise_level']);
     }
     if (isset($options['line_noise_level'])) {
         $captcha->setLineNoiseLevel($options['line_noise_level']);
     }
     if (isset($options['word_len'])) {
         $captcha->setWordlen($options['word_len']);
     }
     if (isset($options['expiration'])) {
         $captcha->setExpiration($options['expiration']);
     }
     if (isset($options['gc_freq'])) {
         $captcha->setGcFreq($options['gc_freq']);
     }
     $captcha->setImgDir($this->options['img_dir']);
     $captcha->setFont($this->options['font']);
     $captcha->setImgUrl($this->options['img_url']);
     $captcha->getWord();
     $captcha->generate();
     $this->session->set($sessionKey, $captcha->getSession()->getName());
     $view->vars = array_merge($view->vars, array('img_url' => $captcha->getImgUrl() . $captcha->getId() . $captcha->getSuffix(), 'height' => $captcha->getHeight(), 'width' => $captcha->getWidth(), 'img_alt' => $captcha->getImgAlt(), 'img_id' => $captcha->getId(), 'value' => ""));
 }
Example #19
0
 /**
  * Retrieve captcha ID
  *
  * @return string
  */
 public function getId()
 {
     if (null !== $this->id && !preg_match('/^[a-z0-9_\\\\]+$/i', $this->id)) {
         $this->id = null;
     }
     return parent::getId();
 }
Example #20
0
 /**
  * CAPTCHAチェック
  * @param boolean $save セッションに保存するか
  * @param string $message エラーメッセージの内容
  */
 public static function check($save = true, $message = '', $multipart = false)
 {
     global $recaptcha_public_key, $recaptcha_private_key, $vars, $session, $_string, $_button;
     // Captchaのセッション名(ticketとリモートホストの加算値。ticketはプログラマーから見てもわからない)
     $session_name = self::CAPTCHA_SESSION_PREFIX . md5(Utility::getTicket() . REMOTE_ADDR);
     if ($save && $session->offsetExists($session_name) && $session->offsetGet($session_name) === true) {
         // CAPTCHA認証済みの場合
         // return array('msg'=>'CAPTCHA','body'=>'Your host was already to challenged.');
         return;
     }
     if (isset($recaptcha_public_key) && isset($recaptcha_private_key)) {
         // reCaptchaを使う場合
         $captcha = new ReCaptcha($recaptcha_public_key, $recaptcha_private_key);
         // 入力があった場合
         if (isset($vars['recaptcha_challenge_field']) && isset($vars['recaptcha_response_field'])) {
             if ($captcha->verify($vars['recaptcha_challenge_field'], $vars['recaptcha_response_field'])) {
                 if ($save) {
                     // captcha認証済セッションを保存
                     $session->offsetSet($session_name, true);
                     // captcha認証済セッションの有効期間を設定
                     $session->setExpirationSeconds($session_name, self::CAPTCHA_SESSION_EXPIRE);
                 }
                 // return array('msg'=>'CAPTCHA','body'=>'OK!');
                 return;
                 // ここで書き込み処理に戻る
             } else {
                 // CAPTCHA認証失敗ログをつける
                 Utility::dump('captcha');
                 $message = $_string['captcha_failure'];
             }
             // チャレンジ&レスポンスデーターを削除
             unset($vars['recaptcha_challenge_field'], $vars['recaptcha_response_field']);
         }
         // 念のためcaptcha認証済みセッションを削除
         $session->offsetUnset($session_name);
         // reCaptchaの設定をオーバーライド
         // 言語設定
         $captcha->setOption('lang', substr(LANG, 0, 2));
         // テーマ
         $captcha->setOption('theme', self::RECAPTCHA_THEME);
         $form = $captcha->getHTML();
     } else {
         // reCaptchaを使わない場合
         $captcha_dir = CACHE_DIR . self::CAPTCHA_IMAGE_DIR_NAME . DIRECTORY_SEPARATOR;
         self::mkdir_r($captcha_dir);
         if (isset($vars['challenge_field']) && isset($vars['response_field'])) {
             // Captchaチェック処理
             if ($session->offsetGet(self::CAPTCHA_SESSION_PREFIX . $vars['response_field']) === strtolower($vars['challenge_field'])) {
                 if ($save) {
                     // captcha認証済セッションを保存
                     $session->offsetSet($session_name, true);
                     // captcha認証済セッションの有効期間を設定
                     $session->setExpirationSeconds($session_name, self::CAPTCHA_SESSION_EXPIRE);
                 }
                 // 認証用セッションの削除
                 $session->offsetUnset(self::CAPTCHA_SESSION_PREFIX . $vars['response_field']);
                 if (file_exists($captcha_dir . $vars['response_field'] . '.png')) {
                     // キャッシュ画像を削除
                     unlink($captcha_dir . $vars['response_field'] . '.png');
                 }
                 // return array('msg'=>'CAPTCHA','body'=>'OK!');
                 return;
                 // ここで書き込み処理に戻る
             } else {
                 // CAPTCHA認証失敗ログをつける
                 Utility::dump('captcha');
                 $message = $_string['captcha_failure'];
             }
             // チャレンジ&レスポンスデーターを削除
             unset($vars['response_field'], $vars['challenge_field']);
         }
         // 念のためcaptcha認証済みセッションを削除
         $session->offsetUnset($session_name);
         // GDが使える場合、画像認証にする
         if (extension_loaded('gd')) {
             // フォルダが存在しない場合作成を試みる
             if (!file_exists($captcha_dir)) {
                 mkdir($captcha_dir);
                 chmod(0777, $captcha_dir);
             }
             // 古い画像を削除する
             $di = new DirectoryIterator($captcha_dir);
             foreach ($di as $f) {
                 if (!$f->isFile()) {
                     // ファイルでない
                     continue;
                 }
                 if (time() - $f->getMTime() > self::CAPTCHA_TIMEOUT) {
                     // タイムアウト時間よりも古いファイルは削除する
                     unlink($f->getRealPath());
                 }
             }
             /*
             				$handle = opendir($captcha_dir,null);
             				if ($handle) {
             					while( $entry = readdir($handle) ){
             						if( $entry !== '.' && $entry !== '..'){
             							$f = realpath($captcha_dir . $entry);
             							if (time() - filectime($f) > self::CAPTCHA_TIMEOUT) unlink($f);
             						}
             					}
             					closedir($handle);
             				}
             */
             // 画像CAPTCHAを生成
             $captcha = new Image(array('wordLen' => self::CAPTCHA_WORD_LENGTH, 'timeout' => self::CAPTCHA_TIMEOUT, 'font' => LIB_DIR . self::CAPTCHA_IMAGE_FONT, 'ImgDir' => $di->getPath()));
             $captcha->generate();
             // cache_refプラグインを用いて画像を表示
             $form = '<img src="' . Router::get_cmd_uri('cache_ref', null, null, array('src' => self::CAPTCHA_IMAGE_DIR_NAME . '/' . $captcha->getId() . '.png')) . '" height="' . $captcha->getHeight() . '" width="' . $captcha->getWidth() . '" alt="' . Utility::htmlsc($captcha->getImgAlt()) . '" /><br />' . "\n";
             // 画像を取得
         } else {
             // GDがない場合アスキーアート
             $captcha = new Figlet(array('wordLen' => self::CAPTCHA_WORD_LENGTH, 'timeout' => self::CAPTCHA_TIMEOUT));
             $captcha->generate();
             // \が¥に見えるのでフォントを明示的に指定。
             $form = '<pre style="font-family: Monaco, Menlo, Consolas, \'Courier New\' !important;">' . Utility::htmlsc($captcha->getFiglet()->render($captcha->getWord())) . '</pre>' . "\n" . '<br />' . "\n";
             // AAを取得
         }
         // 識別子のセッション名
         $response_session = self::CAPTCHA_SESSION_PREFIX . $captcha->getId();
         // 識別子のセッションを発行
         $session->offsetSet($response_session, $captcha->getWord());
         // captchaの有効期間
         $session->setExpirationSeconds($response_session, self::CAPTCHA_TIMEOUT);
         $form .= '<input type="hidden" name="response_field" value="' . $captcha->getId() . '" />' . "\n";
         $form .= '<div class="input-group">';
         $form .= '<span class="input-group-addon"><span class="fa fa-key"></span></span>';
         $form .= '<input type="text" class="form-control" name="challenge_field" maxlength="' . $captcha->getWordLen() . '" size="' . $captcha->getWordLen() . '" />';
         $form .= '<span class="input-group-btn">';
         $form .= '<button type="submit" class="btn btn-primary" value="submit">' . $_button['submit'] . '</button>';
         $form .= '</span>';
         $form .= '</div>';
         // $form .= $captcha->getWord();
     }
     //	$ret[] = $session->offsetExists($session_name) ? 'true' : 'false';
     //	$ret[] = Zend\Debug\Debug::Dump($vars);
     //	$ret[] = Zend\Debug\Debug::Dump($captcha->getSession());
     if (!empty($message)) {
         $ret[] = '<p class="alert alert-warning"><span class="fa fa-warning"></span>' . $message . '</p>';
     }
     // PostIdが有効な場合
     if (isset($use_spam_check['multiple_post']) && $use_spam_check['multiple_post'] === 1) {
         $vars['postid'] = PostId::generate($vars['cmd']);
     }
     $ret[] = '<fieldset>';
     $ret[] = '<legend>CAPTCHA</legend>';
     $ret[] = '<p>' . $_string['captcha_msg'] . '</p>';
     // フォームを出力
     $ret[] = '<form method="post" action="' . Router::get_script_uri() . '" method="post" class="form-inline">';
     //unset($vars['ajax']);
     // ストアされている値を出力
     foreach ($vars as $key => $value) {
         if ($key === 'ajax') {
             continue;
         }
         if (strpos($key, 'attach_file', 0) === 0) {
             // ファイルフォームだった場合。(あまりいい実装ではない)
             $ret[] = '<input type="file" name="' . $key . '" value="' . (!empty($value) ? Utility::htmlsc($value) : '') . '" class="hidden" />';
             continue;
         }
         $ret[] = '<input type="hidden" name="' . $key . '" value="' . (!empty($value) ? Utility::htmlsc($value) : '') . '" />';
     }
     // CAPTCHAフォームを出力
     $ret[] = $form;
     $ret[] = '</form>';
     $ret[] = '</fieldset>';
     // return array('msg'=>'CAPTCHA','body'=>join("\n",$ret));
     new Render('CAPTCHA', join("\n", $ret));
     exit;
 }
Example #21
0
 public function __construct()
 {
     parent::__construct('login');
     $this->setAttribute('method', 'post');
     $this->setAttribute('class', 'form-horizontal');
     $this->setAttribute('enctype', 'multipart/form-data');
     $this->add(array('name' => 'username', 'attributes' => array('type' => 'text', 'class' => 'form-control', 'placeholder' => 'nombre de usuario'), 'options' => array('label' => 'username', 'label_attributes' => array('class' => 'col-sm-3 control-label'))));
     $this->add(array('name' => 'password', 'attributes' => array('type' => 'password', 'id' => 'password', 'maxlength' => 20, 'class' => 'form-control', 'placeholder' => 'Contraseña'), 'options' => array('label' => 'password', 'label_attributes' => array('class' => 'col-sm-3 control-label'))));
     $captchaImage = new CaptchaImage();
     $captchaImage->setFont("public/resource/fonts/arial.ttf");
     $captchaImage->setImgDir("public/resource/images");
     $captchaImage->setImgUrl("/resource/images");
     $captchaImage->setImgAlt("Captcha");
     $captchaImage->setWidth(250);
     $captchaImage->setHeight(80);
     $captchaImage->setDotNoiseLevel(50);
     $captchaImage->setLineNoiseLevel(5);
     $captchaImage->setFontSize(38);
     $captchaImage->setExpiration(1);
     $captchaImage->setWordlen(6);
     $captchaImage->setMessage("El código no coincide, actualízalo y vuelve a intentarlo", $captchaImage::BAD_CAPTCHA);
     $this->add(array('type' => 'Zend\\Form\\Element\\Captcha', 'attributes' => array('type' => 'password', 'class' => 'form-control', 'placeholder' => 'captcha'), 'name' => 'captcha', 'options' => array('captcha' => $captchaImage, 'id' => 'captcha', 'label' => 'captcha', 'label_attributes' => array('class' => 'col-sm-2 control-label'))));
     $this->add(array('type' => 'Zend\\Form\\Element\\Csrf', 'name' => 'csrf', 'options' => array('csrf_options' => array('timeout' => 600))));
     $this->add(array('name' => 'submit', 'attributes' => array('type' => 'submit', 'value' => 'Ingresar', 'class' => 'btn btn-primary btn-sm btn-sm')));
 }
Example #22
0
 protected function generateImage($id, $word)
 {
     parent::generateImage($id, $word);
     $imgFile = $this->getImgDir() . $id . $this->getSuffix();
     chmod($imgFile, 0666);
 }
Example #23
0
 public function __construct($options = array('width' => '350', 'height' => '100', 'dotNoiseLevel' => '60', 'lineNoiseLevel' => 3, 'expiration' => '360'))
 {
     parent::__construct($options);
 }
 function it_should_get_the_configured_captcha_image_url(Image $captcha)
 {
     $this->options();
     $captcha->getImgUrl()->shouldHaveBeenCalled();
 }
Example #25
0
 public function testImageProvidedNotLoadableWillThrowException()
 {
     $this->setExpectedException('Zend\\Captcha\\Exception\\ImageNotLoadableException');
     $captcha = new Image(array('font' => __DIR__ . '/../Pdf/_fonts/Vera.ttf', 'startImage' => 'file_not_found.png'));
     $captcha->generate();
 }
 /**
  * Add captcha
  *
  * @param string $name
  * @param string $label
  * @param string $category
  * @return void
  */
 protected function addCaptcha($name, $label = null, $category = null)
 {
     // pass captcha image options
     $captchaImage = new CaptchaImage(['font' => CaptchaService::getCaptchaFontPath(), 'width' => SettingService::getSetting('application_captcha_width'), 'height' => SettingService::getSetting('application_captcha_height'), 'dotNoiseLevel' => SettingService::getSetting('application_captcha_dot_noise'), 'lineNoiseLevel' => SettingService::getSetting('application_captcha_line_noise')]);
     $captchaImage->setImgDir(CaptchaService::getCaptchaPath());
     $captchaImage->setImgUrl(CaptchaService::getCaptchaUrl());
     $this->add(['type' => self::FIELD_CAPTCHA, 'name' => $name, 'options' => ['label' => '*' . $this->translator->translate($label ? $label : 'Please verify you are human'), 'captcha' => $captchaImage, 'category' => $category ? $category : null], 'attributes' => ['id' => 'captcha', 'class' => 'form-control', 'required' => 'required']]);
 }
 /**
  * @return array
  */
 public function options()
 {
     return ['image_url' => $this->imageCaptcha->getImgUrl()];
 }
Example #28
0
 public function buildForm()
 {
     $this->setAttributes(array('id' => 'post-form', 'method' => 'post'));
     $category = new Element\Select('category');
     $category->setLabel('Categoria');
     $category->setValueOptions(array_combine($this->categories, $this->categories));
     $category->setAttribute('class', 'form-control');
     $title = new Element\Text('title');
     $title->setLabel('Título');
     $title->setAttributes(array('maxlength' => 128, 'class' => 'form-control'));
     $description = new Element\Textarea('description');
     $description->setAttribute('class', 'form-control');
     $description->setLabel('Descrição');
     $photoFilename = new Element\Url('photo_filename');
     $photoFilename->setAttribute('class', 'form-control');
     $photoFilename->setLabel('Foto');
     $contactName = new Element\Text('contact_name');
     $contactName->setAttribute('class', 'form-control');
     $contactName->setLabel('Nome completo');
     $contactEmail = new Element\Email('contact_email');
     $contactEmail->setAttribute('class', 'form-control');
     $contactEmail->setLabel('E-mail');
     $contactPhone = new Element\Text('contact_phone');
     $contactPhone->setAttribute('class', 'form-control');
     $contactPhone->setLabel('Contato');
     $cityCode = new Element\Select('cityCode');
     $cityCode->setAttribute('class', 'form-control');
     $cityCode->setValueOptions($this->cities);
     $cityCode->setLabel('Cidade');
     $deleteCode = new Element\Number('delete_code');
     $deleteCode->setAttribute('class', 'form-control');
     $deleteCode->setLabel('Código de deleção');
     $captcha = new Element\Captcha('captcha');
     $captchaAdapter = new ImageCaptcha(array('font' => './public/fonts/arial.ttf', 'imgDir' => './public/img/captcha', 'imgUrl' => '/img/captcha'));
     $captchaAdapter->setWordlen(4);
     $captcha->setCaptcha($captchaAdapter)->setLabel('Você é um ser humano ou um robô?')->setAttribute('class', 'captchaStyle')->setAttribute('title', 'Você é um ser humano ou um robô?');
     /*$captcha = new Element\Captcha('captcha');
             $captcha->setCaptcha(new \Zend\Captcha\Dumb());
             $captcha->setAttribute('class', 'form-control');
             $captcha->setOptions(array('label' => 'Você é um ser humano ou um robô?'));
     */
     $price = new Element\Number('price');
     $price->setAttributes(array('class' => 'form-control', 'maxlength' => 12, 'min' => 0, 'max' => '999999999999'));
     $price->setLabel('Preço');
     $dateExpires = new Element\Radio('date_expires');
     $dateExpires->setLabel('Expira em (dias)');
     $dateExpires->setValueOptions(array_combine($this->dateExpires, $this->dateExpires));
     $csrf = new Element\Csrf('security');
     $submit = new Element\Submit('submit');
     $submit->setAttributes(array('class' => 'btn btn-default', 'value' => 'Enviar formulário'));
     $this->add($category)->add($title)->add($price)->add($dateExpires)->add($description)->add($photoFilename)->add($contactName)->add($contactEmail)->add($contactPhone)->add($cityCode)->add($deleteCode)->add($captcha)->add($csrf)->add($submit);
     /*
             $factory = new \Zend\Form\Factory();
             $factory->createForm(array(
                 'hydrator' => 'Zend\Stdlib\Hydrator\ArraySerializable',
                 'elements' => array(
                     array(
                         'name' => 'category',
                         'type' => 'text',
                         'options' => array(
                             'label' => 'Category'
                         )
                     ),
                     array(
                         'name' => 'title',
                         'type' => 'text',
                         'options' => array(
                             'label' => 'Title'
                         )
                     ),
                 )
             )); */
 }