Hej! To moje pierwsze podrygi z Symfony (v. 1.4.15), więc proszę o wyrozumiałość


Funkcja jaką robię jest prosta; użytkownik po zalogowaniu (poprzez sfDoctrineGuardPlugin) ma mozliwosc zmiany swojego nazwiska, imienia, emaila lub hasła (dwa pole dla hasła). Pojawia się taki problem, że jeżeli chce zmienić nazwisko, imie lub email - wszystko jest ok, zapisuje się do bazy. Kiedy zmieniam hasło - również zapisuje się do bazy oraz wysyłany jest email z potwierdzeniem. Natomiast kiedy chce zmienic nazwisko, imię lub email ORAZ hasło, na tablicy z danymi uzytkownika nie dzieje sie nic poza updatem pola daty 'updated_at' natomiast hasło się zmienia i email z potwierdzeniem leci. Trochę już skołowany jestem, od czego tak może się dziać, może jakiś pomysł?
Mam dwa formularze zmiany danych użytkownika, jeden jest 'embedded' w drugim:
// formularz z danymi użytkownika
class ChangeDataForm extends sfGuardUserAdminForm {
public function configure() {
if (($object = $this->getObject()->getChangeUserData()) == false) {
$object = new ChangeUserData();
$object->setSfGuardUserId($this->getObject()->getId());
}
$this->setValidators(array( 'id' => new sfValidatorPass(),
'first_name' => new sfValidatorString
(array("required" => true, "min_length" => 2, "trim" => true)), 'last_name' => new sfValidatorString
(array("required" => true, "min_length" => 2, "trim" => true)), 'email_address' => new sfValidatorEmail
(array("required" => true, "min_length" => 2, "trim" => true)) ));
$this->embedForm('change_data', new ChangeUserDataForm
($object, array('sf_guard_user' => $this->getObject()))); $this->widgetSchema['change_data']->setLabel(false);
}
}
// formularz zmiany hasła
class ChangeUserDataForm extends BaseChangeUserDataForm {
public function configure() {
$this->disableLocalCSRFProtection();
$this->widgetSchema['password'] = new sfWidgetFormInputPassword
(array('always_render_empty' => true), array('autocomplete' => 'off')); $this->widgetSchema['password_again'] = new sfWidgetFormInputPassword
(array('always_render_empty' => true), array('autocomplete' => 'off')); $this->setValidators(array( 'password' => new sfValidatorString
(array("required" => false, "min_length" => 8, "trim" => true)), 'password_again' => new sfValidatorString
(array("required" => false, "min_length" => 8, "trim" => true)), ));
$this->widgetSchema->moveField('password_again', 'after', 'password');
$this->mergePostValidator(new sfValidatorSchemaCompare
('password', sfValidatorSchemaCompare
::EQUAL, 'password_again', array(), array('invalid' => 'The two passwords must be the same.'))); }
public function processValues($values) {
$values = parent::processValues($values);
if ($values['password'] != '') {
$values['token_expire'] = date("Y-m-d H:i:s", strtotime('+ 24 hours')); $values['sf_guard_user_id'] = $this->getOption('sf_guard_user')->getId();
}
return $values;
}
public function save($con = null) {
if ($this['password'] != null) {
return parent::save($con);
}
}
}
W widoku zamiast wyświetlać je jak leci, wyciągam tylko interesujące mnie widgety i je wyświetlam:
<?php echo $change_data_form->renderHiddenFields(false); ?>
<?php
$change_data_form['first_name'],
$change_data_form['last_name'],
$change_data_form['email_address'],
$change_data_form['change_data']['password'],
$change_data_form['change_data']['password_again'],
);
?>
<?php foreach ($widgets as $widget): ?>
<div class="sf_admin_form_row sf_admin_text sf_admin_form_field_external_id
<?php echo $widget->hasError() ?
' error' : null; ?>">
<?php echo $widget->renderLabel(); ?> <?php echo $widget->render(); ?> <?php echo $widget->renderError(); ?> </div>
<?php endforeach; ?>
Z kolei akcja kontrolera wygląda w ten sposób:
public function executeEditPrefs(sfWebRequest $request) {
$this->change_data_form = new ChangeDataForm($this->getUser()->getGuardUser());
if ($request->isMethod('post') && $request->hasParameter($this->change_data_form->getName())) {
$this->change_data_form->bind($request->getParameter($this->change_data_form->getName()));
if ($this->change_data_form->isValid()) {
$user = $this->change_data_form->save();
$params = $request->getParameter($this->change_data_form->getName());
if ($params['change_data']['password'] != '') {
$this->getMailer()->sendAdminPasswordChanged(sfConfig::get('app_email_service'), $user->getChangeUserData()->getToken(), $user->getChangeUserData()->getTokenExpire(), $this);
}
}
}
}