【问题标题】:Strange behavior of the form change of the password in ieie中密码形式更改的奇怪行为
【发布时间】:2013-03-15 22:17:54
【问题描述】:

我使用 sfDoctrineGuardPlugin。密码修改的形式有三个字段:

当前密码、新密码、重复新密码。

如果当前是正确的,并且新的和重复的一样,我会这样做

$this->getUser()->getGuardUser()->setPassword($this->form->getValue('password'));
$this->getUser()->getGuardUser()->save();

在所有浏览器中,除了 ie 一切正常,但在 ie 时,save() 是 - 或重新验证形式,或重定向到相同的路由。

结果,用旧数据重新检查当前密码(然后有新密码),抛出表单错误。 告诉我该怎么做,我不明白浏览器如何影响服务器操作。

public function executeChangePassword(sfWebRequest $request) {
        $this->forward404Unless($this->getUser()->isAuthenticated());
        $this->form = new ChangePasswordForm();
        $this->bSuccess = false;

        if ($request->isMethod('post')) {
            $this->form->bind($request->getParameter($this->form->getName()));
            if ($this->form->isValid()) {
                $this->oUser = $this->getUser();
                $this->oUser->setPassword($this->form->getValue('password'));
                $this->bSuccess = true;
            }
        }
}
class ChangePasswordForm extends BaseForm {
    public function configure() {
        $this->setWidgets(array(
            'current_password' => new sfWidgetFormInputPassword(array(), array('class' => 'b-input-text')),
            'password' => new sfWidgetFormInputPassword(array(), array('class' => 'b-input-text')),
            'password_again' => new sfWidgetFormInputPassword(array(), array('class' => 'b-input-text')),
        ));

        $this->validatorSchema['current_password'] = new slValidatorUserPassword(
            array('required' => true,
                'min_length' => 6,
                'max_length' => 128
            )
        );
        $this->validatorSchema['password'] = new sfValidatorString(
            array(
                'required' => true,
                'min_length' => 6,
                'max_length' => 128
            )
        );
        $this->validatorSchema['password_again'] = new sfValidatorString(
            array('required' => true,
                'min_length'    => 6,
                'max_length'    => 128
            )
        );
        $this-> mergePostValidator(new sfValidatorSchemaCompare('password', '==', 'password_again', array(), array()));
        $this->widgetSchema->setNameFormat('change_password[%s]');
    }
}

【问题讨论】:

  • 您使用的是内置的忘记密码系统还是自定义系统?我们可以看到生成的 html 表单和您处理表单的操作吗?
  • 加起来的动作。是的,自定义操作。 ChangePasswordForm 扩展了 BaseForm。
  • 你也可以加ChangePasswordForm类吗?
  • 更新 ChangePasswordForm
  • 对我来说一切都很好,那么显示表单的模板呢?

标签: symfony1 symfony-1.4 sfguard


【解决方案1】:

您可以只使用提供的 sfGuardChangeUserPasswordForm 类。它包含在插件中。

这是一个有效的控制器示例:

public function executeIndex(sfWebRequest $request)
{
    $sf_user = $this->getUser();
    $sf_guard_user = $sf_user->getGuardUser();
    $this->form = new sfGuardChangeUserPasswordForm($sf_guard_user);

    if ("changepassword" == $request->getParameter('do'))
    { /* dont forget to put action="/route/to/this/controler/?do=changepassword" on the view's <form> */ 
        $this->processForm($request, $this->form);
    }
}

protected function processForm(sfWebRequest $request, sfForm $form)
{
    $form->bind($request->getParameter($form->getName()), $request->getFiles($form->getName()));
    if ($form->isValid())
    {
        $notice = 'Password updated successfully.';

        try {
            $sf_guard_user = $form->save();
        } catch (Doctrine_Validator_Exception $e) {

            $errorStack = $form->getObject()->getErrorStack();

            $message = get_class($form->getObject()) . ' has ' . count($errorStack) . " field" . (count($errorStack) > 1 ? 's' : null) . " with validation errors: ";
            foreach ($errorStack as $field => $errors)
            {
                $message .= "$field (" . implode(", ", $errors) . "), ";
            }
            $message = trim($message, ', ');

            $this->getUser()->setFlash('error', $message);
            return sfView::SUCCESS;
        }

        $this->dispatcher->notify(new sfEvent($this, 'admin.save_object', array('object' => $sf_guard_user)));

        $this->getUser()->setFlash('notice', $notice);

        $this->redirect(array('sf_route' => 'sf_guard_user_profile'));
    }
    else
    {
        $this->getUser()->setFlash('error', 'Password was not changed due to some errors.', false);
    }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多