Ejemplo n.º 1
0
 public function beforeExecuteRoute($dispatcher)
 {
     $action = $dispatcher->getActionName();
     $controller = $dispatcher->getControllerName();
     if (\Models\Users::isAuthorized()) {
         foreach (\Models\Users::getInstance()->getGroups() as $group) {
             if (static::getInstanceAccess()->isAllowed($group->getName(), $controller, $action) == \Phalcon\Acl::ALLOW) {
                 return true;
             }
         }
         $this->forward('errors/Forbidden');
     } else {
         if (static::getInstanceAccess()->isAllowed('guest', $controller, $action) == \Phalcon\Acl::ALLOW) {
             return true;
         }
         $this->redirect('/login/');
     }
     return true;
 }
Ejemplo n.º 2
0
 public function addAction()
 {
     $this->tag->setTitle('Add post');
     $form = new \Forms\Blogs\Posts\Add();
     if ($this->request->isPost()) {
         if ($form->isValid($this->request->getPost())) {
             $post = new \Models\Blogs\Posts();
             $post->setUser(\Models\Users::getInstance());
             if (static::fillModelByFormFromRequest($post, $form, 'blogs')->create()) {
                 static::flash('success', 'Post added!');
                 $form->setEntity($post);
             } else {
                 static::flash('error', $post->getMessages());
             }
         } else {
             static::flash('warning', $form->getMessages());
         }
     }
     $this->view->form = $form;
 }
Ejemplo n.º 3
0
 public function indexAction()
 {
     $this->tag->setTitle('Cabinet');
     $user = \Models\Users::getInstance();
     $form = new \Forms\Cabinet\Edit();
     if ($this->request->isPost()) {
         $form = new \Forms\Cabinet\Edit();
         if ($form->isValid($this->request->getPost())) {
             static::fillModelByFormFromRequest($user, $form, 'users');
             if ($user->save()) {
                 static::flash('success', 'Saved');
             } else {
                 static::flash('error', $user->getMessages());
             }
         } else {
             static::flash('warning', $form->getMessages());
         }
     } else {
         $form->setEntity($user);
     }
     $this->view->form = $form;
 }
Ejemplo n.º 4
0
 public function user()
 {
     return \Models\Users::getInstance();
 }
Ejemplo n.º 5
0
 public function beforeCreate()
 {
     $this->setUser(\Models\Users::getInstance());
 }