From c37515f880bd05b86e3e848cc184018295ec1920 Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Thu, 27 Apr 2017 15:58:32 +0200 Subject: Add filter to users management page Signed-off-by: Thomas Citharel --- .../UserBundle/Controller/ManageController.php | 42 +++++++++++++++ src/Wallabag/UserBundle/Form/SearchUserType.php | 29 ++++++++++ .../UserBundle/Repository/UserRepository.php | 15 ++++++ .../Resources/views/Manage/index.html.twig | 61 ++++++++++++---------- .../Resources/views/Manage/search_form.html.twig | 15 ++++++ 5 files changed, 134 insertions(+), 28 deletions(-) create mode 100644 src/Wallabag/UserBundle/Form/SearchUserType.php create mode 100644 src/Wallabag/UserBundle/Resources/views/Manage/search_form.html.twig (limited to 'src/Wallabag/UserBundle') diff --git a/src/Wallabag/UserBundle/Controller/ManageController.php b/src/Wallabag/UserBundle/Controller/ManageController.php index 92ee2b41..f0e3d4de 100644 --- a/src/Wallabag/UserBundle/Controller/ManageController.php +++ b/src/Wallabag/UserBundle/Controller/ManageController.php @@ -10,6 +10,7 @@ use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method; use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; use Wallabag\UserBundle\Entity\User; use Wallabag\CoreBundle\Entity\Config; +use Wallabag\UserBundle\Form\SearchUserType; /** * User controller. @@ -146,4 +147,45 @@ class ManageController extends Controller ->getForm() ; } + + /** + * @param Request $request + * @param int $page + * + * @Route("/search/{page}", name="user-search", defaults={"page" = 1}) + * + * Default parameter for page is hardcoded (in duplication of the defaults from the Route) + * because this controller is also called inside the layout template without any page as argument + * + * @return \Symfony\Component\HttpFoundation\Response + */ + public function searchFormAction(Request $request, $page = 1, $currentRoute = null) + { + // fallback to retrieve currentRoute from query parameter instead of injected one (when using inside a template) + if (null === $currentRoute && $request->query->has('currentRoute')) { + $currentRoute = $request->query->get('currentRoute'); + } + + $form = $this->createForm(SearchUserType::class); + + $form->handleRequest($request); + + if ($form->isSubmitted() && $form->isValid()) { + $this->get('logger')->info('searching users'); + $em = $this->getDoctrine()->getManager(); + + $searchTerm = (isset($request->get('search_user')['term']) ? $request->get('search_user')['term'] : ''); + + $users = $em->getRepository('WallabagUserBundle:User')->getUsersForSearch($searchTerm); + + return $this->render('WallabagUserBundle:Manage:index.html.twig', array( + 'users' => $users, + )); + } + + return $this->render('WallabagUserBundle:Manage:search_form.html.twig', [ + 'form' => $form->createView(), + 'currentRoute' => $currentRoute, + ]); + } } diff --git a/src/Wallabag/UserBundle/Form/SearchUserType.php b/src/Wallabag/UserBundle/Form/SearchUserType.php new file mode 100644 index 00000000..9ce46ee1 --- /dev/null +++ b/src/Wallabag/UserBundle/Form/SearchUserType.php @@ -0,0 +1,29 @@ +setMethod('GET') + ->add('term', TextType::class, [ + 'required' => true, + 'label' => 'user.new.form_search.term_label', + ]) + ; + } + + public function configureOptions(OptionsResolver $resolver) + { + $resolver->setDefaults([ + 'csrf_protection' => false, + ]); + } +} diff --git a/src/Wallabag/UserBundle/Repository/UserRepository.php b/src/Wallabag/UserBundle/Repository/UserRepository.php index f913f52d..66bbab39 100644 --- a/src/Wallabag/UserBundle/Repository/UserRepository.php +++ b/src/Wallabag/UserBundle/Repository/UserRepository.php @@ -52,4 +52,19 @@ class UserRepository extends EntityRepository ->getQuery() ->getSingleScalarResult(); } + + /** + * Retrieves users filtered with a search term. + * + * @param string $term + * + * @return QueryBuilder + */ + public function getUsersForSearch($term) + { + return $this->createQueryBuilder('u') + ->andWhere('lower(u.username) LIKE lower(:term) OR lower(u.email) LIKE lower(:term) OR lower(u.name) LIKE lower(:term)')->setParameter('term', '%'.$term.'%') + ->getQuery() + ->getResult(); + } } diff --git a/src/Wallabag/UserBundle/Resources/views/Manage/index.html.twig b/src/Wallabag/UserBundle/Resources/views/Manage/index.html.twig index daba29e4..abc02852 100644 --- a/src/Wallabag/UserBundle/Resources/views/Manage/index.html.twig +++ b/src/Wallabag/UserBundle/Resources/views/Manage/index.html.twig @@ -8,36 +8,41 @@
-
+

{{ 'user.description'|trans|raw }}

- - - - - - - - - - - - {% for user in users %} - - - - - - - {% endfor %} - -
{{ 'user.form.username_label'|trans }}{{ 'user.form.email_label'|trans }}{{ 'user.form.last_login_label'|trans }}{{ 'user.list.actions'|trans }}
{{ user.username }}{{ user.email }}{% if user.lastLogin %}{{ user.lastLogin|date('Y-m-d H:i:s') }}{% endif %} - {{ 'user.list.edit_action'|trans }} -
-
-

- {{ 'user.list.create_new_one'|trans }} -

+
+
+ {{ render(controller("WallabagUserBundle:Manage:searchForm", {'currentRoute': app.request.attributes.get('_route')})) }} +
+
+ + + + + + + + + + + + {% for user in users %} + + + + + + + {% endfor %} + +
{{ 'user.form.username_label'|trans }}{{ 'user.form.email_label'|trans }}{{ 'user.form2017-03-10 16:51:07.last_login_label'|trans }}{{ 'user.list.actions'|trans }}
{{ user.username }}{{ user.email }}{% if user.lastLogin %}{{ user.lastLogin|date('Y-m-d H:i:s') }}{% endif %} + {{ 'user.list.edit_action'|trans }} +
+
+

+ {{ 'user.list.create_new_one'|trans }} +

diff --git a/src/Wallabag/UserBundle/Resources/views/Manage/search_form.html.twig b/src/Wallabag/UserBundle/Resources/views/Manage/search_form.html.twig new file mode 100644 index 00000000..f59388d0 --- /dev/null +++ b/src/Wallabag/UserBundle/Resources/views/Manage/search_form.html.twig @@ -0,0 +1,15 @@ +
+ {% if form_errors(form) %} + {{ form_errors(form) }} + {% endif %} + + {% if form_errors(form.term) %} + {{ form_errors(form.term) }} + {% endif %} + + search + {{ form_widget(form.term, { 'attr': {'autocomplete': 'off', 'placeholder': 'user.search.placeholder'} }) }} + + + {{ form_rest(form) }} +
-- cgit v1.2.3 From 50cfd8108b8e318fd28564d2e9d30943ab12aac0 Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Thu, 27 Apr 2017 16:23:54 +0200 Subject: Add pagination Signed-off-by: Thomas Citharel --- .../UserBundle/Controller/ManageController.php | 43 ++++++++++++++++++---- .../UserBundle/Repository/UserRepository.php | 6 +-- .../Resources/views/Manage/index.html.twig | 8 +++- 3 files changed, 45 insertions(+), 12 deletions(-) (limited to 'src/Wallabag/UserBundle') diff --git a/src/Wallabag/UserBundle/Controller/ManageController.php b/src/Wallabag/UserBundle/Controller/ManageController.php index f0e3d4de..86fcd431 100644 --- a/src/Wallabag/UserBundle/Controller/ManageController.php +++ b/src/Wallabag/UserBundle/Controller/ManageController.php @@ -4,12 +4,14 @@ namespace Wallabag\UserBundle\Controller; use FOS\UserBundle\Event\UserEvent; use FOS\UserBundle\FOSUserEvents; +use Pagerfanta\Adapter\DoctrineORMAdapter; +use Pagerfanta\Exception\OutOfRangeCurrentPageException; +use Pagerfanta\Pagerfanta; use Symfony\Component\HttpFoundation\Request; use Symfony\Bundle\FrameworkBundle\Controller\Controller; use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method; use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; use Wallabag\UserBundle\Entity\User; -use Wallabag\CoreBundle\Entity\Config; use Wallabag\UserBundle\Form\SearchUserType; /** @@ -20,17 +22,32 @@ class ManageController extends Controller /** * Lists all User entities. * - * @Route("/", name="user_index") + * @Route("/index/{page}", name="user_index") * @Method("GET") + * + * @param int $page + * + * @return \Symfony\Component\HttpFoundation\RedirectResponse|\Symfony\Component\HttpFoundation\Response */ - public function indexAction() + public function indexAction($page = 1) { $em = $this->getDoctrine()->getManager(); - $users = $em->getRepository('WallabagUserBundle:User')->findAll(); + $qb = $em->getRepository('WallabagUserBundle:User')->createQueryBuilder('u'); + $pagerAdapter = new DoctrineORMAdapter($qb->getQuery(), true, false); + $pagerFanta = new Pagerfanta($pagerAdapter); + $pagerFanta->setMaxPerPage(50); + + try { + $pagerFanta->setCurrentPage($page); + } catch (OutOfRangeCurrentPageException $e) { + if ($page > 1) { + return $this->redirect($this->generateUrl('user_index', ['page' => $pagerFanta->getNbPages()]), 302); + } + } return $this->render('WallabagUserBundle:Manage:index.html.twig', array( - 'users' => $users, + 'users' => $pagerFanta, )); } @@ -176,10 +193,22 @@ class ManageController extends Controller $searchTerm = (isset($request->get('search_user')['term']) ? $request->get('search_user')['term'] : ''); - $users = $em->getRepository('WallabagUserBundle:User')->getUsersForSearch($searchTerm); + $qb = $em->getRepository('WallabagUserBundle:User')->getQueryBuilderForSearch($searchTerm); + + $pagerAdapter = new DoctrineORMAdapter($qb->getQuery(), true, false); + $pagerFanta = new Pagerfanta($pagerAdapter); + $pagerFanta->setMaxPerPage(50); + + try { + $pagerFanta->setCurrentPage($page); + } catch (OutOfRangeCurrentPageException $e) { + if ($page > 1) { + return $this->redirect($this->generateUrl('user_index', ['page' => $pagerFanta->getNbPages()]), 302); + } + } return $this->render('WallabagUserBundle:Manage:index.html.twig', array( - 'users' => $users, + 'users' => $pagerFanta, )); } diff --git a/src/Wallabag/UserBundle/Repository/UserRepository.php b/src/Wallabag/UserBundle/Repository/UserRepository.php index 66bbab39..6adbe329 100644 --- a/src/Wallabag/UserBundle/Repository/UserRepository.php +++ b/src/Wallabag/UserBundle/Repository/UserRepository.php @@ -60,11 +60,9 @@ class UserRepository extends EntityRepository * * @return QueryBuilder */ - public function getUsersForSearch($term) + public function getQueryBuilderForSearch($term) { return $this->createQueryBuilder('u') - ->andWhere('lower(u.username) LIKE lower(:term) OR lower(u.email) LIKE lower(:term) OR lower(u.name) LIKE lower(:term)')->setParameter('term', '%'.$term.'%') - ->getQuery() - ->getResult(); + ->andWhere('lower(u.username) LIKE lower(:term) OR lower(u.email) LIKE lower(:term) OR lower(u.name) LIKE lower(:term)')->setParameter('term', '%'.$term.'%'); } } diff --git a/src/Wallabag/UserBundle/Resources/views/Manage/index.html.twig b/src/Wallabag/UserBundle/Resources/views/Manage/index.html.twig index abc02852..7a76f157 100644 --- a/src/Wallabag/UserBundle/Resources/views/Manage/index.html.twig +++ b/src/Wallabag/UserBundle/Resources/views/Manage/index.html.twig @@ -7,6 +7,9 @@
+ {% if users.getNbPages > 1 %} + {{ pagerfanta(users, 'twitter_bootstrap_translated', {'proximity': 1}) }} + {% endif %}

