public function actionGoogleLogin() { if (isset($_GET['error'])) { $this->redirect(Yii::app()->createUrl('/store')); } $plus = Yii::app()->GoogleApis->serviceFactory('Oauth2'); $client = Yii::app()->GoogleApis->client; try { if (!isset(Yii::app()->session['auth_token']) || is_null(Yii::app()->session['auth_token'])) { // You want to use a persistence layer like the DB for storing this along // with the current user Yii::app()->session['auth_token'] = $client->authenticate(); } else { if (isset($_SESSION['auth_token'])) { $client->setAccessToken($_SESSION['auth_token']); } } if (isset($_REQUEST['logout'])) { unset($_SESSION['auth_token']); $client->revokeToken(); } if ($token = $client->getAccessToken()) { $t = $plus->userinfo->get(); if (is_array($t) && count($t) >= 1) { $func = new FunctionsK(); if ($resp_t = $func->googleRegister($t)) { Yii::app()->functions->clientAutoLogin($t['email'], $resp_t['password'], $resp_t['password']); unset($_SESSION['auth_token']); $client->revokeToken(); if (isset($_SESSION['google_http_refferer'])) { $this->redirect($_SESSION['google_http_refferer']); } else { $this->redirect(Yii::app()->createUrl('/store')); } die; } else { echo t("ERROR: Something went wrong"); } } else { echo t("ERROR: Something went wrong"); } } else { $authUrl = $client->createAuthUrl(); } if (isset($authUrl)) { print "<a class='login' href='{$authUrl}'>Connect Me!</a>"; } else { print "<a class='logout' href='?logout'>Logout</a>"; } } catch (Exception $e) { Yii::app()->session['auth_token'] = null; throw $e; } }