Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /***************************** Module.config.php *****************************/
- <?php
- namespace Application;
- return array(
- 'router' => array(
- 'routes' => array(
- 'home' => array(
- 'type' => 'segment',
- 'options' => array(
- 'route' => '[/:lang]/',
- 'constraints' => array(
- 'lang' => '[a-zA-Z][a-zA-Z0-9_-]*'
- ),
- 'defaults' => array(
- 'controller' => 'Application\Controller\Index',
- 'action' => 'index',
- 'lang' => 'en_US'
- ),
- ),
- 'may_terminate' => true,
- 'child_routes' => array(
- 'registerCaptcha' => array(
- 'type' => 'segment',
- 'options' => array(
- 'route' => '/[:action[/]]',
- 'constraints' => array(
- 'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
- ),
- 'defaults' => array(
- 'action' => 'register',
- ),
- ),
- ),
- 'captcha' => array(
- 'type' => 'segment',
- 'options' => array(
- 'route' => '/captcha/[:id]',
- 'constraints' => array(
- 'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
- ),
- 'defaults' => array(
- 'controller' => 'Application\Controller\Index',
- 'action' => 'generate',
- )
- )
- )
- )
- ),
- 'login' => array(
- 'type' => 'segment',
- 'options' => array(
- 'route' => '[/:lang]/login[/][:action][/:id]',
- 'constraints' => array(
- 'lang' => '[a-zA-Z][a-zA-Z0-9_-]*'),
- 'defaults' => array(
- 'controller' => 'Application\Controller\Login',
- 'action' => 'index',
- ),
- ),
- ),
- [...]
- /***************************** ACTIONS *****************************/
- Action Forget My Password (In LoginController)
- <?php
- public function forgetMyPasswordAction()
- {
- // todo @gustavo: criar função de esqueci senha
- $entityManager = $this->getEntityManager();
- $urlCaptcha = $this->getRequest()->getBaseUrl().'/home/captcha';
- // passing entityManager and urlCaptcha objects
- $form = new UsuariosForm($entityManager, $urlCaptcha);
- // some stuff
- if ($this->request->isPost())
- {
- // stuff
- }
- return array('form' => $form, 'lang' => $this->translator->getLocale());
- }
- ?>
- Action in IndexController:
- <?php
- /**
- * Generate Captcha
- */
- public function generateAction()
- {
- $response = $this->getResponse();
- $response->getHeaders()->addHeaderLine('Content-Type', "image/png");
- $id = $this->params('id', false);
- if ($id) {
- $image = './data/captcha/' . $id;
- if (file_exists($image) !== false) {
- $imagegetcontent = @file_get_contents($image);
- $response->setStatusCode(200);
- $response->setContent($imagegetcontent);
- if (file_exists($image) == true) {
- unlink($image);
- }
- }
- }
- return $response;
- }
- ?>
- /***************************** VIEW *****************************/
- <?php
- namespace Application;
- $title = "Forget My Password";
- $this->headTitle($title);
- ?>
- <p>
- <a href="<?php echo $this->url("login", array('action'=>'forgetMyPassword', 'lang' => $locale))?>"><?php echo $this->escapeHtml($this->translate("Sign Up")) ?></a>
- </p>
- <?php
- $form->setAttribute('action' , $this->url('login', array('action' =>'forgetMyPassword', 'lang' => $locale)));
- $form->prepare();
- echo $this->form()->openTag($form);
- echo $this->formRow($form->get('email'));
- echo $this->formRow($form->get('captcha'));
- echo $this->formSubmit($form->get('submit'));
- echo $this->form()->closeTag();
- /***************************** FORM *****************************/
- <?php
- namespace Application\Form\Usuarios;
- use Doctrine\Common\Persistence\ObjectManager;
- use DoctrineModule\Stdlib\Hydrator\DoctrineObject as DoctrineHydrator;
- use Zend\Captcha\Image as CaptchaImage;
- use Zend\Form\Form;
- use Zend\Form\Element;
- use Zend\Form\Element\Captcha;
- use Zend\InputFilter\InputFilter;
- class UsuariosForm extends Form
- {
- /**
- * undocumented function
- *
- * @return void
- * @author
- **/
- public function __construct(ObjectManager $objectManager, $urlCaptcha = null)
- {
- parent::__construct('Usuarios');
- $this->setAttribute('enctype', 'multipart/form-data');
- $this->setAttribute('method', 'post');
- $this->setHydrator(new DoctrineHydrator($objectManager, 'Application\Entity\Usuarios'));
- $dirdata = './data';
- //pass captcha image options
- $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' => 'hidden',
- 'name' => 'idUsuarios'
- )
- //add captcha element...
- ->add(array(
- 'type' => 'Zend\Form\Element\Captcha',
- 'name' => 'captcha',
- 'options' => array(
- 'label' => 'Please verify you are human',
- 'captcha' => $captchaImage,
- ),
- )
- //add captcha element...
- // @gustavo: Dummy Captcha (letters backwards and stuff)
- // ->add(array(
- // 'type' => 'Zend\Form\Element\Captcha',
- // 'name' => 'captcha',
- // 'options' => array(
- // 'label' => 'Please verify you are human',
- // 'captcha' => array(
- // 'class' => 'Dumb'
- // ),
- // ),
- // )
- )->add(array(
- 'name' => 'submit',
- 'attributes' => array(
- 'type' => 'submit',
- 'value' => 'Go',
- 'id' => 'submitbutton'
- )
- ));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement