d753687a3b7928ed739bc4b0bc66dbc54dbbad8b
3 namespace app\Controller\Github
;
5 use app\Controller\Github
;
7 use app\Model\Accounts
;
11 class Signin
extends Github
18 function __construct(Web
$app, API
$github, Session
$session, Accounts
$accounts) {
19 parent
::__construct($app, $github, $session);
20 $this->accounts
= $accounts;
23 function __invoke(array $args = null) {
24 if (($cookie = $this->app
->getRequest()->getCookie("account"))) {
25 $accounts = $this->accounts
->find(["account=" => $cookie]);
26 if (count($accounts)) {
27 $account = $accounts->current();
28 $tokens = $account->allOf("tokens")->filter(function($token) {
29 return $token->authority
== "github";
32 $token = $tokens->current();
33 $this->login($account, $token,
34 $account->allOf("owners")->filter(function($owner) {
35 return $owner->authority
== "github";
38 if (($returnto = $this->app
->getRequest()->getQuery("returnto"))) {
39 $this->app
->redirect($returnto);
41 $this->app
->redirect($this->app
->getBaseUrl()->mod("./github"));
47 $callback = $this->app
->getBaseUrl()->mod("./github/callback");
48 $location = $this->github
->getAuthUrl($callback);
49 $this->app
->redirect($location);
50 if (($returnto = $this->app
->getRequest()->getQuery("returnto"))) {
51 $this->session
->returnto
= $returnto;