From f92fcb53ca78cc8822962e676b0db117e1a08aa5 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Sun, 4 Dec 2016 13:51:58 +0100 Subject: Add CRUD for site credentials --- app/DoctrineMigrations/Version20161204115751.php | 56 ++++++ .../Controller/SiteCredentialController.php | 138 +++++++++++++++ src/Wallabag/CoreBundle/Entity/SiteCredential.php | 197 +++++++++++++++++++++ .../CoreBundle/Form/Type/SiteCredentialType.php | 43 +++++ .../Repository/SiteCredentialRepository.php | 13 ++ .../Resources/translations/messages.da.yml | 25 +++ .../Resources/translations/messages.de.yml | 25 +++ .../Resources/translations/messages.en.yml | 25 +++ .../Resources/translations/messages.es.yml | 25 +++ .../Resources/translations/messages.fa.yml | 25 +++ .../Resources/translations/messages.fr.yml | 31 +++- .../Resources/translations/messages.it.yml | 25 +++ .../Resources/translations/messages.oc.yml | 25 +++ .../Resources/translations/messages.pl.yml | 25 +++ .../Resources/translations/messages.pt.yml | 25 +++ .../Resources/translations/messages.ro.yml | 25 +++ .../Resources/translations/messages.tr.yml | 5 + .../themes/baggy/SiteCredential/edit.html.twig | 60 +++++++ .../themes/baggy/SiteCredential/index.html.twig | 44 +++++ .../themes/baggy/SiteCredential/new.html.twig | 53 ++++++ .../views/themes/material/Config/index.html.twig | 20 +-- .../themes/material/SiteCredential/edit.html.twig | 60 +++++++ .../themes/material/SiteCredential/index.html.twig | 44 +++++ .../themes/material/SiteCredential/new.html.twig | 53 ++++++ 24 files changed, 1054 insertions(+), 13 deletions(-) create mode 100644 app/DoctrineMigrations/Version20161204115751.php create mode 100644 src/Wallabag/CoreBundle/Controller/SiteCredentialController.php create mode 100644 src/Wallabag/CoreBundle/Entity/SiteCredential.php create mode 100644 src/Wallabag/CoreBundle/Form/Type/SiteCredentialType.php create mode 100644 src/Wallabag/CoreBundle/Repository/SiteCredentialRepository.php create mode 100644 src/Wallabag/CoreBundle/Resources/views/themes/baggy/SiteCredential/edit.html.twig create mode 100644 src/Wallabag/CoreBundle/Resources/views/themes/baggy/SiteCredential/index.html.twig create mode 100644 src/Wallabag/CoreBundle/Resources/views/themes/baggy/SiteCredential/new.html.twig create mode 100644 src/Wallabag/CoreBundle/Resources/views/themes/material/SiteCredential/edit.html.twig create mode 100644 src/Wallabag/CoreBundle/Resources/views/themes/material/SiteCredential/index.html.twig create mode 100644 src/Wallabag/CoreBundle/Resources/views/themes/material/SiteCredential/new.html.twig diff --git a/app/DoctrineMigrations/Version20161204115751.php b/app/DoctrineMigrations/Version20161204115751.php new file mode 100644 index 00000000..97635fa7 --- /dev/null +++ b/app/DoctrineMigrations/Version20161204115751.php @@ -0,0 +1,56 @@ +container = $container; + } + + private function getTable($tableName) + { + return $this->container->getParameter('database_table_prefix').$tableName; + } + + /** + * @param Schema $schema + */ + public function up(Schema $schema) + { + $this->skipIf($schema->hasTable($this->getTable('site_credential')), 'It seems that you already played this migration.'); + + $table = $schema->createTable($this->getTable('site_credential')); + $table->addColumn('id', 'integer', ['autoincrement' => true]); + $table->addColumn('user_id', 'integer'); + $table->addColumn('host', 'string', ['length' => 255]); + $table->addColumn('username', 'string', ['length' => 255]); + $table->addColumn('password', 'string', ['length' => 255]); + $table->addColumn('createdAt', 'datetime'); + $table->addIndex(['user_id'], 'idx_user'); + $table->setPrimaryKey(['id']); + $table->addForeignKeyConstraint($this->getTable('user'), ['user_id'], ['id'], [], 'fk_user'); + } + + /** + * @param Schema $schema + */ + public function down(Schema $schema) + { + $schema->dropTable($this->getTable('site_credential')); + } +} diff --git a/src/Wallabag/CoreBundle/Controller/SiteCredentialController.php b/src/Wallabag/CoreBundle/Controller/SiteCredentialController.php new file mode 100644 index 00000000..e7e43800 --- /dev/null +++ b/src/Wallabag/CoreBundle/Controller/SiteCredentialController.php @@ -0,0 +1,138 @@ +getDoctrine()->getManager(); + + $credentials = $em->getRepository('WallabagCoreBundle:SiteCredential')->findAll(); + + return $this->render('WallabagCoreBundle:SiteCredential:index.html.twig', array( + 'credentials' => $credentials, + )); + } + + /** + * Creates a new site credential entity. + * + * @Route("/site-credential/new", name="site_credential_new") + * @Method({"GET", "POST"}) + */ + public function newAction(Request $request) + { + $credential = new SiteCredential($this->getUser()); + + $form = $this->createForm('Wallabag\CoreBundle\Form\Type\SiteCredentialType', $credential); + $form->handleRequest($request); + + if ($form->isSubmitted() && $form->isValid()) { + $em = $this->getDoctrine()->getManager(); + $em->persist($credential); + $em->flush($credential); + + $this->get('session')->getFlashBag()->add( + 'notice', + $this->get('translator')->trans('flashes.site_credential.notice.added', ['%host%' => $credential->getHost()]) + ); + + return $this->redirectToRoute('site_credential_edit', array('id' => $credential->getId())); + } + + return $this->render('WallabagCoreBundle:SiteCredential:new.html.twig', array( + 'credential' => $credential, + 'form' => $form->createView(), + )); + } + + /** + * Displays a form to edit an existing site credential entity. + * + * @Route("/site-credential/{id}/edit", name="site_credential_edit") + * @Method({"GET", "POST"}) + */ + public function editAction(Request $request, SiteCredential $siteCredential) + { + $deleteForm = $this->createDeleteForm($siteCredential); + $editForm = $this->createForm('Wallabag\CoreBundle\Form\Type\SiteCredentialType', $siteCredential); + $editForm->handleRequest($request); + + if ($editForm->isSubmitted() && $editForm->isValid()) { + $em = $this->getDoctrine()->getManager(); + $em->persist($siteCredential); + $em->flush(); + + $this->get('session')->getFlashBag()->add( + 'notice', + $this->get('translator')->trans('flashes.site_credential.notice.updated', ['%host%' => $siteCredential->getHost()]) + ); + + return $this->redirectToRoute('site_credential_edit', array('id' => $siteCredential->getId())); + } + + return $this->render('WallabagCoreBundle:SiteCredential:edit.html.twig', array( + 'credential' => $siteCredential, + 'edit_form' => $editForm->createView(), + 'delete_form' => $deleteForm->createView(), + )); + } + + /** + * Deletes a site credential entity. + * + * @Route("/site-credential/{id}", name="site_credential_delete") + * @Method("DELETE") + */ + public function deleteAction(Request $request, SiteCredential $siteCredential) + { + $form = $this->createDeleteForm($siteCredential); + $form->handleRequest($request); + + if ($form->isSubmitted() && $form->isValid()) { + $this->get('session')->getFlashBag()->add( + 'notice', + $this->get('translator')->trans('flashes.site_credential.notice.deleted', ['%host%' => $siteCredential->getHost()]) + ); + + $em = $this->getDoctrine()->getManager(); + $em->remove($siteCredential); + $em->flush(); + } + + return $this->redirectToRoute('site_credential_index'); + } + + /** + * Creates a form to delete a site credential entity. + * + * @param SiteCredential $siteCredential The site credential entity + * + * @return \Symfony\Component\Form\Form The form + */ + private function createDeleteForm(SiteCredential $siteCredential) + { + return $this->createFormBuilder() + ->setAction($this->generateUrl('site_credential_delete', array('id' => $siteCredential->getId()))) + ->setMethod('DELETE') + ->getForm() + ; + } +} diff --git a/src/Wallabag/CoreBundle/Entity/SiteCredential.php b/src/Wallabag/CoreBundle/Entity/SiteCredential.php new file mode 100644 index 00000000..85ee07d4 --- /dev/null +++ b/src/Wallabag/CoreBundle/Entity/SiteCredential.php @@ -0,0 +1,197 @@ +user = $user; + } + + /** + * Get id. + * + * @return int + */ + public function getId() + { + return $this->id; + } + + /** + * Set host. + * + * @param string $host + * + * @return SiteCredential + */ + public function setHost($host) + { + $this->host = $host; + + return $this; + } + + /** + * Get host. + * + * @return string + */ + public function getHost() + { + return $this->host; + } + + /** + * Set username. + * + * @param string $username + * + * @return SiteCredential + */ + public function setUsername($username) + { + $this->username = $username; + + return $this; + } + + /** + * Get username. + * + * @return string + */ + public function getUsername() + { + return $this->username; + } + + /** + * Set password. + * + * @param string $password + * + * @return SiteCredential + */ + public function setPassword($password) + { + $this->password = $password; + + return $this; + } + + /** + * Get password. + * + * @return string + */ + public function getPassword() + { + return $this->password; + } + + /** + * Set createdAt. + * + * @param \DateTime $createdAt + * + * @return SiteCredential + */ + public function setCreatedAt($createdAt) + { + $this->createdAt = $createdAt; + + return $this; + } + + /** + * Get createdAt. + * + * @return \DateTime + */ + public function getCreatedAt() + { + return $this->createdAt; + } + + /** + * @return User + */ + public function getUser() + { + return $this->user; + } + + /** + * @ORM\PrePersist + */ + public function timestamps() + { + if (is_null($this->createdAt)) { + $this->createdAt = new \DateTime(); + } + } +} diff --git a/src/Wallabag/CoreBundle/Form/Type/SiteCredentialType.php b/src/Wallabag/CoreBundle/Form/Type/SiteCredentialType.php new file mode 100644 index 00000000..9db7c155 --- /dev/null +++ b/src/Wallabag/CoreBundle/Form/Type/SiteCredentialType.php @@ -0,0 +1,43 @@ +add('host', TextType::class, [ + 'label' => 'site_credential.form.host_label', + ]) + ->add('username', TextType::class, [ + 'label' => 'site_credential.form.username_label', + ]) + ->add('password', PasswordType::class, [ + 'label' => 'site_credential.form.password_label', + ]) + ->add('save', SubmitType::class, [ + 'label' => 'config.form.save', + ]) + ; + } + + public function configureOptions(OptionsResolver $resolver) + { + $resolver->setDefaults([ + 'data_class' => 'Wallabag\CoreBundle\Entity\SiteCredential', + ]); + } + + public function getBlockPrefix() + { + return 'site_credential'; + } +} diff --git a/src/Wallabag/CoreBundle/Repository/SiteCredentialRepository.php b/src/Wallabag/CoreBundle/Repository/SiteCredentialRepository.php new file mode 100644 index 00000000..501b4439 --- /dev/null +++ b/src/Wallabag/CoreBundle/Repository/SiteCredentialRepository.php @@ -0,0 +1,13 @@ + +
+
+
+
+

