diff options
Diffstat (limited to 'app/Controller/Oauth.php')
-rw-r--r-- | app/Controller/Oauth.php | 83 |
1 files changed, 30 insertions, 53 deletions
diff --git a/app/Controller/Oauth.php b/app/Controller/Oauth.php index 8c701cf7..452faecd 100644 --- a/app/Controller/Oauth.php +++ b/app/Controller/Oauth.php @@ -11,49 +11,19 @@ namespace Kanboard\Controller; class Oauth extends Base { /** - * Link or authenticate a Google account - * - * @access public - */ - public function google() - { - $this->step1('google'); - } - - /** - * Link or authenticate a Github account - * - * @access public - */ - public function github() - { - $this->step1('github'); - } - - /** - * Link or authenticate a Gitlab account - * - * @access public - */ - public function gitlab() - { - $this->step1('gitlab'); - } - - /** * Unlink external account * * @access public */ - public function unlink($backend = '') + public function unlink() { - $backend = $this->request->getStringParam('backend', $backend); + $backend = $this->request->getStringParam('backend'); $this->checkCSRFParam(); - if ($this->authentication->backend($backend)->unlink($this->userSession->getId())) { - $this->session->flash(t('Your external account is not linked anymore to your profile.')); + if ($this->authenticationManager->getProvider($backend)->unlink($this->userSession->getId())) { + $this->flash->success(t('Your external account is not linked anymore to your profile.')); } else { - $this->session->flashError(t('Unable to unlink your external account.')); + $this->flash->failure(t('Unable to unlink your external account.')); } $this->response->redirect($this->helper->url->to('user', 'external', array('user_id' => $this->userSession->getId()))); @@ -63,46 +33,52 @@ class Oauth extends Base * Redirect to the provider if no code received * * @access private + * @param string $provider */ - private function step1($backend) + protected function step1($provider) { $code = $this->request->getStringParam('code'); if (! empty($code)) { - $this->step2($backend, $code); + $this->step2($provider, $code); } else { - $this->response->redirect($this->authentication->backend($backend)->getService()->getAuthorizationUrl()); + $this->response->redirect($this->authenticationManager->getProvider($provider)->getService()->getAuthorizationUrl()); } } /** * Link or authenticate the user * - * @access private + * @access protected + * @param string $provider + * @param string $code */ - private function step2($backend, $code) + protected function step2($provider, $code) { - $profile = $this->authentication->backend($backend)->getProfile($code); + $this->authenticationManager->getProvider($provider)->setCode($code); if ($this->userSession->isLogged()) { - $this->link($backend, $profile); + $this->link($provider); } - $this->authenticate($backend, $profile); + $this->authenticate($provider); } /** * Link the account * - * @access private + * @access protected + * @param string $provider */ - private function link($backend, $profile) + protected function link($provider) { - if (empty($profile)) { - $this->session->flashError(t('External authentication failed')); + $authProvider = $this->authenticationManager->getProvider($provider); + + if (! $authProvider->authenticate()) { + $this->flash->failure(t('External authentication failed')); } else { - $this->session->flash(t('Your external account is linked to your profile successfully.')); - $this->authentication->backend($backend)->updateUser($this->userSession->getId(), $profile); + $this->userProfile->assign($this->userSession->getId(), $authProvider->getUser()); + $this->flash->success(t('Your external account is linked to your profile successfully.')); } $this->response->redirect($this->helper->url->to('user', 'external', array('user_id' => $this->userSession->getId()))); @@ -111,14 +87,15 @@ class Oauth extends Base /** * Authenticate the account * - * @access private + * @access protected + * @param string $provider */ - private function authenticate($backend, $profile) + protected function authenticate($provider) { - if (! empty($profile) && $this->authentication->backend($backend)->authenticate($profile['id'])) { + if ($this->authenticationManager->oauthAuthentication($provider)) { $this->response->redirect($this->helper->url->to('app', 'index')); } else { - $this->response->html($this->template->layout('auth/index', array( + $this->response->html($this->helper->layout->app('auth/index', array( 'errors' => array('login' => t('External authentication failed')), 'values' => array(), 'no_layout' => true, |