diff options
Diffstat (limited to 'controllers')
-rw-r--r-- | controllers/base.php | 97 | ||||
-rw-r--r-- | controllers/user.php | 61 |
2 files changed, 158 insertions, 0 deletions
diff --git a/controllers/base.php b/controllers/base.php index ebc946fc..6b5555c4 100644 --- a/controllers/base.php +++ b/controllers/base.php @@ -11,6 +11,102 @@ namespace Controller; abstract class Base { /** + * Acl model + * + * @accesss protected + * @var \Model\Acl + */ + protected $acl; + + /** + * Action model + * + * @accesss protected + * @var \Model\Action + */ + protected $action; + + /** + * Board model + * + * @accesss protected + * @var \Model\Board + */ + protected $board; + + /** + * Config model + * + * @accesss protected + * @var \Model\Config + */ + protected $config; + + /** + * Project model + * + * @accesss protected + * @var \Model\Project + */ + protected $project; + + /** + * Task model + * + * @accesss protected + * @var \Model\Task + */ + protected $task; + + /** + * User model + * + * @accesss protected + * @var \Model\User + */ + protected $user; + + /** + * Comment model + * + * @accesss protected + * @var \Model\Comment + */ + protected $comment; + + /** + * RememberMe model + * + * @accesss protected + * @var \Model\RememberMe + */ + protected $rememberMe; + + /** + * LastLogin model + * + * @accesss protected + * @var \Model\LastLogin + */ + protected $lastLogin; + + /** + * Google model + * + * @accesss protected + * @var \Model\Google + */ + protected $google; + + /** + * Event instance + * + * @accesss protected + * @var \Model\Event + */ + protected $event; + + /** * Constructor * * @access public @@ -28,6 +124,7 @@ abstract class Base $this->comment = $registry->comment; $this->rememberMe = $registry->rememberMe; $this->lastLogin = $registry->lastLogin; + $this->google = $registry->google; $this->event = $registry->shared('event'); } diff --git a/controllers/user.php b/controllers/user.php index cc180976..edd7ae45 100644 --- a/controllers/user.php +++ b/controllers/user.php @@ -248,4 +248,65 @@ class User extends Base $this->response->redirect('?controller=user'); } + + /** + * Google authentication + * + * @access public + */ + public function google() + { + $code = $this->request->getStringParam('code'); + + if ($code) { + + $profile = $this->google->getGoogleProfile($code); + + if (is_array($profile)) { + + // If the user is already logged, link the account otherwise authenticate + if ($this->acl->isLogged()) { + + if ($this->google->updateUser($this->acl->getUserId(), $profile)) { + $this->session->flash(t('Your Google Account is linked to your profile successfully.')); + } + else { + $this->session->flashError(t('Unable to link your Google Account.')); + } + + $this->response->redirect('?controller=user'); + } + else if ($this->google->authenticate($profile['id'])) { + $this->response->redirect('?controller=app'); + } + else { + $this->response->html($this->template->layout('user_login', array( + 'errors' => array('login' => t('Google authentication failed')), + 'values' => array(), + 'no_layout' => true, + 'title' => t('Login') + ))); + } + } + } + + $this->response->redirect($this->google->getAuthorizationUrl()); + } + + /** + * Unlink a Google account + * + * @access public + */ + public function unlinkGoogle() + { + if ($this->google->unlink($this->acl->getUserId())) { + $this->session->flash(t('Your Google Account is not linked anymore to your profile.')); + } + else { + $this->session->flashError(t('Unable to unlink your Google Account.')); + } + + $this->response->redirect('?controller=user'); + } } |