summaryrefslogtreecommitdiff
path: root/app/Controller
diff options
context:
space:
mode:
Diffstat (limited to 'app/Controller')
-rw-r--r--app/Controller/Base.php1
-rw-r--r--app/Controller/User.php64
2 files changed, 65 insertions, 0 deletions
diff --git a/app/Controller/Base.php b/app/Controller/Base.php
index 13fb9b91..25a72f15 100644
--- a/app/Controller/Base.php
+++ b/app/Controller/Base.php
@@ -20,6 +20,7 @@ use Model\LastLogin;
* @property \Model\Config $config
* @property \Model\File $file
* @property \Model\Google $google
+ * @property \Model\GitHub $gitHub
* @property \Model\LastLogin $lastLogin
* @property \Model\Ldap $ldap
* @property \Model\Project $project
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');
+ }
}