summaryrefslogtreecommitdiff
path: root/controllers/user.php
diff options
context:
space:
mode:
authorFrédéric Guillot <fguillot@users.noreply.github.com>2014-05-03 22:24:03 -0400
committerFrédéric Guillot <fguillot@users.noreply.github.com>2014-05-03 22:24:03 -0400
commit560a12f0bd6347a335f8ed5201d6d9562d03d4bc (patch)
tree00510d25c1cf5e747573543fa88d44ef003b1c9a /controllers/user.php
parent9531e439cd99fb7dbcfb039f422f1d1ba414ec30 (diff)
Add Google authentication
Diffstat (limited to 'controllers/user.php')
-rw-r--r--controllers/user.php61
1 files changed, 61 insertions, 0 deletions
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');
+ }
}