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 addAction() { $entityManager = $this->getEntityManager(); $user = new User(); //1) A lot of work to manualy change the form add fields etc. Better use a form class //- $form = $this->getRegistrationForm($entityManager, $user); // 2) Better use a form class $form = new UserForm(); $form->get('submit')->setValue('Register'); $form->setHydrator(new DoctrineHydrator($entityManager, 'Aut\\Entity\\User')); $form->bind($user); $request = $this->getRequest(); if ($request->isPost()) { $form->setInputFilter(new UserFilter()); $form->setData($request->getPost()); if ($form->isValid()) { $this->prepareData($user); $entityManager->persist($user); $entityManager->flush(); $mail = new MailController(); $mail->initMail('accountCreated', $user->getUsrEmail(), $user->getUsrEmail()); return $this->redirect()->toRoute('cms/default', array('controller' => 'user', 'action' => 'index')); } } return new ViewModel(array('form' => $form)); // // $form->setData($request->getPost()); // if ($form->isValid()) { // //$this->prepareData($user); // // if ($form->isValid()) { // $data = $form->getData(); // unset($data['submit']); // if (empty($data['user_registration_date'])) $data['user_registration_date'] = '2013-07-19 12:00:00'; // $this->getUsersTable()->insert($data); // return $this->redirect()->toRoute('cms/default', array('controller' => 'user', 'action' => 'index')); // } // } // return new ViewModel(array('form' => $form)); }
public function addAction() { $id = (int) $this->params()->fromRoute('id', 0); if (!$id) { return $this->redirect()->toRoute('cms/default', array('controller' => 'index', 'action' => 'index')); } $entityManager = $this->getServiceLocator()->get('doctrine.entitymanager.orm_default'); $comment = new Comment(); try { $repository = $entityManager->getRepository('Cms\\Entity\\Article'); $article = $repository->findOneBy(array('artcId' => $id)); $comment->setArticle($article); } catch (\Exception $ex) { return $this->redirect()->toRoute('cms/default', array('controller' => 'index', 'action' => 'index')); } $form = new CommentForm(); $form->remove('comCreated'); $form->remove('author'); $form->remove('article'); $auth = $this->getServiceLocator()->get('Zend\\Authentication\\AuthenticationService'); if ($auth->hasIdentity()) { $form->remove('com_email'); $form->remove('com_username'); } foreach ($form->getElements() as $element) { if (method_exists($element, 'getProxy')) { $proxy = $element->getProxy(); if (method_exists($proxy, 'setObjectManager')) { $proxy->setObjectManager($entityManager); } } } $form->setHydrator(new DoctrineHydrator($entityManager, 'Cms\\Entity\\Comment')); $form->bind($comment); $request = $this->getRequest(); if ($request->isPost()) { $form->setData($request->getPost()); if ($form->isValid()) { $data = $form->getData(); $this->prepareData($comment); if (!$auth->hasIdentity()) { $comment->setComUsername($data->getComUsername()); $comment->setComEmail($data->getComEmail()); } $entityManager->persist($comment); $entityManager->flush(); $entityManager = $this->getServiceLocator()->get('doctrine.entitymanager.orm_default'); $admin_id = 3; $sql = "SELECT u.usrEmail, u.usrName FROM Auth\\Entity\\User u WHERE u.usrlId= " . $admin_id; $query = $entityManager->createQuery($sql); $admins = $query->getResult(); $mail = new MailController(); foreach ($admins as $admin) { $mail->initMail('commentCreated', $admin['usrEmail'], $admin['usrName'], $article->getArtcTitle()); } return $this->redirect()->toRoute('cms/default', array('controller' => 'comment', 'action' => 'index', 'id' => $id), true); } } return array('id' => $id, 'form' => $form); }