Zend Framework 2. ZfcUser。当我在登录表单中添加新元素时,使用正确的电子邮件/传递身份验证错

时间:2014-12-18 21:38:04

标签: php authentication zend-framework login zfcuser

当我在ZfcUser中以登录表单添加新元素时,我收到了注册用户的正确电子邮件/通行证的身份验证错误。

我使用以下行在bootstrap函数中添加了新元素:

<?php

namespace SystemUser;

use Zend\Mvc\ModuleRouteListener;
use Zend\Mvc\MvcEvent;

public function onBootstrap($e)
{
    $events = $e->getApplication()->getEventManager()->getSharedManager();
    $sharedEvents->attach('ZfcUser\Form\Login',
        'init',
        function($e)
        {
            // @var $form \ZfcUser\Form\Login
            $form = $e->getTarget();

            // Configure email input
            $form->get('identity')
                ->setAttribute('placeholder', 'Your email')
                ->setAttribute('class', 'text-input')
                ->setAttribute('title', 'Your email');

            // Configure password input
            $form->get('credential')
                ->setAttribute('placeholder', 'Your password')
                ->setAttribute('class', 'text-input')
                ->setAttribute('title', 'Your password');

            // Configure submit button
            $form->get('submit')
                ->setAttribute('class', 'btn btn-primary submit');

            // Add field "Keep me signed in."
            $form->add(
                array(
                    'type' => 'Zend\Form\Element\Checkbox',
                    'name' => 'keep_signed_in',
                    'options' => array(
                        'label' => 'Keep me signed in.',
                        'use_hidden_Element' => true,
                        'checked_value' => '1',
                        'unchecked_value' => '0'
                    ),
                    'attributes' => array(
                        'id' => 'keep_signed_in',
                    ),
                )
            );

        }
    );

}

但是使用新元素'keep_signed_in'登录表单总是返回错误“身份验证失败。请再试一次。”

请帮忙。用真正的auth params删除这个错误我必须做些什么?

谢谢你们,伙计们!

2 个答案:

答案 0 :(得分:1)

听起来你正在尝试做另外一个模块已经在做的事情:https://github.com/goalio/GoalioRememberMe(我知道这不是你问题的答案,但现在你可能不需要答案:))

答案 1 :(得分:0)

我找到解决方案! :)

我忘记为此复选框指定过滤器,其中包含required = false:

$sharedEvents->attach('ZfcUser\Form\LoginFilter', 'init', function($e) {
        // @var $form \ZfcUser\Form\LoginFilter
        $filter = $e->getTarget();

        // Custom field keep_signed_in
        $filter->add(array(
                'name'       => 'keep_signed_in',
                'required'   => false,
            )
        );

    }
);