przewiń do treści

Zend Framework od podstaw

Włodzimierz Gajda

public function changepasswordAction()
{
    $auth = Zend_Auth::getInstance();
    if (!$auth->hasIdentity()) {
        return $this->_helper->redirector(
            'index',
            'auth',
            'default'
        );
    }

    $User = new Application_Model_DbTable_User();
    $select = $User->select()->where('username = ?', $auth->getIdentity());
    $u = $User->fetchRow($select);

    $this->_helper->viewRenderer('changepasswordform');
    $form = new Application_Form_Changepassword();

    if ($u && $form->isValid($this->getRequest()->getPost())) {
        $password = $form->getValue('password');
        $salt = My_Salt::getSalt();

        $u->salt     = $salt;
        $u->password = md5($password . $salt);
        $u->save();

        $mail = new My_Mail_Gmail();
        $mail->mailNewPassword($u->email, $password);

        return $this->_helper->redirector(
            'index',
            'index',
            'default'
        );

    }
    $this->view->form = $form;
}

Listing 37.14. Metoda akcji auth/changepassword

Rozdział 37. Rejestracja użytkowników

listing-37-14.txt