Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [Symfony] setPassword - nie dziala?
janek9
post
Post #1





Grupa: Zarejestrowani
Postów: 121
Pomógł: 2
Dołączył: 22.03.2009

Ostrzeżenie: (0%)
-----


Czesc,

Mam problem z implementacja setPassword w tabeli sfGuardUser. To co mam to nie dziala, nie zapisuje zakodowanych wartosci do tabeli. Czy moze sa jakies potrzebne credentiale zeby taki zapis przeprowadzic? Nie wiem gdzie moze byc blad..Pomozcie

  1. <?php
  2. public function executeEdit(sfWebRequest $request)
  3.  {
  4.    $this->forward404Unless($sf_guard_user = sfGuardUserPeer::retrieveByPk($this->getUser()->getGuardUser()->getId()), sprintf('Object sf_guard_user does not exist (%s).', $this->getUser()->getGuardUser()->getId()));
  5.    $this->form = new sfGuardUserForm($sf_guard_user);
  6.  }
  7.  
  8.  public function executeUpdate(sfWebRequest $request)
  9.  {
  10.    $this->forward404Unless($request->isMethod('post') || $request->isMethod('put'));
  11.    $this->forward404Unless($sf_guard_user = sfGuardUserPeer::retrieveByPk($this->getUser()->getGuardUser()->getId()), sprintf('Object sf_guard_user does not exist (%s).', $this->getUser()->getGuardUser()->getId()));
  12.    $this->form = new sfGuardUserForm($sf_guard_user);
  13.  
  14.    $this->processForm($request, $this->form);
  15.  
  16.    $this->setTemplate('Edit');
  17.  }
  18.  
  19. protected function processForm(sfWebRequest $request, sfForm $form)
  20.  {
  21.    $form->bind($request->getParameter($form->getName()), $request->getFiles($form->getName()));
  22.    if ($form->isValid())
  23.    {
  24.      $sf_guard_user->setPassword($form->getValue('password'));
  25.    $form->save();
  26.      $sf_guard_user->save();
  27.  
  28.      $this->redirect('homepage');
  29.    }
  30.  }
  31. ?>


formularz:

  1. <?php
  2. class sfGuardUserForm extends BasesfGuardUserForm
  3. {
  4.  protected
  5.    $pkName = null;
  6.  
  7.  public function configure()
  8.  {
  9.    
  10.  
  11.    unset(
  12.      $this['last_login'],
  13.      $this['created_at'],
  14.      $this['salt'],
  15.      $this['algorithm'],
  16.      $this['is_active'],
  17.      $this['is_super_admin'],
  18.      $this['sf_guard_user_group_list'],
  19.      $this['sf_guard_user_permission_list']
  20.    );
  21.  
  22.    $this->widgetSchema['password'] = new sfWidgetFormInputPassword();
  23.    $this->widgetSchema['password_new_again'] = new sfWidgetFormInputPassword();
  24.    $this->widgetSchema['password_old'] = new sfWidgetFormInputPassword();
  25.  
  26.    $this->validatorSchema['password'] = new sfValidatorString(array('required' => true, 'min_length' => 6, 'max_length' => 255),array('required' => 'Wypełnij pole.', 'min_length' => 'Minimalna długość hasła to %min_length% znaków', 'max_length' => 'Maksymalna długość hasła to %max_length% znaków'));
  27.    $this->validatorSchema['password_new_again'] = new sfValidatorString(array('required' => true, 'min_length' => 6, 'max_length' => 255),array('required' => 'Wypełnij pole.', 'min_length' => 'Minimalna długość hasła to %min_length% znaków', 'max_length' => 'Maksymalna długość hasła to %max_length% znaków'));
  28.    $this->validatorSchema['password_old'] = new sfValidatorString(array('required' => true, 'min_length' => 6, 'max_length' => 255),array('required' => 'Wypełnij pole.', 'min_length' => 'Minimalna długość hasła to %min_length% znaków', 'max_length' => 'Maksymalna długość hasła to %max_length% znaków'));
  29.    
  30.        $this->mergePostValidator(new sfValidatorSchemaCompare('password', sfValidatorSchemaCompare::EQUAL, 'password_new_again', array(), array('invalid' => 'Podane hasła muszą być takie same!')));
  31.  
  32.    $this->mergePostValidator(new sfValidatorSchemaCompare('password', sfValidatorSchemaCompare::NOT_EQUAL, 'password_old', array(), array('invalid' => 'Wprowadź nowe hasło!')));
  33.  
  34.    
  35.  
  36.    //$this->widgetSchema->moveField('password', 'after', 'email_again');
  37.  
  38.    $this->widgetSchema->setLabels(array(
  39.    'password' => 'Nowe hasło: ',
  40.        'password_new_again' => 'Powtórz nowe hasło: ',
  41.        'password_old' => 'Wpisz stare hasło: '
  42.    ));
  43.  
  44.        
  45.    
  46.      
  47.      $this->widgetSchema->setNameFormat('passwordchange[%s]');
  48.  }
  49. }
  50. ?>
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
destroyerr
post
Post #2





