/** * Authenticates the user * * @param void * @return mixed {Zend\Http\PhpEnvironment\Response, ViewModel} **/ public function loginAction() { $params = array('controller' => 'blog', 'action' => 'view-all'); if ($this->_userService->getAuthService()->hasIdentity()) { return $this->redirect()->toRoute('blog/default', $params); } $request = $this->getRequest(); if ($request->isPost()) { if ($this->_userService->auth($request->getPost())) { return $this->redirect()->toRoute('blog/default', $params); } } return new ViewModel(array('form' => $this->_userService->getForm(), 'messages' => $this->_userService->getMessages(UserService::MSG_NOTICE), 'errors' => $this->_userService->getMessages(UserService::MSG_ERROR))); }
/** * Creates a blog post * * @parmam void * @return mixed {Zend\Http\PhpEnvironment\Response, ViewModel} * @throws AccessProhibitedException **/ public function createAction() { $this->_checkAcl('create'); $userService = new UserService($this->_em); $auth = $userService->getAuthService(); $user = $userService->findById($auth->getIdentity()->getId()); $post = new Post(); $post->setDateAdded(new DateTime()); $post->setUser($user); $form = new PostForm(); $form->bind($post); $categoryService = new CategoryService($this->_em); $form->setCategoryList($categoryService->getAll()); $service = new PostService($this->_em); $service->setForm($form); $request = $this->getRequest(); if ($request->isPost()) { if ($service->save($request->getPost())) { $params = array('controller' => 'admin', 'action' => 'index'); return $this->redirect()->toRoute('blog/default', $params); } } return new ViewModel(array('form' => $form, 'messages' => $this->_postService->getMessages(PostService::MSG_NOTICE), 'errors' => $this->_postService->getMessages(PostService::MSG_ERROR))); }