]> git.immae.eu Git - github/wallabag/wallabag.git/commitdiff
getSalt method
authorNicolas Lœuillet <nicolas@loeuillet.org>
Tue, 10 Feb 2015 07:35:43 +0000 (08:35 +0100)
committerNicolas Lœuillet <nicolas@loeuillet.org>
Tue, 10 Feb 2015 07:35:43 +0000 (08:35 +0100)
app/config/routing.yml
app/config/security.yml
src/Wallabag/CoreBundle/Controller/WallabagRestController.php

index 426dcdcfe8aff3c92f507c0dc196800e7d536ae7..20f6979a642de69fb50511f793c157e51f9cbd92 100644 (file)
@@ -18,11 +18,6 @@ login_check:
 logout:
     path:   /logout
 
-#wallabag_api:
-#    resource: "@WallabagApiBundle/Controller/"
-#    type:     annotation
-#    prefix:   /api
-
 rest :
   type : rest
   resource : "routing_rest.yml"
index 4a798e56fb16be9dfaeb27e4bf500bb4d5f8a343..e06c89672aa7712552ece39759c35ec2034aa5ad 100644 (file)
@@ -56,6 +56,7 @@ security:
                 target: /
 
     access_control:
+        - { path: ^/api/salt, roles: IS_AUTHENTICATED_ANONYMOUSLY }
         - { path: ^/api/doc, roles: IS_AUTHENTICATED_ANONYMOUSLY }
         - { path: ^/login, roles: IS_AUTHENTICATED_ANONYMOUSLY }
         - { path: ^/, roles: ROLE_USER }
index 75e5204e4fab4876e544b95dfbab678eac90485d..96d2529a43c7251c0c1d0dd0ba04b6644ef4a740 100644 (file)
@@ -8,10 +8,34 @@ use Symfony\Component\HttpFoundation\Request;
 use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
 use Wallabag\CoreBundle\Entity\Entry;
 use Wallabag\CoreBundle\Entity\Tags;
+use Wallabag\CoreBundle\Entity\User;
 use Wallabag\CoreBundle\Service\Extractor;
 
 class WallabagRestController extends Controller
 {
+    /**
+     * Retrieve salt for a giver user.
+     *
+     * @ApiDoc(
+     *       parameters={
+     *          {"name"="username", "dataType"="string", "required"=true, "description"="username"}
+     *       }
+     * )
+     * @return string
+     */
+    public function getSaltAction($username)
+    {
+        $user = $this
+            ->getDoctrine()
+            ->getRepository('WallabagCoreBundle:User')
+            ->findOneByUsername($username);
+
+        if (is_null($user)) {
+            throw $this->createNotFoundException();
+        }
+
+        return $user->getSalt();
+    }
     /**
      * Retrieve all entries. It could be filtered by many options.
      *
@@ -85,8 +109,7 @@ class WallabagRestController extends Controller
         $url = $request->request->get('url');
 
         $content = Extractor::extract($url);
-        $entry = new Entry();
-        $entry->setUserId($this->getUser()->getId());
+        $entry = new Entry($this->getUser()->getId());
         $entry->setUrl($url);
         $entry->setTitle($request->request->get('title') ?: $content->getTitle());
         $entry->setContent($content->getBody());