X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=app%2FController%2FGithub%2FSignin.php;h=d753687a3b7928ed739bc4b0bc66dbc54dbbad8b;hb=9815b77a14832685f90d34f9a348af1cadd63576;hp=9fca55481886af5321fe0157f4206cd55bb5a611;hpb=498633479633aaaaea5d848b4f466821f15b205f;p=pharext%2Fpharext.org diff --git a/app/Controller/Github/Signin.php b/app/Controller/Github/Signin.php index 9fca554..d753687 100644 --- a/app/Controller/Github/Signin.php +++ b/app/Controller/Github/Signin.php @@ -3,10 +3,47 @@ namespace app\Controller\Github; use app\Controller\Github; +use app\Github\API; +use app\Model\Accounts; +use app\Session; +use app\Web; class Signin extends Github { + /** + * @var Accounts + */ + private $accounts; + + function __construct(Web $app, API $github, Session $session, Accounts $accounts) { + parent::__construct($app, $github, $session); + $this->accounts = $accounts; + } + function __invoke(array $args = null) { + if (($cookie = $this->app->getRequest()->getCookie("account"))) { + $accounts = $this->accounts->find(["account=" => $cookie]); + if (count($accounts)) { + $account = $accounts->current(); + $tokens = $account->allOf("tokens")->filter(function($token) { + return $token->authority == "github"; + }); + if (count($tokens)) { + $token = $tokens->current(); + $this->login($account, $token, + $account->allOf("owners")->filter(function($owner) { + return $owner->authority == "github"; + })->current() + ); + if (($returnto = $this->app->getRequest()->getQuery("returnto"))) { + $this->app->redirect($returnto); + } else { + $this->app->redirect($this->app->getBaseUrl()->mod("./github")); + } + return; + } + } + } $callback = $this->app->getBaseUrl()->mod("./github/callback"); $location = $this->github->getAuthUrl($callback); $this->app->redirect($location);