/** * @param Plus $plus * * @return User|bool */ public static function fromGoogleAuth(Plus $plus) { $person = $plus->person(); $email = false; foreach ($person->getEmails() as $email) { if (self::emailBelongsToAccount($email)) { $email = $email->value; } } if (!$email) { // throw new Exception('Failed to determine account email'); // return false; exit('Failed to determine account email'); // temporary } return new self($email, $person->getDisplayName(), $person->getImage()->url, $person->getId(), $plus->client()->refreshToken(), 0); }
<?php require_once '../autoload.php'; $user = Auth::user(); $dbManager = new DatabaseManager(); if (isset($_GET['code'])) { $plus = Plus::fromRequest($_GET); $gUser = User::fromGoogleAuth($plus); $user = $dbManager->userExists($gUser->id()); if (!$user) { $user = $dbManager->makeUser($gUser); } else { if ($gUser->refreshToken()) { $user = $dbManager->updateRefreshToken($gUser); } } $tmp_user = $dbManager->getUser($user->id()); $user->remainingUsernameChanges = $tmp_user->remainingUsernameChanges; Auth::login($user); } $key = 'unauthenticated'; $displayName = false; if ($user) { $displayName = "\"" + $user->displayName() + "\""; $key = $dbManager->genAuthKey($user); if ($user->remainingUsernameChanges === 3) { echo "showUsernameModal();\n"; die; } } // ...
/** * Returns the data model based on the primary key given in the GET variable. * If the data model is not found, an HTTP exception will be raised. * @param integer $id the ID of the model to be loaded * @return Plus the loaded model * @throws CHttpException */ public function loadModel($id) { $model = Plus::model()->findByPk($id); if ($model === null) { throw new CHttpException(404, 'The requested page does not exist.'); } return $model; }