webhook management
[pharext/pharext.org] / app / Controller / Github / Repo / Hook.php
index 7bfb54565bd5980264afde502197c404196965d1..1ef33a37cb921cae11284f1c8d95a5c2910a8d8b 100644 (file)
@@ -7,14 +7,22 @@ use app\Controller\Github;
 class Hook extends Github
 {
        function __invoke(array $args = null) {
-               switch ($args["action"]) {
-                       case "add":
-                               $this->addHook($args["owner"], $args["name"]);
-                               break;
-                       
-                       case "del":
-                               $this->delHook($args["owner"], $args["name"]);
-                               break;
+               if ($this->checkToken()) {
+                       if ($this->app->getRequest()->getRequestMethod() != "POST") {
+                               // user had to re-authenticate, and was redirected here
+                               $this->app->redirect($this->app->getBaseUrl()->mod([
+                                       "path" => "./github/repo/" . $args["owner"] ."/". $args["name"],
+                                       "query" => "modal=hook&hook=" . $args["action"]
+                               ]));
+                       } else switch ($args["action"]) {
+                               case "add":
+                                       $this->addHook($args["owner"], $args["name"]);
+                                       break;
+
+                               case "del":
+                                       $this->delHook($args["owner"], $args["name"]);
+                                       break;
+                       }
                }
        }