2011-06-25 39 views
2

我使用Doctrine:Symfony的 - 注册系统 - 确认密码,并隐藏输入

User: 
    columns: 
    username:  { type: string(255), unique: true } 
    password:  { type: string(255) } 
    ip:    { type: string(255) } 

这产生了我新的形式:

username: 
password: 
ip: 

我怎样才能使确认密码,并在隐蔽获取IP地址输入?

我:

username: 
password: 
confirm password: 

和MySQL数据库将用户名,密码以及IP($ _ SERVER [ 'REMOTE_ADDR'];) 我怎样才能使它在Symfony的1.4?

THX!

@@@@@@@

补充说:

我做:

$user = $this->form->getObject(); 
    $user->setPassword(sha1($user->getPassword())); 
    $user->setIp($_SERVER['REMOTE_ADDR']); 
    $user = $form->save(); 

setPassword不起作用,但SETIP良好的工作。

回答

2

您可以通过在窗体的configure()方法设置删除字段:

unset($form['ip']) 

而且通过添加确认密码字段:

$this->widgetSchema['password']  = new sfWidgetFormInputPassword(); 
    $this->widgetSchema['password2'] = new sfWidgetFormInputPassword(); 
    // Don't print passwords when complaining about inadequate length 
    $this->setValidator('password', new sfValidatorString(array(
     'required' => true, 
     'trim' => true, 
     'min_length' => 6, 
     'max_length' => 128 
     )); 
    $this->validatorSchema['password2'] = clone $this->validatorSchema['password'];   

    $this->mergePostValidator(new sfValidatorSchemaCompare(
     'password', sfValidatorSchemaCompare::EQUAL, 'password2', 
     array()) 
    )); 

你可以在你的操作添加IP .class.php:

if ($request->isMethod('post')) { 
    $this->form->bind($request->getParameter('yourformprefix')); 
    if ($this->form->isValid()) { 
    $user = $this->form->getObject(); 
    $user->setIp($_SERVER['REMOTE_ADDR']); 
    $user->save(); 
    } 
} 

小记:我强烈建议使用现有的插件(doAuth/sfDoctr ineGuardPlugin)如果你打算做这种工作。

+0

非常非常感谢:)我尽快尝试 –

+0

sfDoctrineGuardPlugin可能不使用数据库,我必须使用mysql –

+0

我试过了。它工作得很好。感谢您的帮助! –