/**
* SiteCredential controller.
+ *
+ * @Route("/site-credentials")
*/
class SiteCredentialController extends Controller
{
/**
* Lists all User entities.
*
- * @Route("/site-credential", name="site_credential_index")
+ * @Route("/", name="site_credentials_index")
* @Method("GET")
*/
public function indexAction()
{
- $em = $this->getDoctrine()->getManager();
-
- $credentials = $em->getRepository('WallabagCoreBundle:SiteCredential')->findAll();
+ $credentials = $this->get('wallabag_core.site_credential_repository')->findByUser($this->getUser());
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")
+ * @Route("/new", name="site_credentials_new")
* @Method({"GET", "POST"})
*/
public function newAction(Request $request)
$this->get('translator')->trans('flashes.site_credential.notice.added', ['%host%' => $credential->getHost()])
);
- return $this->redirectToRoute('site_credential_edit', array('id' => $credential->getId()));
+ return $this->redirectToRoute('site_credentials_edit', array('id' => $credential->getId()));
}
return $this->render('WallabagCoreBundle:SiteCredential:new.html.twig', array(
/**
* Displays a form to edit an existing site credential entity.
*
- * @Route("/site-credential/{id}/edit", name="site_credential_edit")
+ * @Route("/{id}/edit", name="site_credentials_edit")
* @Method({"GET", "POST"})
*/
public function editAction(Request $request, SiteCredential $siteCredential)
{
+ $this->checkUserAction($siteCredential);
+
$deleteForm = $this->createDeleteForm($siteCredential);
$editForm = $this->createForm('Wallabag\CoreBundle\Form\Type\SiteCredentialType', $siteCredential);
$editForm->handleRequest($request);
$this->get('translator')->trans('flashes.site_credential.notice.updated', ['%host%' => $siteCredential->getHost()])
);
- return $this->redirectToRoute('site_credential_edit', array('id' => $siteCredential->getId()));
+ return $this->redirectToRoute('site_credentials_edit', array('id' => $siteCredential->getId()));
}
return $this->render('WallabagCoreBundle:SiteCredential:edit.html.twig', array(
/**
* Deletes a site credential entity.
*
- * @Route("/site-credential/{id}", name="site_credential_delete")
+ * @Route("/{id}", name="site_credentials_delete")
* @Method("DELETE")
*/
public function deleteAction(Request $request, SiteCredential $siteCredential)
{
+ $this->checkUserAction($siteCredential);
+
$form = $this->createDeleteForm($siteCredential);
$form->handleRequest($request);
$em->flush();
}
- return $this->redirectToRoute('site_credential_index');
+ return $this->redirectToRoute('site_credentials_index');
}
/**
private function createDeleteForm(SiteCredential $siteCredential)
{
return $this->createFormBuilder()
- ->setAction($this->generateUrl('site_credential_delete', array('id' => $siteCredential->getId())))
+ ->setAction($this->generateUrl('site_credentials_delete', array('id' => $siteCredential->getId())))
->setMethod('DELETE')
->getForm()
;
}
+
+ /**
+ * Check if the logged user can manage the given site credential.
+ *
+ * @param SiteCredential $siteCredential The site credential entity
+ */
+ private function checkUserAction(SiteCredential $siteCredential)
+ {
+ if (null === $this->getUser() || $this->getUser()->getId() != $siteCredential->getUser()->getId()) {
+ throw $this->createAccessDeniedException('You can not access this site credential.');
+ }
+ }
}