{{ 'site_credential.edit_site_credential'|trans }}

+ +
+ {{ form_start(edit_form) }} + {{ form_errors(edit_form) }} + +
+
+ {{ form_label(edit_form.host) }} + {{ form_errors(edit_form.host) }} + {{ form_widget(edit_form.host) }} +
+
+ +
+
+ {{ form_label(edit_form.username) }} + {{ form_errors(edit_form.username) }} + {{ form_widget(edit_form.username) }} +
+
+ +
+
+ {{ form_label(edit_form.password) }} + {{ form_errors(edit_form.password) }} + {{ form_widget(edit_form.password) }} +
+
+ +
+ + {{ form_widget(edit_form.save, {'attr': {'class': 'btn waves-effect waves-light'}}) }} + {{ form_widget(edit_form._token) }} + +

+ {{ form_start(delete_form) }} + + {{ form_end(delete_form) }} +

+

{{ 'site_credential.form.back_to_list'|trans }}

+
+
+
+
+
+ + +{% endblock %} diff --git a/src/Wallabag/CoreBundle/Resources/views/themes/baggy/SiteCredential/index.html.twig b/src/Wallabag/CoreBundle/Resources/views/themes/baggy/SiteCredential/index.html.twig new file mode 100644 index 00000000..fda60b31 --- /dev/null +++ b/src/Wallabag/CoreBundle/Resources/views/themes/baggy/SiteCredential/index.html.twig @@ -0,0 +1,44 @@ +{% extends "WallabagCoreBundle::layout.html.twig" %} + +{% block title %}{{ 'site_credential.page_title'|trans }}{% endblock %} + +{% block content %} + +
+
+
+
+
+

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

