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 20325dec1f64001809b57c831ced55e3a1640161..66ed5571a2315570d891918df3d746daa5df987e 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 a730583d8b87569678713ece4fb9110e393310b6..28ba16d185e4426f472d36f50dab04c8480491bd 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 0cb8e913ffeb95988bdfe58c6e89b11313309dcf..58768f2e880883418be36d1ecf8613684bfa2ecb 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 97d142a19f026a3f6b15de2074173dd2a757b7bb..acc9238c111e8f1e12e6979e4d39b24fbe6f6bab 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 85143f7bb04aff15a5fa16e64f79c185afd4b979..21c44d453f9f3365a9b13d3fcd6cea58fdecd053 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 770751637f9580824a9375aab9c1578358d2004b..48e5998a51f60bf80461fadb5ab0035956457d77 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>