public function forgottenPasswordAction()
 {
     $form = new ForgottenPasswordForm();
     $form->get('submit')->setValue('Send');
     $request = $this->getRequest();
     if ($request->isPost()) {
         $form->setInputFilter(new ForgottenPasswordFilter($this->getServiceLocator()));
         $form->setData($request->getPost());
         if ($form->isValid()) {
             $data = $form->getData();
             $usrEmail = $data['usrEmail'];
             $entityManager = $this->getServiceLocator()->get('doctrine.entitymanager.orm_default');
             $user = $entityManager->getRepository('Auth\\Entity\\User')->findOneBy(array('usrEmail' => $usrEmail));
             $username = $user->getUsrName();
             $password = $this->generatePassword();
             $bcrypt = new Bcrypt();
             $user->setUsrPassword($bcrypt->create($password));
             $entityManager->persist($user);
             $entityManager->flush();
             $mail = new MailController();
             $mail->initMail('forgotPassword', $usrEmail, $username, $password);
             return $this->redirect()->toRoute('auth/default', array('controller' => 'registration', 'action' => 'password-change-success'));
         }
     }
     return new ViewModel(array('form' => $form));
 }
 public function forgottenPasswordAction()
 {
     $form = new ForgottenPasswordForm();
     //$form->get('submit')->setValue('Send');
     $request = $this->getRequest();
     if ($request->isPost()) {
         $form->setInputFilter(new ForgottenPasswordFilter($this->getServiceLocator()));
         $form->setData($request->getPost());
         if ($form->isValid()) {
             $data = $form->getData();
             $usr_email = $data['usr_email'];
             $usersTable = $this->getUsersTable();
             $auth = $usersTable->getUserByEmail($usr_email);
             $password = $this->generatePassword(8, 2, 2, 2);
             $auth->usr_password = $this->encriptPassword($this->getStaticSalt(), $password, $auth->usr_password_salt);
             //		$usersTable->changePassword($auth->usr_id, $password); - tableDataGateway or
             $usersTable->saveUser($auth);
             // DataMapper
             $this->sendPasswordByEmail($usr_email, $password);
             $this->flashMessenger()->addMessage($usr_email);
             return $this->redirect()->toRoute('auth/default', array('controller' => 'registration', 'action' => 'password-change-success'));
         }
     }
     return new ViewModel(array('form' => $form));
 }