+ + + + + + + + + + + {% for credential in credentials %} + + + + + + {% endfor %} + +
{{ 'site_credential.form.host_label'|trans }}{{ 'site_credential.form.username_label'|trans }}{{ 'site_credential.list.actions'|trans }}
{{ credential.host }}{{ credential.username }} + {{ 'site_credential.list.edit_action'|trans }} +
+
+

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

+
+
+
+
+
+ +{% endblock %} diff --git a/src/Wallabag/CoreBundle/Resources/views/themes/baggy/SiteCredential/new.html.twig b/src/Wallabag/CoreBundle/Resources/views/themes/baggy/SiteCredential/new.html.twig new file mode 100644 index 00000000..bf713902 --- /dev/null +++ b/src/Wallabag/CoreBundle/Resources/views/themes/baggy/SiteCredential/new.html.twig @@ -0,0 +1,53 @@ +{% extends "WallabagCoreBundle::layout.html.twig" %} + +{% block title %}{{ 'site_credential.page_title'|trans }}{% endblock %} + +{% block content %} + +
+
+
+
+
+

{{ 'site_credential.new_site_credential'|trans }}

+ +
+ {{ form_start(form) }} + {{ form_errors(form) }} + +
+
+ {{ form_label(form.host) }} + {{ form_errors(form.host) }} + {{ form_widget(form.host) }} +
+
+ +
+
+ {{ form_label(form.username) }} + {{ form_errors(form.username) }} + {{ form_widget(form.username) }} +
+
+ +
+
+ {{ form_label(form.password) }} + {{ form_errors(form.password) }} + {{ form_widget(form.password) }} +
+
+ + {{ form_widget(form.save, {'attr': {'class': 'btn waves-effect waves-light'}}) }} + {{ form_rest(form) }} + +

