]> git.immae.eu Git - github/shaarli/Shaarli.git/commitdiff
Add an endpoint to refresh the token
authorArthurHoaro <arthur@hoa.ro>
Sat, 25 Mar 2017 14:54:18 +0000 (15:54 +0100)
committerArthurHoaro <arthur@hoa.ro>
Thu, 25 May 2017 13:05:23 +0000 (15:05 +0200)
Useful for AJAX requests which burns the token

application/Router.php
index.php

index c9a519120eecf3274c1b66a7df5f4e2deacbec95..f6896b1cfcd578ac02792d0f9c4f673f169aa136 100644 (file)
@@ -45,6 +45,8 @@ class Router
 
     public static $PAGE_SAVE_PLUGINSADMIN = 'save_pluginadmin';
 
+    public static $GET_TOKEN = 'token';
+
     /**
      * Reproducing renderPage() if hell, to avoid regression.
      *
@@ -142,6 +144,10 @@ class Router
             return self::$PAGE_SAVE_PLUGINSADMIN;
         }
 
+        if (startsWith($query, 'do='. self::$GET_TOKEN)) {
+            return self::$GET_TOKEN;
+        }
+
         return self::$PAGE_LINKLIST;
     }
 }
index 40539a04666c1c16acbad9c604a5e7a2cef48cc0..9566fb016f14156fa3efc7bec609d5e2b9763e31 100644 (file)
--- a/index.php
+++ b/index.php
@@ -1582,6 +1582,13 @@ function renderPage($conf, $pluginManager, $LINKSDB, $history)
         exit;
     }
 
+    // Get a fresh token
+    if ($targetPage == Router::$GET_TOKEN) {
+        header('Content-Type:text/plain');
+        echo getToken($conf);
+        exit;
+    }
+
     // -------- Otherwise, simply display search form and links:
     showLinkList($PAGE, $LINKSDB, $conf, $pluginManager);
     exit;