/**
  * @Request({"permissions": "array"}, csrf=true)
  * @Response("json")
  */
 public function saveAction($permissions = [])
 {
     foreach ($this->roles->findAll() as $role) {
         $role->setPermissions(isset($permissions[$role->getId()]) ? $permissions[$role->getId()] : []);
         $this->roles->save($role);
     }
     return $this['request']->isXmlHttpRequest() ? ['message' => __('Permissions saved!')] : $this->redirect('@system/permission');
 }
Exemplo n.º 2
0
 /**
  * @Request({"order": "array"}, csrf=true)
  * @Response("json")
  */
 public function priorityAction($order)
 {
     foreach ($order as $id => $priority) {
         $role = $this->roles->find($id);
         if ($role) {
             $this->roles->save($role, compact('priority'));
         }
     }
     return $order;
 }
Exemplo n.º 3
0
 /**
  * Constructor.
  *
  * @param  EntityManager $manager
  * @param  Metadata      $metadata
  * @param  array         $mapping
  */
 public function __construct(EntityManager $manager, Metadata $metadata, array $mapping)
 {
     $this->manager = $manager;
     $this->metadata = $metadata;
     if (!($this->name = $mapping['name'])) {
         throw new \InvalidArgumentException('The parameter "name" may not be omitted in relations.');
     }
     $this->targetEntity = $mapping['targetEntity'];
     $this->targetRepository = $manager->getRepository($this->targetEntity);
     $this->targetMetadata = $this->targetRepository->getMetadata();
 }
Exemplo n.º 4
0
 /**
  * @Request({"id": "int"}, csrf=true)
  */
 public function deleteAction($id)
 {
     try {
         if (!($menu = $this->menus->find($id))) {
             throw new Exception(__('Invalid menu id'));
         }
         $this->menus->delete($menu);
         $this['db']->delete('@system_menu_item', ['menu_id' => $id]);
     } catch (Exception $e) {
         $this['message']->error($e->getMessage());
     }
     return $this->redirect('@system/menu');
 }
Exemplo n.º 5
0
 /**
  * @Route("/{id}", name="@page/id", requirements={"id"="\d+"})
  * @Response("extension://page/views/index.razr")
  */
 public function indexAction($id = 0)
 {
     if (!($page = $this->pages->where(compact('id'))->where(['status' => Page::STATUS_PUBLISHED])->first())) {
         throw new NotFoundHttpException(__('Page not found!'));
     }
     if (!$page->hasAccess($this['user'])) {
         if (!$this['user']->isAuthenticated()) {
             return $this->redirect('@system/auth/login', ['redirect' => $this['url']->current()]);
         }
         throw new AccessDeniedHttpException(__('Unable to access this page!'));
     }
     $page->setContent($this['content']->applyPlugins($page->getContent(), ['page' => $page, 'markdown' => $page->get('markdown')]));
     return ['head.title' => __($page->getTitle()), 'page' => $page];
 }
Exemplo n.º 6
0
 /**
  * @Request({"ids": "int[]"}, csrf=true)
  */
 public function deleteAction($ids = [])
 {
     foreach ($ids as $id) {
         if ($alias = $this->aliases->find($id)) {
             $this->aliases->delete($alias);
         }
     }
     $this['message']->success(_c('{0} No alias deleted.|{1} Alias deleted.|]1,Inf[ Aliases deleted.', count($ids)));
     return $this->redirect('@system/alias');
 }
Exemplo n.º 7
0
 /**
  * @Request({"position", "order": "array"}, csrf=true)
  * @Response("json")
  */
 public function reorderAction($position, $order = [])
 {
     $widgets = $this->widgets->findAll();
     foreach ($order as $priority => $data) {
         $id = $data['id'];
         if (isset($widgets[$id])) {
             $this->widgets->save($widgets[$id], compact('position', 'priority'));
         }
     }
     return ['message' => __('Widgets updated.')];
 }
