From ace226e665fa77d04a61dfd61818f6cce5df6861 Mon Sep 17 00:00:00 2001 From: Christian Weiske Date: Tue, 7 Oct 2014 07:51:07 +0200 Subject: [PATCH] Deleting tokens works (without confirmation) --- appinfo/application.php | 2 ++ appinfo/routes.php | 5 +++++ controller/guicontroller.php | 1 + controller/tokencontroller.php | 28 ++++++++++++++++++++++++++-- grauphel.css | 17 +++++++++++++++++ templates/tokens.php | 10 +++++++--- 6 files changed, 58 insertions(+), 5 deletions(-) diff --git a/appinfo/application.php b/appinfo/application.php index 20325de..66ed557 100644 --- a/appinfo/application.php +++ b/appinfo/application.php @@ -59,6 +59,8 @@ class Application extends App $container->registerService( 'TokenController', function($c) { + Dependencies::get()->urlGen + = $c->query('ServerContainer')->getURLGenerator(); return new \OCA\Grauphel\Controller\TokenController( $c->query('AppName'), $c->query('Request'), diff --git a/appinfo/routes.php b/appinfo/routes.php index a730583..28ba16d 100644 --- a/appinfo/routes.php +++ b/appinfo/routes.php @@ -79,6 +79,11 @@ $application->registerRoutes( 'name' => 'token#delete', 'verb' => 'DELETE', ), + array( + 'url' => '/tokens/{username}/{tokenKey}', + 'name' => 'token#deletePost', + 'verb' => 'POST', + ), ) ) ); diff --git a/controller/guicontroller.php b/controller/guicontroller.php index 0cb8e91..58768f2 100644 --- a/controller/guicontroller.php +++ b/controller/guicontroller.php @@ -111,6 +111,7 @@ class GuiController extends Controller $this->user->getUid(), 'access' ), 'client' => new Client(), + 'username' => $this->user->getUid(), ) ); $this->addNavigation($res, null); diff --git a/controller/tokencontroller.php b/controller/tokencontroller.php index 97d142a..acc9238 100644 --- a/controller/tokencontroller.php +++ b/controller/tokencontroller.php @@ -14,6 +14,7 @@ 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; @@ -41,7 +42,8 @@ class TokenController extends Controller 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'); @@ -49,7 +51,7 @@ class TokenController extends Controller /** - * Delete access tokens + * Delete an access token * DELETE /tokens/$username/$tokenKey * * @NoAdminRequired @@ -84,5 +86,27 @@ class TokenController extends Controller $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; + } } ?> diff --git a/grauphel.css b/grauphel.css index 85143f7..21c44d4 100644 --- a/grauphel.css +++ b/grauphel.css @@ -115,3 +115,20 @@ table.table td { 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; +} diff --git a/templates/tokens.php b/templates/tokens.php index 7707516..48e5998 100644 --- a/templates/tokens.php +++ b/templates/tokens.php @@ -11,7 +11,6 @@ Token Client Last use - Actions @@ -19,8 +18,13 @@ tokenKey); ?> getNiceName($token->client)); ?> - lastuse)); ?> - Disable Delete + + lastuse)); ?> +
+ +