{{ 'user.description'|trans|raw }}

@@ -22,7 +25,7 @@ {{ 'user.form.username_label'|trans }} {{ 'user.form.email_label'|trans }} - {{ 'user.form2017-03-10 16:51:07.last_login_label'|trans }} + {{ 'user.form.last_login_label'|trans }} {{ 'user.list.actions'|trans }} @@ -43,6 +46,9 @@

{{ 'user.list.create_new_one'|trans }}

+ {% if users.getNbPages > 1 %} + {{ pagerfanta(users, 'twitter_bootstrap_translated', {'proximity': 1}) }} + {% endif %}
-- cgit v1.2.3 From a2daa32d0c6f71aa8553aed3c6ed58d7aa861baa Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Thu, 27 Apr 2017 16:40:18 +0200 Subject: Fix tests Signed-off-by: Thomas Citharel --- src/Wallabag/UserBundle/Resources/views/Manage/search_form.html.twig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/Wallabag/UserBundle') diff --git a/src/Wallabag/UserBundle/Resources/views/Manage/search_form.html.twig b/src/Wallabag/UserBundle/Resources/views/Manage/search_form.html.twig index f59388d0..1d4df204 100644 --- a/src/Wallabag/UserBundle/Resources/views/Manage/search_form.html.twig +++ b/src/Wallabag/UserBundle/Resources/views/Manage/search_form.html.twig @@ -1,4 +1,4 @@ -
+ {% if form_errors(form) %} {{ form_errors(form) }} {% endif %} -- cgit v1.2.3 From d01dc5a81e7fde37d98fe6b10b9329b53add5b6a Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Sat, 29 Apr 2017 19:39:51 +0200 Subject: rename index to list Signed-off-by: Thomas Citharel --- src/Wallabag/UserBundle/Controller/ManageController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/Wallabag/UserBundle') diff --git a/src/Wallabag/UserBundle/Controller/ManageController.php b/src/Wallabag/UserBundle/Controller/ManageController.php index 86fcd431..3ea773ee 100644 --- a/src/Wallabag/UserBundle/Controller/ManageController.php +++ b/src/Wallabag/UserBundle/Controller/ManageController.php @@ -22,7 +22,7 @@ class ManageController extends Controller /** * Lists all User entities. * - * @Route("/index/{page}", name="user_index") + * @Route("/list/{page}", name="user_index") * @Method("GET") * * @param int $page -- cgit v1.2.3 From b5b6877976bc32f23e51c2fb0f3f973f0d571b10 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Tue, 2 May 2017 15:27:58 +0200 Subject: Merged list and search methods --- .../UserBundle/Controller/ManageController.php | 72 +++++----------------- .../Resources/views/Manage/index.html.twig | 14 ++++- .../Resources/views/Manage/search_form.html.twig | 15 ----- 3 files changed, 29 insertions(+), 72 deletions(-) delete mode 100644 src/Wallabag/UserBundle/Resources/views/Manage/search_form.html.twig (limited to 'src/Wallabag/UserBundle') diff --git a/src/Wallabag/UserBundle/Controller/ManageController.php b/src/Wallabag/UserBundle/Controller/ManageController.php index 3ea773ee..1c5c86d4 100644 --- a/src/Wallabag/UserBundle/Controller/ManageController.php +++ b/src/Wallabag/UserBundle/Controller/ManageController.php @@ -19,38 +19,6 @@ use Wallabag\UserBundle\Form\SearchUserType; */ class ManageController extends Controller { - /** - * Lists all User entities. - * - * @Route("/list/{page}", name="user_index") - * @Method("GET") - * - * @param int $page - * - * @return \Symfony\Component\HttpFoundation\RedirectResponse|\Symfony\Component\HttpFoundation\Response - */ - public function indexAction($page = 1) - { - $em = $this->getDoctrine()->getManager(); - - $qb = $em->getRepository('WallabagUserBundle:User')->createQueryBuilder('u'); - $pagerAdapter = new DoctrineORMAdapter($qb->getQuery(), true, false); - $pagerFanta = new Pagerfanta($pagerAdapter); - $pagerFanta->setMaxPerPage(50); - - try { - $pagerFanta->setCurrentPage($page); - } catch (OutOfRangeCurrentPageException $e) { - if ($page > 1) { - return $this->redirect($this->generateUrl('user_index', ['page' => $pagerFanta->getNbPages()]), 302); - } - } - - return $this->render('WallabagUserBundle:Manage:index.html.twig', array( - 'users' => $pagerFanta, - )); - } - /** * Creates a new User entity. * @@ -169,52 +137,44 @@ class ManageController extends Controller * @param Request $request * @param int $page * - * @Route("/search/{page}", name="user-search", defaults={"page" = 1}) + * @Route("/list/{page}", name="user_index", defaults={"page" = 1}) * * Default parameter for page is hardcoded (in duplication of the defaults from the Route) * because this controller is also called inside the layout template without any page as argument * * @return \Symfony\Component\HttpFoundation\Response */ - public function searchFormAction(Request $request, $page = 1, $currentRoute = null) + public function searchFormAction(Request $request, $page = 1) { - // fallback to retrieve currentRoute from query parameter instead of injected one (when using inside a template) - if (null === $currentRoute && $request->query->has('currentRoute')) { - $currentRoute = $request->query->get('currentRoute'); - } + $em = $this->getDoctrine()->getManager(); + $qb = $em->getRepository('WallabagUserBundle:User')->createQueryBuilder('u'); $form = $this->createForm(SearchUserType::class); - $form->handleRequest($request); if ($form->isSubmitted() && $form->isValid()) { $this->get('logger')->info('searching users'); - $em = $this->getDoctrine()->getManager(); $searchTerm = (isset($request->get('search_user')['term']) ? $request->get('search_user')['term'] : ''); $qb = $em->getRepository('WallabagUserBundle:User')->getQueryBuilderForSearch($searchTerm); + } - $pagerAdapter = new DoctrineORMAdapter($qb->getQuery(), true, false); - $pagerFanta = new Pagerfanta($pagerAdapter); - $pagerFanta->setMaxPerPage(50); + $pagerAdapter = new DoctrineORMAdapter($qb->getQuery(), true, false); + $pagerFanta = new Pagerfanta($pagerAdapter); + $pagerFanta->setMaxPerPage(50); - try { - $pagerFanta->setCurrentPage($page); - } catch (OutOfRangeCurrentPageException $e) { - if ($page > 1) { - return $this->redirect($this->generateUrl('user_index', ['page' => $pagerFanta->getNbPages()]), 302); - } + try { + $pagerFanta->setCurrentPage($page); + } catch (OutOfRangeCurrentPageException $e) { + if ($page > 1) { + return $this->redirect($this->generateUrl('user_index', ['page' => $pagerFanta->getNbPages()]), 302); } - - return $this->render('WallabagUserBundle:Manage:index.html.twig', array( - 'users' => $pagerFanta, - )); } - return $this->render('WallabagUserBundle:Manage:search_form.html.twig', [ - 'form' => $form->createView(), - 'currentRoute' => $currentRoute, + return $this->render('WallabagUserBundle:Manage:index.html.twig', [ + 'searchForm' => $form->createView(), + 'users' => $pagerFanta, ]); } } diff --git a/src/Wallabag/UserBundle/Resources/views/Manage/index.html.twig b/src/Wallabag/UserBundle/Resources/views/Manage/index.html.twig index 7a76f157..15002632 100644 --- a/src/Wallabag/UserBundle/Resources/views/Manage/index.html.twig +++ b/src/Wallabag/UserBundle/Resources/views/Manage/index.html.twig @@ -16,7 +16,19 @@
- {{ render(controller("WallabagUserBundle:Manage:searchForm", {'currentRoute': app.request.attributes.get('_route')})) }} + + {% if form_errors(searchForm) %} + {{ form_errors(searchForm) }} + {% endif %} + + {% if form_errors(searchForm.term) %} + {{ form_errors(searchForm.term) }} + {% endif %} + + {{ form_widget(searchForm.term, { 'attr': {'autocomplete': 'off', 'placeholder': 'user.search.placeholder'} }) }} + + {{ form_rest(searchForm) }} +
diff --git a/src/Wallabag/UserBundle/Resources/views/Manage/search_form.html.twig b/src/Wallabag/UserBundle/Resources/views/Manage/search_form.html.twig deleted file mode 100644 index 1d4df204..00000000 --- a/src/Wallabag/UserBundle/Resources/views/Manage/search_form.html.twig +++ /dev/null @@ -1,15 +0,0 @@ -
- {% if form_errors(form) %} - {{ form_errors(form) }} - {% endif %} - - {% if form_errors(form.term) %} - {{ form_errors(form.term) }} - {% endif %} - - search - {{ form_widget(form.term, { 'attr': {'autocomplete': 'off', 'placeholder': 'user.search.placeholder'} }) }} - - - {{ form_rest(form) }} -
-- cgit v1.2.3 From 2251045901875aa815dee43ec467fb1af8d416d0 Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Sat, 29 Apr 2017 19:22:50 +0200 Subject: WIP Signed-off-by: Thomas Citharel --- src/Wallabag/UserBundle/Entity/User.php | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'src/Wallabag/UserBundle') diff --git a/src/Wallabag/UserBundle/Entity/User.php b/src/Wallabag/UserBundle/Entity/User.php index 3a167de7..1863c966 100644 --- a/src/Wallabag/UserBundle/Entity/User.php +++ b/src/Wallabag/UserBundle/Entity/User.php @@ -4,6 +4,7 @@ namespace Wallabag\UserBundle\Entity; use Doctrine\Common\Collections\ArrayCollection; use Doctrine\ORM\Mapping as ORM; +use JMS\Serializer\Annotation\Groups; use Scheb\TwoFactorBundle\Model\Email\TwoFactorInterface; use Scheb\TwoFactorBundle\Model\TrustedComputerInterface; use FOS\UserBundle\Model\User as BaseUser; @@ -35,6 +36,7 @@ class User extends BaseUser implements TwoFactorInterface, TrustedComputerInterf * @ORM\Column(name="id", type="integer") * @ORM\Id * @ORM\GeneratedValue(strategy="AUTO") + * @Groups({"user_api"}) */ protected $id; @@ -42,6 +44,7 @@ class User extends BaseUser implements TwoFactorInterface, TrustedComputerInterf * @var string * * @ORM\Column(name="name", type="text", nullable=true) + * @Groups({"user_api"}) */ protected $name; @@ -49,6 +52,7 @@ class User extends BaseUser implements TwoFactorInterface, TrustedComputerInterf * @var date * * @ORM\Column(name="created_at", type="datetime") + * @Groups({"user_api"}) */ protected $createdAt; @@ -56,6 +60,7 @@ class User extends BaseUser implements TwoFactorInterface, TrustedComputerInterf * @var date * * @ORM\Column(name="updated_at", type="datetime") + * @Groups({"user_api"}) */ protected $updatedAt; -- cgit v1.2.3 From 5709ecb36809fb009446a11a758232bbe8f264e4 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Tue, 30 May 2017 07:56:01 +0200 Subject: Re-use `NewUserType` to validate registration MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The only ugly things is how we handle error by generating the view and then parse the content to retrieve all errors… Fix exposition fields in User entity --- src/Wallabag/UserBundle/Entity/User.php | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) (limited to 'src/Wallabag/UserBundle') diff --git a/src/Wallabag/UserBundle/Entity/User.php b/src/Wallabag/UserBundle/Entity/User.php index 1863c966..1ff3046a 100644 --- a/src/Wallabag/UserBundle/Entity/User.php +++ b/src/Wallabag/UserBundle/Entity/User.php @@ -5,11 +5,10 @@ namespace Wallabag\UserBundle\Entity; use Doctrine\Common\Collections\ArrayCollection; use Doctrine\ORM\Mapping as ORM; use JMS\Serializer\Annotation\Groups; +use JMS\Serializer\Annotation\XmlRoot; use Scheb\TwoFactorBundle\Model\Email\TwoFactorInterface; use Scheb\TwoFactorBundle\Model\TrustedComputerInterface; use FOS\UserBundle\Model\User as BaseUser; -use JMS\Serializer\Annotation\ExclusionPolicy; -use JMS\Serializer\Annotation\Expose; use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity; use Symfony\Component\Security\Core\User\UserInterface; use Wallabag\ApiBundle\Entity\Client; @@ -19,23 +18,24 @@ use Wallabag\CoreBundle\Entity\Entry; /** * User. * + * @XmlRoot("user") * @ORM\Entity(repositoryClass="Wallabag\UserBundle\Repository\UserRepository") * @ORM\Table(name="`user`") * @ORM\HasLifecycleCallbacks() - * @ExclusionPolicy("all") * * @UniqueEntity("email") * @UniqueEntity("username") */ class User extends BaseUser implements TwoFactorInterface, TrustedComputerInterface { + /** @Serializer\XmlAttribute */ /** * @var int * - * @Expose * @ORM\Column(name="id", type="integer") * @ORM\Id * @ORM\GeneratedValue(strategy="AUTO") + * * @Groups({"user_api"}) */ protected $id; @@ -44,14 +44,30 @@ class User extends BaseUser implements TwoFactorInterface, TrustedComputerInterf * @var string * * @ORM\Column(name="name", type="text", nullable=true) + * * @Groups({"user_api"}) */ protected $name; + /** + * @var string + * + * @Groups({"user_api"}) + */ + protected $username; + + /** + * @var string + * + * @Groups({"user_api"}) + */ + protected $email; + /** * @var date * * @ORM\Column(name="created_at", type="datetime") + * * @Groups({"user_api"}) */ protected $createdAt; @@ -60,6 +76,7 @@ class User extends BaseUser implements TwoFactorInterface, TrustedComputerInterf * @var date * * @ORM\Column(name="updated_at", type="datetime") + * * @Groups({"user_api"}) */ protected $updatedAt; -- cgit v1.2.3 From d069bff4f606be75c47a3415f2a5af13d6f04865 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Tue, 30 May 2017 07:56:41 +0200 Subject: Remove unknown validation_groups The Profile validation_groups does not exist and then for validation to be skipped (like password length) --- src/Wallabag/UserBundle/Controller/ManageController.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'src/Wallabag/UserBundle') diff --git a/src/Wallabag/UserBundle/Controller/ManageController.php b/src/Wallabag/UserBundle/Controller/ManageController.php index 1c5c86d4..084f2c67 100644 --- a/src/Wallabag/UserBundle/Controller/ManageController.php +++ b/src/Wallabag/UserBundle/Controller/ManageController.php @@ -33,9 +33,7 @@ class ManageController extends Controller // enable created user by default $user->setEnabled(true); - $form = $this->createForm('Wallabag\UserBundle\Form\NewUserType', $user, [ - 'validation_groups' => ['Profile'], - ]); + $form = $this->createForm('Wallabag\UserBundle\Form\NewUserType', $user); $form->handleRequest($request); if ($form->isSubmitted() && $form->isValid()) { -- cgit v1.2.3 From c3f7a2ca707dbd43a8798cb3fcefe01333305d8b Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Thu, 1 Jun 2017 09:30:20 +0200 Subject: Set the right variable type --- src/Wallabag/UserBundle/Entity/User.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/Wallabag/UserBundle') diff --git a/src/Wallabag/UserBundle/Entity/User.php b/src/Wallabag/UserBundle/Entity/User.php index 1ff3046a..6cc962b8 100644 --- a/src/Wallabag/UserBundle/Entity/User.php +++ b/src/Wallabag/UserBundle/Entity/User.php @@ -64,7 +64,7 @@ class User extends BaseUser implements TwoFactorInterface, TrustedComputerInterf protected $email; /** - * @var date + * @var \DateTime * * @ORM\Column(name="created_at", type="datetime") * @@ -73,7 +73,7 @@ class User extends BaseUser implements TwoFactorInterface, TrustedComputerInterf protected $createdAt; /** - * @var date + * @var \DateTime * * @ORM\Column(name="updated_at", type="datetime") * -- cgit v1.2.3 From 10bf812a9ed6364902eb0382fe261f3ec0ae7254 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Thu, 1 Jun 2017 09:30:38 +0200 Subject: Both parameter wasn't used in the function, removing them --- src/Wallabag/UserBundle/EventListener/CreateConfigListener.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'src/Wallabag/UserBundle') diff --git a/src/Wallabag/UserBundle/EventListener/CreateConfigListener.php b/src/Wallabag/UserBundle/EventListener/CreateConfigListener.php index 0bdd1cae..e4d55c19 100644 --- a/src/Wallabag/UserBundle/EventListener/CreateConfigListener.php +++ b/src/Wallabag/UserBundle/EventListener/CreateConfigListener.php @@ -5,7 +5,6 @@ namespace Wallabag\UserBundle\EventListener; use Doctrine\ORM\EntityManager; use FOS\UserBundle\Event\UserEvent; use FOS\UserBundle\FOSUserEvents; -use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Wallabag\CoreBundle\Entity\Config; @@ -47,7 +46,7 @@ class CreateConfigListener implements EventSubscriberInterface ]; } - public function createConfig(UserEvent $event, $eventName = null, EventDispatcherInterface $eventDispatcher = null) + public function createConfig(UserEvent $event) { $config = new Config($event->getUser()); $config->setTheme($this->theme); -- cgit v1.2.3 From 3a6af6c580b686593045a8f0cfbfc478aa93943c Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Thu, 1 Jun 2017 09:36:01 +0200 Subject: fixup! Set the right variable type --- src/Wallabag/UserBundle/Entity/User.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/Wallabag/UserBundle') diff --git a/src/Wallabag/UserBundle/Entity/User.php b/src/Wallabag/UserBundle/Entity/User.php index 6cc962b8..ed6ce331 100644 --- a/src/Wallabag/UserBundle/Entity/User.php +++ b/src/Wallabag/UserBundle/Entity/User.php @@ -157,7 +157,7 @@ class User extends BaseUser implements TwoFactorInterface, TrustedComputerInterf } /** - * @return string + * @return \DateTime */ public function getCreatedAt() { @@ -165,7 +165,7 @@ class User extends BaseUser implements TwoFactorInterface, TrustedComputerInterf } /** - * @return string + * @return \DateTime */ public function getUpdatedAt() { -- cgit v1.2.3 From be9d693e74e41fdcdb18bf80aa1aff614154bcce Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Thu, 1 Jun 2017 10:42:19 +0200 Subject: remove craueconfig domain name setting and add a proper one in parameters --- src/Wallabag/UserBundle/Resources/config/services.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/Wallabag/UserBundle') diff --git a/src/Wallabag/UserBundle/Resources/config/services.yml b/src/Wallabag/UserBundle/Resources/config/services.yml index 72f6f12c..bfba6010 100644 --- a/src/Wallabag/UserBundle/Resources/config/services.yml +++ b/src/Wallabag/UserBundle/Resources/config/services.yml @@ -7,7 +7,7 @@ services: - "%scheb_two_factor.email.sender_email%" - "%scheb_two_factor.email.sender_name%" - '@=service(''craue_config'').get(''wallabag_support_url'')' - - '@=service(''craue_config'').get(''wallabag_url'')' + - '%domain_name%' wallabag_user.password_resetting: class: Wallabag\UserBundle\EventListener\PasswordResettingListener -- cgit v1.2.3 From 0c00e5251671c3648eabb8888271c09137ad902d Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Wed, 7 Jun 2017 23:23:28 +0200 Subject: Create a client when creating a user using the api MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit While creating a new user using the API, we also create a new client for the current user. So the app which just create the user can use its newly created client to configure the app. That new client is only return after creating the user. When calling the endpoint /api/user to get user information, the new client information won’t be return. --- src/Wallabag/UserBundle/Entity/User.php | 38 +++++++++++++++++++++++++++------ 1 file changed, 31 insertions(+), 7 deletions(-) (limited to 'src/Wallabag/UserBundle') diff --git a/src/Wallabag/UserBundle/Entity/User.php b/src/Wallabag/UserBundle/Entity/User.php index ed6ce331..5c75846f 100644 --- a/src/Wallabag/UserBundle/Entity/User.php +++ b/src/Wallabag/UserBundle/Entity/User.php @@ -6,6 +6,7 @@ use Doctrine\Common\Collections\ArrayCollection; use Doctrine\ORM\Mapping as ORM; use JMS\Serializer\Annotation\Groups; use JMS\Serializer\Annotation\XmlRoot; +use JMS\Serializer\Annotation\Accessor; use Scheb\TwoFactorBundle\Model\Email\TwoFactorInterface; use Scheb\TwoFactorBundle\Model\TrustedComputerInterface; use FOS\UserBundle\Model\User as BaseUser; @@ -36,7 +37,7 @@ class User extends BaseUser implements TwoFactorInterface, TrustedComputerInterf * @ORM\Id * @ORM\GeneratedValue(strategy="AUTO") * - * @Groups({"user_api"}) + * @Groups({"user_api", "user_api_with_client"}) */ protected $id; @@ -45,21 +46,21 @@ class User extends BaseUser implements TwoFactorInterface, TrustedComputerInterf * * @ORM\Column(name="name", type="text", nullable=true) * - * @Groups({"user_api"}) + * @Groups({"user_api", "user_api_with_client"}) */ protected $name; /** * @var string * - * @Groups({"user_api"}) + * @Groups({"user_api", "user_api_with_client"}) */ protected $username; /** * @var string * - * @Groups({"user_api"}) + * @Groups({"user_api", "user_api_with_client"}) */ protected $email; @@ -68,7 +69,7 @@ class User extends BaseUser implements TwoFactorInterface, TrustedComputerInterf * * @ORM\Column(name="created_at", type="datetime") * - * @Groups({"user_api"}) + * @Groups({"user_api", "user_api_with_client"}) */ protected $createdAt; @@ -77,7 +78,7 @@ class User extends BaseUser implements TwoFactorInterface, TrustedComputerInterf * * @ORM\Column(name="updated_at", type="datetime") * - * @Groups({"user_api"}) + * @Groups({"user_api", "user_api_with_client"}) */ protected $updatedAt; @@ -97,7 +98,8 @@ class User extends BaseUser implements TwoFactorInterface, TrustedComputerInterf private $authCode; /** - * @var bool Enabled yes/no + * @var bool + * * @ORM\Column(type="boolean") */ private $twoFactorAuthentication = false; @@ -112,6 +114,14 @@ class User extends BaseUser implements TwoFactorInterface, TrustedComputerInterf */ protected $clients; + /** + * @see getFirstClient() below + * + * @Groups({"user_api_with_client"}) + * @Accessor(getter="getFirstClient") + */ + protected $default_client; + public function __construct() { parent::__construct(); @@ -288,4 +298,18 @@ class User extends BaseUser implements TwoFactorInterface, TrustedComputerInterf { return $this->clients; } + + /** + * Only used by the API when creating a new user it'll also return the first client (which was also created at the same time). + * + * @return Client + */ + public function getFirstClient() + { + if (empty($this->clients)) { + return $this->clients; + } + + return $this->clients->first(); + } } -- cgit v1.2.3 From eb570e49c8e3ba12638fac600bb5527191c2aaa2 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Wed, 7 Jun 2017 23:23:34 +0200 Subject: CS --- src/Wallabag/UserBundle/Entity/User.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/Wallabag/UserBundle') diff --git a/src/Wallabag/UserBundle/Entity/User.php b/src/Wallabag/UserBundle/Entity/User.php index 5c75846f..aba76ca7 100644 --- a/src/Wallabag/UserBundle/Entity/User.php +++ b/src/Wallabag/UserBundle/Entity/User.php @@ -110,6 +110,8 @@ class User extends BaseUser implements TwoFactorInterface, TrustedComputerInterf private $trusted; /** + * @var ArrayCollection + * * @ORM\OneToMany(targetEntity="Wallabag\ApiBundle\Entity\Client", mappedBy="user", cascade={"remove"}) */ protected $clients; @@ -306,10 +308,8 @@ class User extends BaseUser implements TwoFactorInterface, TrustedComputerInterf */ public function getFirstClient() { - if (empty($this->clients)) { - return $this->clients; + if (!empty($this->clients)) { + return $this->clients->first(); } - - return $this->clients->first(); } } -- cgit v1.2.3 From 63f9f22fa37b14171c6f92d24f99ccf01ae7af00 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Thu, 8 Jun 2017 22:24:49 +0200 Subject: Log an error level message when user auth fail MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When a user login using the form we know log an error level information with information about the user: - username used - IP - User agent For example: > Authentication failure for user "eza", from IP "127.0.0.1", with UA: "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36". It’ll allows server admin using fail2ban to configure it to block these people if they generate too much failure authentication. --- .../UserBundle/Resources/config/services.yml | 8 +++ .../CustomAuthenticationFailureHandler.php | 62 ++++++++++++++++++++++ 2 files changed, 70 insertions(+) create mode 100644 src/Wallabag/UserBundle/Security/CustomAuthenticationFailureHandler.php (limited to 'src/Wallabag/UserBundle') diff --git a/src/Wallabag/UserBundle/Resources/config/services.yml b/src/Wallabag/UserBundle/Resources/config/services.yml index 72f6f12c..6ab463e3 100644 --- a/src/Wallabag/UserBundle/Resources/config/services.yml +++ b/src/Wallabag/UserBundle/Resources/config/services.yml @@ -35,3 +35,11 @@ services: - "%wallabag_core.list_mode%" tags: - { name: kernel.event_subscriber } + + wallabag_user.security.custom_auth_failure_handler: + class: Wallabag\UserBundle\Security\CustomAuthenticationFailureHandler + arguments: + - "@http_kernel" + - "@security.http_utils" + - { } + - "@logger" diff --git a/src/Wallabag/UserBundle/Security/CustomAuthenticationFailureHandler.php b/src/Wallabag/UserBundle/Security/CustomAuthenticationFailureHandler.php new file mode 100644 index 00000000..93e2d17b --- /dev/null +++ b/src/Wallabag/UserBundle/Security/CustomAuthenticationFailureHandler.php @@ -0,0 +1,62 @@ +options['failure_path_parameter'])) { + $this->options['failure_path'] = $failureUrl; + } + + if (null === $this->options['failure_path']) { + $this->options['failure_path'] = $this->options['login_path']; + } + + if ($this->options['failure_forward']) { + $this->logger->debug('Authentication failure, forward triggered.', ['failure_path' => $this->options['failure_path']]); + + $this->logError($request); + + $subRequest = $this->httpUtils->createRequest($request, $this->options['failure_path']); + $subRequest->attributes->set(Security::AUTHENTICATION_ERROR, $exception); + + return $this->httpKernel->handle($subRequest, HttpKernelInterface::SUB_REQUEST); + } + + $this->logger->debug('Authentication failure, redirect triggered.', ['failure_path' => $this->options['failure_path']]); + + $this->logError($request); + + $request->getSession()->set(Security::AUTHENTICATION_ERROR, $exception); + + return $this->httpUtils->createRedirectResponse($request, $this->options['failure_path']); + } + + /** + * Log error information about fialure + * + * @param Request $request + */ + private function logError(Request $request) + { + $this->logger->error('Authentication failure for user "'.$request->request->get('_username').'", from IP "'.$request->getClientIp().'", with UA: "'.$request->server->get('HTTP_USER_AGENT').'".'); + } +} -- cgit v1.2.3 From fa1c9d7cc7f3c4d2f9167a5b62bbc8cd1f9df59b Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Thu, 8 Jun 2017 22:52:26 +0200 Subject: CS --- .../UserBundle/Security/CustomAuthenticationFailureHandler.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/Wallabag/UserBundle') diff --git a/src/Wallabag/UserBundle/Security/CustomAuthenticationFailureHandler.php b/src/Wallabag/UserBundle/Security/CustomAuthenticationFailureHandler.php index 93e2d17b..2d4ea0ea 100644 --- a/src/Wallabag/UserBundle/Security/CustomAuthenticationFailureHandler.php +++ b/src/Wallabag/UserBundle/Security/CustomAuthenticationFailureHandler.php @@ -51,9 +51,9 @@ class CustomAuthenticationFailureHandler extends DefaultAuthenticationFailureHan } /** - * Log error information about fialure + * Log error information about fialure. * - * @param Request $request + * @param Request $request */ private function logError(Request $request) { -- cgit v1.2.3 From f81a34e37929a822755d120215d2f18f042ff713 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Fri, 9 Jun 2017 09:45:43 +0200 Subject: Use a listener to catch auth failure --- .../AuthenticationFailureListener.php | 40 ++++++++++++++ .../UserBundle/Resources/config/services.yml | 10 ++-- .../CustomAuthenticationFailureHandler.php | 62 ---------------------- 3 files changed, 45 insertions(+), 67 deletions(-) create mode 100644 src/Wallabag/UserBundle/EventListener/AuthenticationFailureListener.php delete mode 100644 src/Wallabag/UserBundle/Security/CustomAuthenticationFailureHandler.php (limited to 'src/Wallabag/UserBundle') diff --git a/src/Wallabag/UserBundle/EventListener/AuthenticationFailureListener.php b/src/Wallabag/UserBundle/EventListener/AuthenticationFailureListener.php new file mode 100644 index 00000000..10f13233 --- /dev/null +++ b/src/Wallabag/UserBundle/EventListener/AuthenticationFailureListener.php @@ -0,0 +1,40 @@ +requestStack = $requestStack; + $this->logger = $logger; + } + + /** + * {@inheritdoc} + */ + public static function getSubscribedEvents() + { + return [ + AuthenticationEvents::AUTHENTICATION_FAILURE => 'onAuthenticationFailure', + ]; + } + + /** + * On failure, add a custom error in log so server admin can configure fail2ban to block IP from people who try to login too much. + */ + public function onAuthenticationFailure() + { + $request = $this->requestStack->getMasterRequest(); + + $this->logger->error('Authentication failure for user "'.$request->request->get('_username').'", from IP "'.$request->getClientIp().'", with UA: "'.$request->server->get('HTTP_USER_AGENT').'".'); + } +} diff --git a/src/Wallabag/UserBundle/Resources/config/services.yml b/src/Wallabag/UserBundle/Resources/config/services.yml index 6ab463e3..f2cd6e01 100644 --- a/src/Wallabag/UserBundle/Resources/config/services.yml +++ b/src/Wallabag/UserBundle/Resources/config/services.yml @@ -36,10 +36,10 @@ services: tags: - { name: kernel.event_subscriber } - wallabag_user.security.custom_auth_failure_handler: - class: Wallabag\UserBundle\Security\CustomAuthenticationFailureHandler + wallabag_user.listener.authentication_failure_event_listener: + class: Wallabag\UserBundle\EventListener\AuthenticationFailureListener arguments: - - "@http_kernel" - - "@security.http_utils" - - { } + - "@request_stack" - "@logger" + tags: + - { name: kernel.event_listener, event: security.authentication.failure, method: onAuthenticationFailure } diff --git a/src/Wallabag/UserBundle/Security/CustomAuthenticationFailureHandler.php b/src/Wallabag/UserBundle/Security/CustomAuthenticationFailureHandler.php deleted file mode 100644 index 2d4ea0ea..00000000 --- a/src/Wallabag/UserBundle/Security/CustomAuthenticationFailureHandler.php +++ /dev/null @@ -1,62 +0,0 @@ -options['failure_path_parameter'])) { - $this->options['failure_path'] = $failureUrl; - } - - if (null === $this->options['failure_path']) { - $this->options['failure_path'] = $this->options['login_path']; - } - - if ($this->options['failure_forward']) { - $this->logger->debug('Authentication failure, forward triggered.', ['failure_path' => $this->options['failure_path']]); - - $this->logError($request); - - $subRequest = $this->httpUtils->createRequest($request, $this->options['failure_path']); - $subRequest->attributes->set(Security::AUTHENTICATION_ERROR, $exception); - - return $this->httpKernel->handle($subRequest, HttpKernelInterface::SUB_REQUEST); - } - - $this->logger->debug('Authentication failure, redirect triggered.', ['failure_path' => $this->options['failure_path']]); - - $this->logError($request); - - $request->getSession()->set(Security::AUTHENTICATION_ERROR, $exception); - - return $this->httpUtils->createRedirectResponse($request, $this->options['failure_path']); - } - - /** - * Log error information about fialure. - * - * @param Request $request - */ - private function logError(Request $request) - { - $this->logger->error('Authentication failure for user "'.$request->request->get('_username').'", from IP "'.$request->getClientIp().'", with UA: "'.$request->server->get('HTTP_USER_AGENT').'".'); - } -} -- cgit v1.2.3 From f808b01692a835673f328d7221ba8c212caa9b61 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Sat, 1 Jul 2017 09:52:38 +0200 Subject: Add a real configuration for CS-Fixer --- .../UserBundle/Controller/ManageController.php | 48 +++++++++++----------- .../DependencyInjection/WallabagUserExtension.php | 6 +-- src/Wallabag/UserBundle/Entity/User.php | 36 ++++++++-------- .../AuthenticationFailureListener.php | 2 +- .../EventListener/PasswordResettingListener.php | 2 +- src/Wallabag/UserBundle/Form/UserType.php | 10 ++--- src/Wallabag/UserBundle/Mailer/AuthCodeMailer.php | 2 +- .../UserBundle/Repository/UserRepository.php | 2 +- 8 files changed, 54 insertions(+), 54 deletions(-) (limited to 'src/Wallabag/UserBundle') diff --git a/src/Wallabag/UserBundle/Controller/ManageController.php b/src/Wallabag/UserBundle/Controller/ManageController.php index 084f2c67..f3de656f 100644 --- a/src/Wallabag/UserBundle/Controller/ManageController.php +++ b/src/Wallabag/UserBundle/Controller/ManageController.php @@ -7,10 +7,10 @@ use FOS\UserBundle\FOSUserEvents; use Pagerfanta\Adapter\DoctrineORMAdapter; use Pagerfanta\Exception\OutOfRangeCurrentPageException; use Pagerfanta\Pagerfanta; -use Symfony\Component\HttpFoundation\Request; -use Symfony\Bundle\FrameworkBundle\Controller\Controller; use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method; use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; +use Symfony\Bundle\FrameworkBundle\Controller\Controller; +use Symfony\Component\HttpFoundation\Request; use Wallabag\UserBundle\Entity\User; use Wallabag\UserBundle\Form\SearchUserType; @@ -48,13 +48,13 @@ class ManageController extends Controller $this->get('translator')->trans('flashes.user.notice.added', ['%username%' => $user->getUsername()]) ); - return $this->redirectToRoute('user_edit', array('id' => $user->getId())); + return $this->redirectToRoute('user_edit', ['id' => $user->getId()]); } - return $this->render('WallabagUserBundle:Manage:new.html.twig', array( + return $this->render('WallabagUserBundle:Manage:new.html.twig', [ 'user' => $user, 'form' => $form->createView(), - )); + ]); } /** @@ -79,15 +79,15 @@ class ManageController extends Controller $this->get('translator')->trans('flashes.user.notice.updated', ['%username%' => $user->getUsername()]) ); - return $this->redirectToRoute('user_edit', array('id' => $user->getId())); + return $this->redirectToRoute('user_edit', ['id' => $user->getId()]); } - return $this->render('WallabagUserBundle:Manage:edit.html.twig', array( + return $this->render('WallabagUserBundle:Manage:edit.html.twig', [ 'user' => $user, 'edit_form' => $editForm->createView(), 'delete_form' => $deleteForm->createView(), 'twofactor_auth' => $this->getParameter('twofactor_auth'), - )); + ]); } /** @@ -115,22 +115,6 @@ class ManageController extends Controller return $this->redirectToRoute('user_index'); } - /** - * Creates a form to delete a User entity. - * - * @param User $user The User entity - * - * @return \Symfony\Component\Form\Form The form - */ - private function createDeleteForm(User $user) - { - return $this->createFormBuilder() - ->setAction($this->generateUrl('user_delete', array('id' => $user->getId()))) - ->setMethod('DELETE') - ->getForm() - ; - } - /** * @param Request $request * @param int $page @@ -175,4 +159,20 @@ class ManageController extends Controller 'users' => $pagerFanta, ]); } + + /** + * Creates a form to delete a User entity. + * + * @param User $user The User entity + * + * @return \Symfony\Component\Form\Form The form + */ + private function createDeleteForm(User $user) + { + return $this->createFormBuilder() + ->setAction($this->generateUrl('user_delete', ['id' => $user->getId()])) + ->setMethod('DELETE') + ->getForm() + ; + } } diff --git a/src/Wallabag/UserBundle/DependencyInjection/WallabagUserExtension.php b/src/Wallabag/UserBundle/DependencyInjection/WallabagUserExtension.php index 99040f69..5ca3482e 100644 --- a/src/Wallabag/UserBundle/DependencyInjection/WallabagUserExtension.php +++ b/src/Wallabag/UserBundle/DependencyInjection/WallabagUserExtension.php @@ -2,10 +2,10 @@ namespace Wallabag\UserBundle\DependencyInjection; -use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\Config\FileLocator; -use Symfony\Component\HttpKernel\DependencyInjection\Extension; +use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Loader; +use Symfony\Component\HttpKernel\DependencyInjection\Extension; class WallabagUserExtension extends Extension { @@ -14,7 +14,7 @@ class WallabagUserExtension extends Extension $configuration = new Configuration(); $config = $this->processConfiguration($configuration, $configs); - $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); + $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config')); $loader->load('services.yml'); $container->setParameter('wallabag_user.registration_enabled', $config['registration_enabled']); } diff --git a/src/Wallabag/UserBundle/Entity/User.php b/src/Wallabag/UserBundle/Entity/User.php index aba76ca7..20aca298 100644 --- a/src/Wallabag/UserBundle/Entity/User.php +++ b/src/Wallabag/UserBundle/Entity/User.php @@ -4,12 +4,12 @@ namespace Wallabag\UserBundle\Entity; use Doctrine\Common\Collections\ArrayCollection; use Doctrine\ORM\Mapping as ORM; +use FOS\UserBundle\Model\User as BaseUser; +use JMS\Serializer\Annotation\Accessor; use JMS\Serializer\Annotation\Groups; use JMS\Serializer\Annotation\XmlRoot; -use JMS\Serializer\Annotation\Accessor; use Scheb\TwoFactorBundle\Model\Email\TwoFactorInterface; use Scheb\TwoFactorBundle\Model\TrustedComputerInterface; -use FOS\UserBundle\Model\User as BaseUser; use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity; use Symfony\Component\Security\Core\User\UserInterface; use Wallabag\ApiBundle\Entity\Client; @@ -93,36 +93,36 @@ class User extends BaseUser implements TwoFactorInterface, TrustedComputerInterf protected $config; /** - * @ORM\Column(type="integer", nullable=true) + * @var ArrayCollection + * + * @ORM\OneToMany(targetEntity="Wallabag\ApiBundle\Entity\Client", mappedBy="user", cascade={"remove"}) */ - private $authCode; + protected $clients; /** - * @var bool + * @see getFirstClient() below * - * @ORM\Column(type="boolean") + * @Groups({"user_api_with_client"}) + * @Accessor(getter="getFirstClient") */ - private $twoFactorAuthentication = false; + protected $default_client; /** - * @ORM\Column(type="json_array", nullable=true) + * @ORM\Column(type="integer", nullable=true) */ - private $trusted; + private $authCode; /** - * @var ArrayCollection + * @var bool * - * @ORM\OneToMany(targetEntity="Wallabag\ApiBundle\Entity\Client", mappedBy="user", cascade={"remove"}) + * @ORM\Column(type="boolean") */ - protected $clients; + private $twoFactorAuthentication = false; /** - * @see getFirstClient() below - * - * @Groups({"user_api_with_client"}) - * @Accessor(getter="getFirstClient") + * @ORM\Column(type="json_array", nullable=true) */ - protected $default_client; + private $trusted; public function __construct() { @@ -137,7 +137,7 @@ class User extends BaseUser implements TwoFactorInterface, TrustedComputerInterf */ public function timestamps() { - if (is_null($this->createdAt)) { + if (null === $this->createdAt) { $this->createdAt = new \DateTime(); } diff --git a/src/Wallabag/UserBundle/EventListener/AuthenticationFailureListener.php b/src/Wallabag/UserBundle/EventListener/AuthenticationFailureListener.php index 10f13233..18f14a3a 100644 --- a/src/Wallabag/UserBundle/EventListener/AuthenticationFailureListener.php +++ b/src/Wallabag/UserBundle/EventListener/AuthenticationFailureListener.php @@ -35,6 +35,6 @@ class AuthenticationFailureListener implements EventSubscriberInterface { $request = $this->requestStack->getMasterRequest(); - $this->logger->error('Authentication failure for user "'.$request->request->get('_username').'", from IP "'.$request->getClientIp().'", with UA: "'.$request->server->get('HTTP_USER_AGENT').'".'); + $this->logger->error('Authentication failure for user "' . $request->request->get('_username') . '", from IP "' . $request->getClientIp() . '", with UA: "' . $request->server->get('HTTP_USER_AGENT') . '".'); } } diff --git a/src/Wallabag/UserBundle/EventListener/PasswordResettingListener.php b/src/Wallabag/UserBundle/EventListener/PasswordResettingListener.php index 3a7f2637..7df093f1 100644 --- a/src/Wallabag/UserBundle/EventListener/PasswordResettingListener.php +++ b/src/Wallabag/UserBundle/EventListener/PasswordResettingListener.php @@ -2,8 +2,8 @@ namespace Wallabag\UserBundle\EventListener; -use FOS\UserBundle\FOSUserEvents; use FOS\UserBundle\Event\FormEvent; +use FOS\UserBundle\FOSUserEvents; use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Symfony\Component\HttpFoundation\RedirectResponse; use Symfony\Component\Routing\Generator\UrlGeneratorInterface; diff --git a/src/Wallabag/UserBundle/Form/UserType.php b/src/Wallabag/UserBundle/Form/UserType.php index d8cdbaf9..56fea640 100644 --- a/src/Wallabag/UserBundle/Form/UserType.php +++ b/src/Wallabag/UserBundle/Form/UserType.php @@ -3,12 +3,12 @@ namespace Wallabag\UserBundle\Form; use Symfony\Component\Form\AbstractType; -use Symfony\Component\Form\FormBuilderInterface; -use Symfony\Component\OptionsResolver\OptionsResolver; use Symfony\Component\Form\Extension\Core\Type\CheckboxType; +use Symfony\Component\Form\Extension\Core\Type\EmailType; use Symfony\Component\Form\Extension\Core\Type\SubmitType; use Symfony\Component\Form\Extension\Core\Type\TextType; -use Symfony\Component\Form\Extension\Core\Type\EmailType; +use Symfony\Component\Form\FormBuilderInterface; +use Symfony\Component\OptionsResolver\OptionsResolver; class UserType extends AbstractType { @@ -50,8 +50,8 @@ class UserType extends AbstractType */ public function configureOptions(OptionsResolver $resolver) { - $resolver->setDefaults(array( + $resolver->setDefaults([ 'data_class' => 'Wallabag\UserBundle\Entity\User', - )); + ]); } } diff --git a/src/Wallabag/UserBundle/Mailer/AuthCodeMailer.php b/src/Wallabag/UserBundle/Mailer/AuthCodeMailer.php index 961208f2..aed805c9 100644 --- a/src/Wallabag/UserBundle/Mailer/AuthCodeMailer.php +++ b/src/Wallabag/UserBundle/Mailer/AuthCodeMailer.php @@ -2,8 +2,8 @@ namespace Wallabag\UserBundle\Mailer; -use Scheb\TwoFactorBundle\Model\Email\TwoFactorInterface; use Scheb\TwoFactorBundle\Mailer\AuthCodeMailerInterface; +use Scheb\TwoFactorBundle\Model\Email\TwoFactorInterface; /** * Custom mailer for TwoFactorBundle email. diff --git a/src/Wallabag/UserBundle/Repository/UserRepository.php b/src/Wallabag/UserBundle/Repository/UserRepository.php index 6adbe329..b1d753d2 100644 --- a/src/Wallabag/UserBundle/Repository/UserRepository.php +++ b/src/Wallabag/UserBundle/Repository/UserRepository.php @@ -63,6 +63,6 @@ class UserRepository extends EntityRepository public function getQueryBuilderForSearch($term) { return $this->createQueryBuilder('u') - ->andWhere('lower(u.username) LIKE lower(:term) OR lower(u.email) LIKE lower(:term) OR lower(u.name) LIKE lower(:term)')->setParameter('term', '%'.$term.'%'); + ->andWhere('lower(u.username) LIKE lower(:term) OR lower(u.email) LIKE lower(:term) OR lower(u.name) LIKE lower(:term)')->setParameter('term', '%' . $term . '%'); } } -- cgit v1.2.3 From 9114615adcee0255273c7e91d6d8e55f57fc3d6f Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Sat, 1 Jul 2017 09:32:13 +0200 Subject: Fixed mapping entities There were this error in the console: > The association Wallabag\CoreBundle\Entity\SiteCredential#user refers to the inverse side field Wallabag\UserBundle\Entity\User#site_credentials which does not exist. --- src/Wallabag/UserBundle/Entity/User.php | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'src/Wallabag/UserBundle') diff --git a/src/Wallabag/UserBundle/Entity/User.php b/src/Wallabag/UserBundle/Entity/User.php index 20aca298..a3320bbc 100644 --- a/src/Wallabag/UserBundle/Entity/User.php +++ b/src/Wallabag/UserBundle/Entity/User.php @@ -92,6 +92,13 @@ class User extends BaseUser implements TwoFactorInterface, TrustedComputerInterf */ protected $config; + /** + * @var ArrayCollection + * + * @ORM\OneToMany(targetEntity="Wallabag\CoreBundle\Entity\SiteCredential", mappedBy="user", cascade={"remove"}) + */ + protected $site_credentials; + /** * @var ArrayCollection * -- cgit v1.2.3 From e50d7d31c0746ffbfe69065258981e1b4dcd203b Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Mon, 3 Jul 2017 11:49:46 +0200 Subject: CS --- src/Wallabag/UserBundle/Entity/User.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/Wallabag/UserBundle') diff --git a/src/Wallabag/UserBundle/Entity/User.php b/src/Wallabag/UserBundle/Entity/User.php index a3320bbc..53c327f9 100644 --- a/src/Wallabag/UserBundle/Entity/User.php +++ b/src/Wallabag/UserBundle/Entity/User.php @@ -97,7 +97,7 @@ class User extends BaseUser implements TwoFactorInterface, TrustedComputerInterf * * @ORM\OneToMany(targetEntity="Wallabag\CoreBundle\Entity\SiteCredential", mappedBy="user", cascade={"remove"}) */ - protected $site_credentials; + protected $siteCredentials; /** * @var ArrayCollection -- cgit v1.2.3 From 927c9e796ff6fad2bf82a965234f52932cdee657 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Thu, 6 Jul 2017 09:00:37 +0200 Subject: Add EntityTimestampsTrait to handle dates Refactorize timestamps() method to avoid re-writing it on each entity --- src/Wallabag/UserBundle/Entity/User.php | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) (limited to 'src/Wallabag/UserBundle') diff --git a/src/Wallabag/UserBundle/Entity/User.php b/src/Wallabag/UserBundle/Entity/User.php index 53c327f9..48446e3c 100644 --- a/src/Wallabag/UserBundle/Entity/User.php +++ b/src/Wallabag/UserBundle/Entity/User.php @@ -15,6 +15,7 @@ use Symfony\Component\Security\Core\User\UserInterface; use Wallabag\ApiBundle\Entity\Client; use Wallabag\CoreBundle\Entity\Config; use Wallabag\CoreBundle\Entity\Entry; +use Wallabag\CoreBundle\Helper\EntityTimestampsTrait; /** * User. @@ -29,6 +30,8 @@ use Wallabag\CoreBundle\Entity\Entry; */ class User extends BaseUser implements TwoFactorInterface, TrustedComputerInterface { + use EntityTimestampsTrait; + /** @Serializer\XmlAttribute */ /** * @var int @@ -138,19 +141,6 @@ class User extends BaseUser implements TwoFactorInterface, TrustedComputerInterf $this->roles = ['ROLE_USER']; } - /** - * @ORM\PrePersist - * @ORM\PreUpdate - */ - public function timestamps() - { - if (null === $this->createdAt) { - $this->createdAt = new \DateTime(); - } - - $this->updatedAt = new \DateTime(); - } - /** * Set name. * -- cgit v1.2.3 From 52b84c11a5b5474cd45271d937a46c6adfdf2749 Mon Sep 17 00:00:00 2001 From: Nicolas Hart Date: Sat, 29 Jul 2017 22:51:50 +0200 Subject: Fix some namespaces and phpdoc --- src/Wallabag/UserBundle/Repository/UserRepository.php | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/Wallabag/UserBundle') diff --git a/src/Wallabag/UserBundle/Repository/UserRepository.php b/src/Wallabag/UserBundle/Repository/UserRepository.php index b1d753d2..75cbeef2 100644 --- a/src/Wallabag/UserBundle/Repository/UserRepository.php +++ b/src/Wallabag/UserBundle/Repository/UserRepository.php @@ -3,6 +3,8 @@ namespace Wallabag\UserBundle\Repository; use Doctrine\ORM\EntityRepository; +use Doctrine\ORM\QueryBuilder; +use Wallabag\UserBundle\Entity\User; class UserRepository extends EntityRepository { -- cgit v1.2.3 From f7a4b441361404b378c30b7788b3699c208537ad Mon Sep 17 00:00:00 2001 From: Nicolas Hart Date: Mon, 31 Jul 2017 23:20:41 +0200 Subject: add search argument and limit option to list users command --- src/Wallabag/UserBundle/Repository/UserRepository.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'src/Wallabag/UserBundle') diff --git a/src/Wallabag/UserBundle/Repository/UserRepository.php b/src/Wallabag/UserBundle/Repository/UserRepository.php index 75cbeef2..be693d3b 100644 --- a/src/Wallabag/UserBundle/Repository/UserRepository.php +++ b/src/Wallabag/UserBundle/Repository/UserRepository.php @@ -55,6 +55,19 @@ class UserRepository extends EntityRepository ->getSingleScalarResult(); } + /** + * Count how many users are existing. + * + * @return int + */ + public function getSumUsers() + { + return $this->createQueryBuilder('u') + ->select('count(u)') + ->getQuery() + ->getSingleScalarResult(); + } + /** * Retrieves users filtered with a search term. * -- cgit v1.2.3 From 162740b79827cb8c83d53be838188110d4d69240 Mon Sep 17 00:00:00 2001 From: Quent-in Date: Sat, 5 Aug 2017 15:19:34 +0200 Subject: Update MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 2FA : choix des occitanophones interrogés : autentificacion en dos temps. + fautes de frappes --- src/Wallabag/UserBundle/Resources/translations/wallabag_user.oc.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/Wallabag/UserBundle') diff --git a/src/Wallabag/UserBundle/Resources/translations/wallabag_user.oc.yml b/src/Wallabag/UserBundle/Resources/translations/wallabag_user.oc.yml index 53a1afd1..cebf8f28 100644 --- a/src/Wallabag/UserBundle/Resources/translations/wallabag_user.oc.yml +++ b/src/Wallabag/UserBundle/Resources/translations/wallabag_user.oc.yml @@ -5,7 +5,7 @@ auth_code: subject: "Còdi d'autentificacion wallabag" body: hello: "Bonjorn %user%," - first_para: "Estant qu'avètz activat la dobla autentificacion sus vòtre compte wallabag e que venètz de vos conectar dempuèi un novèl aparelh (ordinador, mobil, etc.) vos mandem un còdi per validar la connexion." - second_para: "Vaquí lo còdi a dintrar :" - support: "S'avètz un problèma de connexion, dobtetz pas a contacter l'assisténcia : " + first_para: "Estant qu'avètz activat l'autentificacion en dos temps sus vòstre compte wallabag e que venètz de vos connectar dempuèi un novèl periferic (ordinador, mobil, etc.) vos mandem un còdi per validar la connexion." + second_para: "Vaquí lo còdi per dintrar :" + support: "S'avètz un problèma de connexion, dobtetz pas a contactar l'assisténcia : " signature: "La còla de wallabag" -- cgit v1.2.3 From 442147d92345ba9e6ba09bd762a5a1941de473d5 Mon Sep 17 00:00:00 2001 From: Quent-in Date: Wed, 30 Aug 2017 20:10:58 +0200 Subject: Update wallabag_user.oc.yml --- src/Wallabag/UserBundle/Resources/translations/wallabag_user.oc.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/Wallabag/UserBundle') diff --git a/src/Wallabag/UserBundle/Resources/translations/wallabag_user.oc.yml b/src/Wallabag/UserBundle/Resources/translations/wallabag_user.oc.yml index cebf8f28..e62ea2bc 100644 --- a/src/Wallabag/UserBundle/Resources/translations/wallabag_user.oc.yml +++ b/src/Wallabag/UserBundle/Resources/translations/wallabag_user.oc.yml @@ -6,6 +6,6 @@ auth_code: body: hello: "Bonjorn %user%," first_para: "Estant qu'avètz activat l'autentificacion en dos temps sus vòstre compte wallabag e que venètz de vos connectar dempuèi un novèl periferic (ordinador, mobil, etc.) vos mandem un còdi per validar la connexion." - second_para: "Vaquí lo còdi per dintrar :" - support: "S'avètz un problèma de connexion, dobtetz pas a contactar l'assisténcia : " + second_para: "Vaquí lo còdi per dintrar : " + support: "S'avètz un problèma de connexion, dobtetz pas a contactar l'assisténcia : " signature: "La còla de wallabag" -- cgit v1.2.3 From ef5fcdee20bc2c9915f59065fc738bc10f95f003 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9E=D0=BB=D0=B5=D0=B3?= Date: Fri, 6 Oct 2017 15:39:34 +0300 Subject: add Russian language --- .../UserBundle/Resources/translations/wallabag_user.ru.yml | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 src/Wallabag/UserBundle/Resources/translations/wallabag_user.ru.yml (limited to 'src/Wallabag/UserBundle') diff --git a/src/Wallabag/UserBundle/Resources/translations/wallabag_user.ru.yml b/src/Wallabag/UserBundle/Resources/translations/wallabag_user.ru.yml new file mode 100644 index 00000000..2a418224 --- /dev/null +++ b/src/Wallabag/UserBundle/Resources/translations/wallabag_user.ru.yml @@ -0,0 +1,11 @@ +# Two factor mail +auth_code: + on: 'Вкл' + mailer: + subject: 'код аутентификации wallabag' + body: + hello: "Привет %user%," + first_para: "Поскольку вы активируете двухфакторную аутентификацию на своей учетной записи wallabag и только что вошли в систему с нового устройства (компьютер, телефон и т. д.), мы отправляем вам код для подтверждения вашего соединения." + second_para: "Вот код:" + support: "Пожалуйста, не стесняйтесь обращаться к нам, если у вас есть какие-либо проблемы:" + signature: "Команда wallabag" -- cgit v1.2.3