Exemplo n.º 8
0
 /**
  * @Route("/feed")
  * @Route("/feed/{type}")
  */
 public function feedAction($type = '')
 {
     $feed = $this['feed']->create($type ?: $this->extension->getParams('feed.type'), ['title' => $this['option']->get('system:app.site_title'), 'link' => $this['url']->route('@blog/site', [], true), 'description' => $this['option']->get('system:app.site_description'), 'element' => ['language', $this['option']->get('system:app.locale')], 'selfLink' => $this['url']->route('@blog/site/feed', [], true)]);
     if ($last = $this->posts->query()->where(['status = ?', 'date < ?'], [Post::STATUS_PUBLISHED, new \DateTime()])->limit(1)->orderBy('modified', 'DESC')->first()) {
         $feed->setDate($last->getModified());
     }
     foreach ($this->posts->query()->where(['status = ?', 'date < ?'], [Post::STATUS_PUBLISHED, new \DateTime()])->related('user')->limit($this->extension->getParams('feed.limit'))->orderBy('date', 'DESC')->get() as $post) {
         $feed->addItem($feed->createItem(['title' => $post->getTitle(), 'link' => $this['url']->route('@blog/id', ['id' => $post->getId()], true), 'description' => $this['content']->applyPlugins($post->getContent(), ['post' => $post, 'markdown' => $post->get('markdown'), 'readmore' => true]), 'date' => $post->getDate(), 'author' => [$post->getUser()->getName(), $post->getUser()->getEmail()], 'id' => $this['url']->route('@blog/id', ['id' => $post->getId()], true)]));
     }
     return $this['response']->create($feed->generate(), Response::HTTP_OK, ['Content-Type' => $feed->getMIMEType()]);
 }
Exemplo n.º 9
0
 /**
  * @Request({"status": "int", "ids": "int[]"}, csrf=true)
  * @Response("json")
  */
 public function statusAction($status, $ids = [])
 {
     foreach ($ids as $id) {
         if ($comment = $this->comments->find($id) and $comment->getStatus() != $status) {
             $previous = $comment->getStatus();
             $comment->setStatus($status);
             $this->comments->save($comment);
             $this['events']->dispatch('system.comment.spam_mark', new MarkSpamEvent($comment, $previous));
         }
     }
     return ['message' => _c('{0} No comment status updated.|{1} Comment status updated.|]1,Inf[ Comment statuses updated.', count($ids))];
 }
Exemplo n.º 10
0
 /**
  * Gets the user roles.
  *
  * @param  User $user
  * @return array
  */
 protected function getRoles(User $user = null)
 {
     $roles = $this->roles->where(['id <> ?'], [Role::ROLE_ANONYMOUS])->orderBy('priority')->get();
     foreach ($roles as $role) {
         if ($role->isAuthenticated()) {
             $role->disabled = true;
         }
         if ($user && $user->getId() == $this['user']->getId() && $user->isAdministrator() && $role->isAdministrator()) {
             $role->disabled = true;
         }
     }
     return $roles;
 }
Exemplo n.º 11
0
 /**
  * @Request({"status": "int", "ids": "int[]"}, csrf=true)
  * @Response("json")
  */
 public function statusAction($status, $ids = [])
 {
     foreach ($ids as $id) {
         if ($page = $this->pages->find($id) and $page->getStatus() != $status) {
             $page->setStatus($status);
             $this->pages->save($page);
         }
     }
     if ($status == Page::STATUS_PUBLISHED) {
         $message = _c('{0} No page published.|{1} Page published.|]1,Inf[ Pages published.', count($ids));
     } else {
         $message = _c('{0} No page unpublished.|{1} Page unpublished.|]1,Inf[ Pages unpublished.', count($ids));
     }
     return compact('message');
 }
Exemplo n.º 12
0
 /**
  * @Request({"status": "int", "menu": "int", "id": "int[]"}, csrf=true)
  */
 public function statusAction($status, $menuId, $ids = [])
 {
     try {
         if (!($menu = $this->menus->find($menuId))) {
             throw new Exception(__('Invalid menu.'));
         }
         foreach ($ids as $id) {
             if ($item = $this->items->find($id) and $item->getStatus() != $status) {
                 $this->items->save($item, compact('status'));
             }
         }
         if ($status == Item::STATUS_ENABLED) {
             $message = _c('{0} No menu item enabled.|{1} Menu item enabled.|]1,Inf[ Menu items enabled.', count($ids));
         } else {
             $message = _c('{0} No menu item disabled.|{1} Menu item disabled.|]1,Inf[ Menu items disabled.', count($ids));
         }
         $this['message']->success($message);
     } catch (Exception $e) {
         $this['message']->error($e->getMessage());
     }
     return $this->redirect('@system/menu', ['id' => $menuId]);
 }
