3 namespace app\Controller
;
16 abstract class Github
implements Controller
33 function __construct(Web
$app, API
$github, Session
$session) {
35 $this->github
= $github;
36 $this->session
= $session;
37 $this->app
->getView()->addData(compact("session") +
[
38 "location" => "github",
41 $this->app
->getView()->registerFunction("check", [$github, "checkRepoHook"]);
43 if (($header = $this->app
->getRequest()->getHeader("Cache-Control", Header
::class))) {
44 $params = $header->getParams();
45 if (!empty($params["no-cache"])) {
46 $this->github
->setMaxAge(0);
47 } elseif (!empty($params["max-age"])) {
48 $this->github
->setMaxAge($params["max-age"]["value"]);
53 protected function login(Account
$account, Token
$token, Owner
$owner) {
55 $auth->setCookie("account", $account->account
->get());
56 $auth->setFlags(Cookie
::SECURE | Cookie
::HTTPONLY
);
57 $auth->setPath($this->app
->getBaseUrl()->path
);
58 $auth->setMaxAge(60*60*24);
59 $this->app
->getResponse()->setCookie($auth);
61 $this->github
->setToken($token->token
->get());
62 $this->session
->account
= $account->account
->get();
63 $this->session
->github
= (object) $owner->export();
66 protected function checkToken() {
67 if ($this->github
->hasToken()) {
70 $this->app
->redirect($this->app
->getBaseUrl()->mod([
71 "path" => "github/signin",
72 "query" => new QueryString(["returnto" => $this->session
->current
])