diff options
author | Frédéric Guillot <fred@kanboard.net> | 2014-06-30 21:52:02 -0300 |
---|---|---|
committer | Frédéric Guillot <fred@kanboard.net> | 2014-06-30 21:52:02 -0300 |
commit | 06d0b7048ebcdfdf6e24eec3ac7dc8fb0327dd6f (patch) | |
tree | eb006b4c560781186f1debd2437c02edf6008878 /app/Controller/User.php | |
parent | f70ac7d65fa0e7f1e6a9559242d9c141ba5c9eb3 (diff) |
Merge pull-request: Github authentication #162
Diffstat (limited to 'app/Controller/User.php')
-rw-r--r-- | app/Controller/User.php | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/app/Controller/User.php b/app/Controller/User.php index fca33b28..d30c6fd2 100644 --- a/app/Controller/User.php +++ b/app/Controller/User.php @@ -299,4 +299,68 @@ class User extends Base $this->response->redirect('?controller=user'); } + + /** + * GitHub authentication + * + * @access public + */ + public function gitHub() + { + $code = $this->request->getStringParam('code'); + + if ($code) { + $profile = $this->gitHub->getGitHubProfile($code); + + if (is_array($profile)) { + + // If the user is already logged, link the account otherwise authenticate + if ($this->acl->isLogged()) { + + if ($this->gitHub->updateUser($this->acl->getUserId(), $profile)) { + $this->session->flash(t('Your GitHub account was successfully linked to your profile.')); + } + else { + $this->session->flashError(t('Unable to link your GitHub Account.')); + } + + $this->response->redirect('?controller=user'); + } + else if ($this->gitHub->authenticate($profile['id'])) { + $this->response->redirect('?controller=app'); + } + else { + $this->response->html($this->template->layout('user_login', array( + 'errors' => array('login' => t('GitHub authentication failed')), + 'values' => array(), + 'no_layout' => true, + 'title' => t('Login') + ))); + } + } + } + + $this->response->redirect($this->gitHub->getAuthorizationUrl()); + } + + /** + * Unlink a GitHub account + * + * @access public + */ + public function unlinkGitHub() + { + $this->checkCSRFParam(); + + $this->gitHub->revokeGitHubAccess(); + + if ($this->gitHub->unlink($this->acl->getUserId())) { + $this->session->flash(t('Your GitHub account is no longer linked to your profile.')); + } + else { + $this->session->flashError(t('Unable to unlink your GitHub Account.')); + } + + $this->response->redirect('?controller=user'); + } } |