{{ 'site_credential.form.back_to_list'|trans }}

+
+
+
+
+
+
+ +{% endblock %} diff --git a/src/Wallabag/CoreBundle/Resources/views/themes/material/Config/index.html.twig b/src/Wallabag/CoreBundle/Resources/views/themes/material/Config/index.html.twig index 9b0816eb..1e10bf38 100644 --- a/src/Wallabag/CoreBundle/Resources/views/themes/material/Config/index.html.twig +++ b/src/Wallabag/CoreBundle/Resources/views/themes/material/Config/index.html.twig @@ -66,13 +66,13 @@ -
-
- {{ form_errors(form.config.action_mark_as_read) }} - {{ form_widget(form.config.action_mark_as_read) }} - {{ form_label(form.config.action_mark_as_read) }} +
+
+ {{ form_label(form.config.action_mark_as_read) }} + {{ form_errors(form.config.action_mark_as_read) }} + {{ form_widget(form.config.action_mark_as_read) }} +
-
@@ -254,11 +254,11 @@ {{ form_start(form.pwd) }} {{ form_errors(form.pwd) }} -
-
- {{ 'config.form_password.description'|trans }} +
+
+ {{ 'config.form_password.description'|trans }} +
-
diff --git a/src/Wallabag/CoreBundle/Resources/views/themes/material/SiteCredential/edit.html.twig b/src/Wallabag/CoreBundle/Resources/views/themes/material/SiteCredential/edit.html.twig new file mode 100644 index 00000000..8448f17e --- /dev/null +++ b/src/Wallabag/CoreBundle/Resources/views/themes/material/SiteCredential/edit.html.twig @@ -0,0 +1,60 @@ +{% extends "WallabagCoreBundle::layout.html.twig" %} + +{% block title %}{{ 'site_credential.page_title'|trans }}{% endblock %} + +{% block content %} + +
+
+
+
+
+

