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 (1 - 6)
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
destroyerr
post
Post #4





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

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


Co do tej zmiennej to może jestem teraz zaćmiony, ale zasięg zmiennej nie pozwala deklarować w jednej metodzie a korzystać w drugiej.
Jeśli zapiszesz tylko sam formularz to w bazie się zmienia? Masz w niej wtedy zmieniony hash czy ten stary?
Go to the top of the page
+Quote Post
janek9
post
Post #5





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

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


Cytat(destroyerr @ 13.06.2009, 15:28:41 ) *
Co do tej zmiennej to może jestem teraz zaćmiony, ale zasięg zmiennej nie pozwala deklarować w jednej metodzie a korzystać w drugiej.
Jeśli zapiszesz tylko sam formularz to w bazie się zmienia? Masz w niej wtedy zmieniony hash czy ten stary?


Jezeli zapisze tylko sam formularz to nic sie nie dzieje ( poprzez zapisanie obiektu takze nic sie nie dzieje ). Nawet przekierowanie w processForm nie dziala na homepage i zatrzymuje sie na akcji update. W bazie nic sie nie zmienia. Moze jest jakas blokada zapisu do tej tabeli.. Bo jeszcze nie mam ustalonych credentiali i permissions, moze to jest przyczyna tego..;/

Ten post edytował janek9 13.06.2009, 14:37:52
Go to the top of the page
+Quote Post
destroyerr
post
Post #6





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

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


To nie jest przyczyna.
W jakim środowiksu uruchamiasz (choć to w sumie mało istotne)? Czy wyświetlasz błędy z formularza?
Chyba już wiem, do formularza nie dochodzą żadne dane. Format nazw pól formularza ustawiłeś na passwordchange, a w akcji przesyłasz inne dane.
  1. <?php
  2. $form->bind($request->getParameter('passwordchange'));
  3. ?>

Mniej więcej tak, plików nie przesyłasz więc nie potrzebne.
Go to the top of the page
+Quote Post
janek9
post
Post #7





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

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


Cytat(destroyerr @ 13.06.2009, 16:03:35 ) *
To nie jest przyczyna.
W jakim środowiksu uruchamiasz (choć to w sumie mało istotne)? Czy wyświetlasz błędy z formularza?
Chyba już wiem, do formularza nie dochodzą żadne dane. Format nazw pól formularza ustawiłeś na passwordchange, a w akcji przesyłasz inne dane.
  1. <?php
  2. $form->bind($request->getParameter('passwordchange'));
  3. ?>

Mniej więcej tak, plików nie przesyłasz więc nie potrzebne.


Uruchamiam w srodowisku 'dev' . Bledy sa wyswietlane z formularza. Niestety getParameter('passwordchange') rowniez nie dziala...


To jest moj caly partial. Nadal zatrzymuje sie akcja na update. Zachowuje sie tak jakby wogole nie przechodzilo do processForm...


  1. <?php include_stylesheets_for_form($form) ?>
  2. <?php include_javascripts_for_form($form) ?>
  3.  
  4. <form action="<?php echo url_for('password/update') ?>" method="post" <?php $form->isMultipart() and print 'enctype="multipart/form-data" ' ?>>
  5. <?php if (!$form->getObject()->isNew()): ?>
  6. <input type="hidden" name="sf_method" value="put" />
  7. <?php endif; ?>
  8.  <table>
  9.    <tfoot>
  10.      <tr>
  11.        <td colspan="2">
  12.          <?php echo $form->renderHiddenFields() ?>
  13.          &nbsp;<a href="<?php echo url_for('@homepage') ?>">< Powrót</a>
  14.      
  15.          <input type="submit" value="Save" />
  16.        </td>
  17.      </tr>
  18.    </tfoot>
  19.    <tbody>
  20.      <?php echo $form->renderGlobalErrors() ?>
  21.      <tr>
  22.        <th><?php echo $form['password']->renderLabel() ?></th>
  23.        <td>
  24.          <?php echo $form['password']->renderError() ?>
  25.          <?php echo $form['password'] ?>
  26.        </td>
  27.      </tr>
  28.      <tr>
  29.        <th><?php echo $form['password_new_again']->renderLabel() ?></th>
  30.        <td>
  31.          <?php echo $form['password_new_again']->renderError() ?>
  32.          <?php echo $form['password_new_again'] ?>
  33.        </td>
  34.      </tr>
  35.      <tr>
  36.        <th><?php echo $form['password_old']->renderLabel() ?></th>
  37.        <td>
  38.          <?php echo $form['password_old']->renderError() ?>
  39.          <?php echo $form['password_old'] ?>
  40.        </td>
  41.      </tr>
  42.      
  43.    </tbody>
  44.  </table>
  45. </form>




CODE
SQL queries

1. SET NAMES 'utf8'
2. SELECT sf_guard_user.ID, sf_guard_user.USERNAME, sf_guard_user.ALGORITHM, sf_guard_user.SALT, sf_guard_user.PASSWORD, sf_guard_user.CREATED_AT, sf_guard_user.LAST_LOGIN, sf_guard_user.IS_ACTIVE, sf_guard_user.IS_SUPER_ADMIN FROM `sf_guard_user` WHERE sf_guard_user.ID=4
3. SELECT sf_guard_user.ID, sf_guard_user.USERNAME, sf_guard_user.ALGORITHM, sf_guard_user.SALT, sf_guard_user.PASSWORD, sf_guard_user.CREATED_AT, sf_guard_user.LAST_LOGIN, sf_guard_user.IS_ACTIVE, sf_guard_user.IS_SUPER_ADMIN FROM `sf_guard_user` WHERE sf_guard_user.ID='4' LIMIT 1
4. SELECT sf_guard_user.ID, sf_guard_user.USERNAME, sf_guard_user.ALGORITHM, sf_guard_user.SALT, sf_guard_user.PASSWORD, sf_guard_user.CREATED_AT, sf_guard_user.LAST_LOGIN, sf_guard_user.IS_ACTIVE, sf_guard_user.IS_SUPER_ADMIN FROM `sf_guard_user` WHERE sf_guard_user.USERNAME IS NULL LIMIT 1



chyba tutaj jest blad...

Ten post edytował janek9 13.06.2009, 15:58:46
Go to the top of the page
+Quote Post

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

 



RSS Aktualny czas: 19.08.2025 - 07:34