Grupa: Zarejestrowani
Postów: 879
Pomógł: 189
Dołączył: 14.06.2006
Skąd: Bytom

Ostrzeżenie: (0%)
-----


Metoda processForm zawiera zmienną $sf_guard_user. Gdzie i jak ją deklarujesz?
Zapisujesz i formularz i obiekt, wystarczy zapisać jedno z nich.
Go to the top of the page
+Quote Post
janek9
post
Post #3





Grupa: Zarejestrowani
Postów: 121
Pomógł: 2
Dołączył: 22.03.2009

Ostrzeżenie: (0%)
-----


Cytat(destroyerr @ 13.06.2009, 13:55:28 ) *
Metoda processForm zawiera zmienną $sf_guard_user. Gdzie i jak ją deklarujesz?
Zapisujesz i formularz i obiekt, wystarczy zapisać jedno z nich.




  1. <?php
  2. protected function processForm(sfWebRequest $request, sfForm $form)
  3. {
  4.   $form->bind($request->getParameter($form->getName()), $request->getFiles($form->getName()));
  5.   if ($form->isValid())
  6.   {
  7.     $sf_guard_user->setPassword($form->getValue('password'));
  8.     $sf_guard_user->save();
  9.  
  10.     $this->redirect('homepage');
  11.   }
  12. ?>


po kliknieciu linka wywolywana jest metoda edit. Wiec zmienna $sf_guard_user jest wywolywana wraz z funkcja:

  1. <?php
  2. $this->forward404Unless($sf_guard_user = sfGuardUserPeer::retrieveByPk($this->getUser()->getGuardUser()->getId()), sprintf('Object sf_guard_user does not exist (%s).', $this->getUser()->getGuardUser()->getId()));
  3. ?>


Z tego co zagladalem do kodu pluginu sfGuard, metoda setPassword sama automatycznie zapisuje salt przy domyslnym wybranym algorytmie. Akurat ten ktory tam jest mi odpowiada wiec nie bede go zmienial. Ale nie wiem czy dobrze deklaruje/odwoluje sie do tej metody. Probowalem juz przy uzyciu: setUser()->setGuardUser()->setPassword($form->getValue('password')) ale to Tez nie pomoglo..

Czy moze mialbym napisac jakas funkcje w modelu pluginu tabeli sfGuardUser i poprzez odwolanie sie do niej ?

Aha w partialu do formularza mam tak to zapisane:

CODE
form action="<?php echo url_for('password/update') ?>" method="post" <?php $form->isMultipart() and print 'enctype="multipart/form-data" ' ?>>
getObject()->isNew()): ?>



Nie moge dojsc do tego co robie zle...
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 11.10.2025 - 12:39