inital commit
[pharext/pharext.org] / app / Controller / Github / Callback.php
1 <?php
2
3 namespace app\Controller\Github;
4
5 use app\Controller\Github;
6
7 class Callback extends Github
8 {
9 function __invoke(array $args = null) {
10 if ($this->app->getRequest()->getQuery("error")) {
11 $this->app->getView()->addData([
12 "error" => $this->app->getRequest()->getQuery("error_description")
13 ]);
14 } else {
15 try {
16 $this->github->fetchToken(
17 $this->app->getRequest()->getQuery("code"),
18 $this->app->getRequest()->getQuery("state"),
19 function($json) {
20 $this->github->setToken($json->access_token);
21 })->send();
22 if (isset($this->session->returnto)) {
23 $this->app->redirect($this->session->returnto);
24 } else {
25 $this->app->redirect(
26 $this->app->getBaseUrl()->mod("./github"));
27 }
28 } catch (\app\Github\Exception $exception) {
29 $this->app->getView()->addData(compact("exception"));
30 }
31 }
32 $this->app->display("github/callback");
33 }
34 }