diff --git a/app/DoctrineMigrations/Version20161204115751.php b/app/DoctrineMigrations/Version20161204115751.php new file mode 100644 index 000000000..97635fa73 --- /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 000000000..e7e438002 --- /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 000000000..85ee07d4a --- /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 000000000..9db7c155d --- /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 000000000..501b44396 --- /dev/null +++ b/src/Wallabag/CoreBundle/Repository/SiteCredentialRepository.php @@ -0,0 +1,13 @@ + +
+ {{ form_start(delete_form) }} + + {{ form_end(delete_form) }} +
+ +{{ 'site_credential.description'|trans|raw }}
+ +{{ '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 }} + | +
+ {{ form_start(delete_form) }} + + {{ form_end(delete_form) }} +
+ +{{ 'site_credential.description'|trans|raw }}
+ +{{ '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 }} + | +