示例#1
0
 /**
  * Checks if the current user has the priviledge to do something.
  *
  * @param string $priviledge
  * @return AccessProhibitedException
  **/
 protected function _checkAcl($priviledge)
 {
     $service = new UserService($this->_em);
     if (!$this->_acl->isAllowed($service->getCurrentRole(), $this, $priviledge)) {
         throw new AccessProhibitedException('Access is prohibited.');
     }
 }
 /**
  * Returns DisplayComments instance.
  *
  * @param ServiceLocatorInterface $serviceLocator
  * @return DisplayQuote
  * @override
  **/
 public function createService(ServiceLocatorInterface $serviceLocator)
 {
     /* @var $serviceLocator Zend\View\HelperPluginManager */
     $sm = $serviceLocator->getServiceLocator();
     $em = $sm->get('em');
     $service = new UserService($em);
     $role = $service->getCurrentRole();
     $helper = new DisplayComments();
     $helper->setRole($role);
     return $helper;
 }
示例#3
0
 /**
  * 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)));
 }
示例#4
0
 /**
  * De-Authenticates the user
  *
  * @param void
  * @return Zend\Http\PhpEnvironment\Response
  **/
 public function logoutAction()
 {
     $this->_userService->logout();
     return $this->redirect()->toRoute('blog/default');
 }