Symfony1 Symfony 1.3和表单:当我单击“保存”时,密码会更改,为什么?
我已经安装了sfDoctrineGuardUser并创建了这个模型 继承sfGuardUser模型:Symfony1 Symfony 1.3和表单:当我单击“保存”时,密码会更改,为什么?,symfony1,Symfony1,我已经安装了sfDoctrineGuardUser并创建了这个模型 继承sfGuardUser模型: Usuario: inheritance: extends: sfGuardUser type: simple columns: nombre_apellidos: string(60) sexo: boolean fecha_nac: date provincia: string(60) localidad: s
Usuario:
inheritance:
extends: sfGuardUser
type: simple
columns:
nombre_apellidos: string(60)
sexo: boolean
fecha_nac: date
provincia: string(60)
localidad: string(255)
email_address: string(255)
avatar: string(255)
avatar_mensajes: string(255)
我还基于该模型创建了一个名为“miembros”的模块
嗯,我通常通过sfGuardAuth/signin登录,然后我去
miembros/edit/id/$id\u成员的\u我使用\u登录并按下“保存”
按钮然后我退出
如果我再次尝试登录,它会显示:用户名和/或密码为
无效
后来,我意识到,当单击“保存”时,“密码”字段的值会很好地更改其加密版本。因此,这就是我无法登录的原因
但是,当我点击“保存”时,为什么密码的值会改变
问候
Javisf\u guard\u用户对象不打算通过继承像这样扩展。提供了一种机制,用于将概要文件对象链接到用户。我见过人们使用类似于你的方法,但我自己没有尝试过,所以不确定这是否是一个常见的问题。但是我会检查您的所有模型和表单类是否正确地相互继承,包括plugin文件夹中的Pluginxxxx类。您是否在password表单字段中显示了旧密码?在这种情况下,它可以显示加密,从而在保存时第二次加密 哈希通常不可识别,因此不应在字段上显示密码 使用sfGuard时,这是一个常见问题。以下是两种解决方案,可能还有其他解决方案可以解决此问题: 不要让用户更改此表单中的用户密码,并为密码重置创建单独的表单 默认情况下,让password表单字段为空,并且仅当用户键入新密码时才保存它 我通常进入第二种方式,这里是使用的表单类:
class ewaSfGuardUserForm extends sfGuardUserForm
{
public function configure()
{
// parent::configure();
//"virtual" new password fields, empty by default
$this->widgetSchema['new_password'] = new sfWidgetFormInputPassword();
$this->widgetSchema['new_password_bis'] = new sfWidgetFormInputPassword();
$error_messages = array('min_length' => 'Passwords must be at least 4 characters long.');
$this->validatorSchema['new_password'] = new sfValidatorString(array('required' => false, 'min_length' => 4), $error_messages);
$this->validatorSchema['new_password_bis'] = new sfValidatorString(array('required' => false, 'min_length' => 4), $error_messages);
$error_messages = array('invalid' => 'New password didn\'t match confirmation');
//validate identical password
$this->validatorSchema->setPostValidator(new sfValidatorSchemaCompare('new_password', '==', 'new_password_bis', array(), $error_messages));
$this->validatorSchema->setPostValidator(
new sfValidatorAnd(array(
new sfValidatorDoctrineUnique(array('model' => 'sfGuardUser', 'column' => array('email_address'))),
new sfValidatorDoctrineUnique(array('model' => 'sfGuardUser', 'column' => array('username')), array('invalid' => 'Email is already in use for another account')),
new sfValidatorSchemaCompare('new_password', '==', 'new_password_bis', array(), $error_messages)
))
);
//unused fields
unset(
$this['groups_list'],
$this['permissions_list'],
$this['password'],
$this['created_at'],
$this['updated_at'],
$this['last_login'],
$this['salt'],
$this['algorithm']
);
//putting back validator for real password field
$this->validatorSchema['password'] = new sfValidatorPass();
}
}
另一部分是动作类sf\u guard\u userActions
protected function processForm(sfWebRequest $request, sfForm $form)
{
$requestParams = $request->getParameter($form->getName());
$requestParams['password'] = $requestParams['new_password'];
$requestParams['email_address'] = $requestParams['username'];
$form->bind($requestParams, $request->getFiles($form->getName()));
if ($form->isValid())
{
[....] Copy of generated code
}
}
我的实现的特殊性在于它总是强制使用email==用户名
我不使用扩展模型来存储用户的配置文件,但我覆盖了defaut-sfGuardUser原则表,添加了额外的字段,如名字、姓氏等。这样工作,原则继承可能会更好。发布代码。我的魔杖坏了。好的,我明天再贴。是模板和使用常规步骤生成的操作:-安装symfony-安装sfDoctrineGuardPlugin-创建一个继承名为Usuario的sfGuardUser的模型-build all reload-php symfony原则:generate module-使用show frontend miembros Usuario谢谢,无论如何为了解决这个问题,我创建了一个基于sfGuardUser的模块,所以没有继承:php symfony原则:生成模块-使用show frontend Guardauario sfGuardUser这些是我的步骤:-安装symfony&sfDoctrineGuardUser-基于sfGuardUser创建一个名为“foo”的模块执行'frontend_dev.php/foo/edit/id/X'并按下'Save'按钮“密码”的值将更改。哈维