Exemplo n.º 13
0
 /**
  * @Route("/feed")
  * @Route("/feed/{type}")
  */
 public function feedAction($type = '')
 {
     $feed = $this->getFeed($type);
     $feed->setTitle($this['option']->get('system:app.site_title'));
     $feed->setLink($this['url']->route('@blog/site/index', [], true));
     $feed->setDescription($this['option']->get('system:app.site_description'));
     $feed->setChannelElement('language', $this['option']->get('system:app.locale'));
     if ($last = $this->posts->query()->where(['status = ?', 'date < ?'], [Post::STATUS_PUBLISHED, new \DateTime()])->limit(1)->orderBy('modified', 'DESC')->first()) {
         $feed->setDate($last->getModified()->format(DATE_RSS));
     }
     $feed->setSelfLink($this['url']->route('@blog/site/feed', [], true));
     foreach ($this->posts->query()->where(['status = ?', 'date < ?'], [Post::STATUS_PUBLISHED, new \DateTime()])->related('user')->limit($this->extension->getParams('feed.limit'))->orderBy('date', 'DESC')->get() as $post) {
         $item = $feed->createNewItem();
         $item->setTitle($post->getTitle());
         $item->setLink($this['url']->route('@blog/id', ['id' => $post->getId()], true));
         $item->setDescription($this['content']->applyPlugins($post->getContent(), ['post' => $post, 'markdown' => $post->get('markdown'), 'readmore' => true]));
         $item->setDate($post->getDate()->format(DATE_RSS));
         $item->setAuthor($post->getUser()->getName(), $post->getUser()->getEmail());
         $item->setId($this['url']->route('@blog/id', ['id' => $post->getId()], true), true);
         $feed->addItem($item);
     }
     return $this['response']->create($feed->generateFeed(), Response::HTTP_OK, array('Content-Type' => $feed->getMIMEType()));
 }
 /**
  * @Request({"user": "******"})
  * @Response("json")
  */
 public function registerAction($data)
 {
     $response = ['success' => false];
     $errors = [];
     try {
         if ($this['user']->isAuthenticated() || $this['option']->get('system:user.registration', 'admin') == 'admin') {
             return $this->redirect('/');
         }
         if (!$this['csrf']->validate($this['request']->request->get('_csrf'))) {
             throw new Exception(__('Invalid token. Please try again.'));
         }
         $name = trim(@$data['name']);
         $username = trim(@$data['username']);
         $email = trim(@$data['email']);
         $password = @$data['password'];
         if (empty($name)) {
             $errors[] = ['field' => 'name', 'message' => __('Name required.')];
         }
         if (empty($password)) {
             $errors[] = ['field' => 'password', 'message' => __('Password required.')];
         }
         if (strlen($username) < 3 || !preg_match('/^[a-zA-Z0-9_\\-]+$/', $username)) {
             $errors[] = ['field' => 'username', 'message' => __('Username is invalid.')];
         }
         if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
             $errors[] = ['field' => 'email', 'message' => __('Email is invalid.')];
         }
         if ($this->users->query()->orWhere(['username = :username', 'email = :username'], ['username' => $username])->first()) {
             $errors[] = ['field' => 'username', 'message' => __('Username not available.'), 'dynamic' => true];
         }
         if ($this->users->query()->orWhere(['username = :email', 'email = :email'], ['email' => $email])->first()) {
             $errors[] = ['field' => 'email', 'message' => __('Email not available.'), 'dynamic' => true];
         }
         if (count($errors)) {
             throw new Exception(__('Signup failed'));
         }
         $user = new User();
         $user->setRegistered(new \DateTime());
         $user->setName($name);
         $user->setUsername($username);
         $user->setEmail($email);
         $user->setPassword($this['auth.password']->hash($password));
         $user->setStatus(UserInterface::STATUS_BLOCKED);
         $user->setRoles($this->roles->where(['id' => RoleInterface::ROLE_AUTHENTICATED])->get());
         $token = $this['auth.random']->generateString(32);
         $admin = $this['option']->get('system:user.registration') == 'approval';
         if ($verify = $this['option']->get('system:user.require_verification')) {
             $user->setActivation($token);
         } elseif ($admin) {
             $user->setActivation($token);
             $user->set('verified', true);
         } else {
             $user->setStatus(UserInterface::STATUS_ACTIVE);
         }
         $this->users->save($user);
         if ($verify) {
             $this->sendVerificationMail($user);
             $response['success'] = __('Your user account has been created. Complete your registration, by clicking the link provided in the mail that has been sent to you.');
         } elseif ($admin) {
             $this->sendApproveMail($user);
             $response['success'] = __('Your user account has been created and is pending approval by the site administrator.');
         } else {
             $this->sendWelcomeEmail($user);
             $response['success'] = __('Your user account has been created.');
         }
         if (!$response['success']) {
             $response['success'] = true;
         }
         if (!$this['request']->isXmlHttpRequest()) {
             $this['message']->success($response['success']);
             return $this->redirect('@system/auth/login');
         }
     } catch (Exception $e) {
         if (!$this['request']->isXmlHttpRequest()) {
             foreach ($errors as $error) {
                 $this['message']->error($error['message']);
             }
         } else {
             $response['errors'] = $errors;
         }
     }
     return $this['request']->isXmlHttpRequest() ? $response : $this->redirect(count($errors) ? '@system/registration' : '@system/auth/login');
 }