{{ 'site_credential.edit_site_credential'|trans }}

+ +
+ {{ form_start(edit_form) }} + {{ form_errors(edit_form) }} + +
+
+ {{ form_label(edit_form.host) }} + {{ form_errors(edit_form.host) }} + {{ form_widget(edit_form.host) }} +
+
+ +
+
+ {{ form_label(edit_form.username) }} + {{ form_errors(edit_form.username) }} + {{ form_widget(edit_form.username) }} +
+
+ +
+
+ {{ form_label(edit_form.password) }} + {{ form_errors(edit_form.password) }} + {{ form_widget(edit_form.password) }} +
+
+ +
+ + {{ form_widget(edit_form.save, {'attr': {'class': 'btn waves-effect waves-light'}}) }} + {{ form_widget(edit_form._token) }} + +

+ {{ form_start(delete_form) }} + + {{ form_end(delete_form) }} +

+

{{ 'site_credential.form.back_to_list'|trans }}

+
+
+
+
+
+
+ +{% endblock %} diff --git a/src/Wallabag/CoreBundle/Resources/views/themes/material/SiteCredential/index.html.twig b/src/Wallabag/CoreBundle/Resources/views/themes/material/SiteCredential/index.html.twig new file mode 100644 index 00000000..fda60b31 --- /dev/null +++ b/src/Wallabag/CoreBundle/Resources/views/themes/material/SiteCredential/index.html.twig @@ -0,0 +1,44 @@ +{% extends "WallabagCoreBundle::layout.html.twig" %} + +{% block title %}{{ 'site_credential.page_title'|trans }}{% endblock %} + +{% block content %} + +
+
+
+
+
+

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

+ + + + + + + + + + + {% for credential in credentials %} + + + + + + {% endfor %} + +
{{ 'site_credential.form.host_label'|trans }}{{ 'site_credential.form.username_label'|trans }}{{ 'site_credential.list.actions'|trans }}
{{ credential.host }}{{ credential.username }} + {{ 'site_credential.list.edit_action'|trans }} +
+
+

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

+
+
+
+
+
+ +{% endblock %} diff --git a/src/Wallabag/CoreBundle/Resources/views/themes/material/SiteCredential/new.html.twig b/src/Wallabag/CoreBundle/Resources/views/themes/material/SiteCredential/new.html.twig new file mode 100644 index 00000000..bf713902 --- /dev/null +++ b/src/Wallabag/CoreBundle/Resources/views/themes/material/SiteCredential/new.html.twig @@ -0,0 +1,53 @@ +{% extends "WallabagCoreBundle::layout.html.twig" %} + +{% block title %}{{ 'site_credential.page_title'|trans }}{% endblock %} + +{% block content %} + +
+
+
+
+
+

{{ 'site_credential.new_site_credential'|trans }}

+ +
+ {{ form_start(form) }} + {{ form_errors(form) }} + +
+
+ {{ form_label(form.host) }} + {{ form_errors(form.host) }} + {{ form_widget(form.host) }} +
+
+ +
+
+ {{ form_label(form.username) }} + {{ form_errors(form.username) }} + {{ form_widget(form.username) }} +
+
+ +
+
+ {{ form_label(form.password) }} + {{ form_errors(form.password) }} + {{ form_widget(form.password) }} +
+
+ + {{ form_widget(form.save, {'attr': {'class': 'btn waves-effect waves-light'}}) }} + {{ form_rest(form) }} + +

{{ 'site_credential.form.back_to_list'|trans }}

+
+
+
+
+
+
+ +{% endblock %} -- cgit v1.2.3