Deleting tokens works (without confirmation)
authorChristian Weiske <cweiske@cweiske.de>
Tue, 7 Oct 2014 05:51:07 +0000 (07:51 +0200)
committerChristian Weiske <cweiske@cweiske.de>
Tue, 7 Oct 2014 05:51:07 +0000 (07:51 +0200)
appinfo/application.php
appinfo/routes.php
controller/guicontroller.php
controller/tokencontroller.php
grauphel.css
templates/tokens.php

index 20325de..66ed557 100644 (file)
@@ -59,6 +59,8 @@ class Application extends App
         $container->registerService(
             'TokenController',
             function($c) {
         $container->registerService(
             'TokenController',
             function($c) {
+                Dependencies::get()->urlGen
+                    = $c->query('ServerContainer')->getURLGenerator();
                 return new \OCA\Grauphel\Controller\TokenController(
                     $c->query('AppName'),
                     $c->query('Request'),
                 return new \OCA\Grauphel\Controller\TokenController(
                     $c->query('AppName'),
                     $c->query('Request'),
index a730583..28ba16d 100644 (file)
@@ -79,6 +79,11 @@ $application->registerRoutes(
                 'name' => 'token#delete',
                 'verb' => 'DELETE',
             ),
                 'name' => 'token#delete',
                 'verb' => 'DELETE',
             ),
+            array(
+                'url'  => '/tokens/{username}/{tokenKey}',
+                'name' => 'token#deletePost',
+                'verb' => 'POST',
+            ),
         )
     )
 );
         )
     )
 );
index 0cb8e91..58768f2 100644 (file)
@@ -111,6 +111,7 @@ class GuiController extends Controller
                     $this->user->getUid(), 'access'
                 ),
                 'client' => new Client(),
                     $this->user->getUid(), 'access'
                 ),
                 'client' => new Client(),
+                'username' => $this->user->getUid(),
             )
         );
         $this->addNavigation($res, null);
             )
         );
         $this->addNavigation($res, null);
index 97d142a..acc9238 100644 (file)
@@ -14,6 +14,7 @@
 namespace OCA\Grauphel\Controller;
 
 use \OCP\AppFramework\Controller;
 namespace OCA\Grauphel\Controller;
 
 use \OCP\AppFramework\Controller;
+use \OCP\AppFramework\Http\RedirectResponse;
 use \OCA\Grauphel\Lib\Dependencies;
 use \OCA\Grauphel\Lib\OAuthException;
 use \OCA\Grauphel\Lib\Response\ErrorResponse;
 use \OCA\Grauphel\Lib\Dependencies;
 use \OCA\Grauphel\Lib\OAuthException;
 use \OCA\Grauphel\Lib\Response\ErrorResponse;
@@ -41,7 +42,8 @@ class TokenController extends Controller
     public function __construct($appName, \OCP\IRequest $request, $user)
     {
         parent::__construct($appName, $request);
     public function __construct($appName, \OCP\IRequest $request, $user)
     {
         parent::__construct($appName, $request);
-        $this->user   = $user;
+        $this->user = $user;
+        $this->deps = Dependencies::get();
 
         //default http header: we assume something is broken
         header('HTTP/1.0 500 Internal Server Error');
 
         //default http header: we assume something is broken
         header('HTTP/1.0 500 Internal Server Error');
@@ -49,7 +51,7 @@ class TokenController extends Controller
 
 
     /**
 
 
     /**
-     * Delete access tokens
+     * Delete an access token
      * DELETE /tokens/$username/$tokenKey
      *
      * @NoAdminRequired
      * DELETE /tokens/$username/$tokenKey
      *
      * @NoAdminRequired
@@ -84,5 +86,27 @@ class TokenController extends Controller
         $res->setStatus(\OCP\AppFramework\Http::STATUS_NO_CONTENT);
         return $res;
     }
         $res->setStatus(\OCP\AppFramework\Http::STATUS_NO_CONTENT);
         return $res;
     }
+
+    /**
+     * Delete an access token via POST
+     * POST /tokens/$username/$tokenKey
+     *
+     * @NoAdminRequired
+     * @NoCSRFRequired
+     */
+    public function deletePost($username, $tokenKey)
+    {
+        if (isset($_POST['delete']) && $_POST['delete'] == 1) {
+            $this->delete($username, $tokenKey);
+        }
+
+        $res = new RedirectResponse(
+            $this->deps->urlGen->getAbsoluteURL(
+                $this->deps->urlGen->linkToRoute('grauphel.gui.tokens')
+            )
+        );
+        $res->setStatus(\OCP\AppFramework\Http::STATUS_FOUND);
+        return $res;
+    }
 }
 ?>
 }
 ?>
index 85143f7..21c44d4 100644 (file)
@@ -115,3 +115,20 @@ table.table td {
     background-position: 8px center;
     background-repeat: no-repeat;
 }
     background-position: 8px center;
     background-repeat: no-repeat;
 }
+
+a.action.delete, table.table form button.action.delete {
+    position: absolute;
+    right: 0px;
+    padding: 17px 14px;
+    padding: 3px 14px;
+}
+a.action {
+    line-height: 30px;
+}
+table.table form {
+    display: inline;
+}
+table.table form button.action {
+    border: none;
+    background-color: transparent;
+}
index 7707516..48e5998 100644 (file)
@@ -11,7 +11,6 @@
      <th>Token</th>
      <th>Client</th>
      <th>Last use</th>
      <th>Token</th>
      <th>Client</th>
      <th>Last use</th>
-     <th>Actions</th>
     </tr>
    </thead>
    <tbody>
     </tr>
    </thead>
    <tbody>
       <tr>
        <td><?php p($token->tokenKey); ?></td>
        <td title="<?php p($token->client); ?>"><?php p($_['client']->getNiceName($token->client)); ?></td>
       <tr>
        <td><?php p($token->tokenKey); ?></td>
        <td title="<?php p($token->client); ?>"><?php p($_['client']->getNiceName($token->client)); ?></td>
-       <td><?php p(\OCP\Util::formatDate($token->lastuse)); ?></td>
-       <td>Disable Delete</td>
+       <td>
+        <?php p(\OCP\Util::formatDate($token->lastuse)); ?>
+        <form method="POST" action="<?php p(OCP\Util::linkToRoute('grauphel.token.delete', array('username' => $_['username'], 'tokenKey' => $token->tokenKey))); ?>">
+           <input type="hidden" name="delete" value="1" />
+           <button type="submit" class="icon-delete delete action" original-title="Delete"/>
+        </form>
+       </td>
       </tr>
     <?php } ?>
    </tbody>
       </tr>
     <?php } ?>
    </tbody>