コード例 #1
1
 public function signin()
 {
     $client = new \Google_Client();
     $client->setClientId(Config::get('ntentan:social.google.client_id'));
     $client->setClientSecret(Config::get('ntentan:social.google.client_secret'));
     $client->setRedirectUri(Config::get('ntentan:social.google.redirect_uri'));
     $client->addScope(array('profile', 'email'));
     $oauth2 = new \Google_Service_Oauth2($client);
     if (isset($_REQUEST['logout'])) {
         Session::set('access_token', '');
         $client->revokeToken();
     }
     if (isset($_GET['code'])) {
         $client->authenticate($_GET['code']);
         Session::set('access_token', $client->getAccessToken());
         Redirect::path(\ntentan\Router::getRoute());
     }
     if (isset($_SESSION['access_token'])) {
         $client->setAccessToken($_SESSION['access_token']);
     }
     if ($client->isAccessTokenExpired()) {
         $authUrl = $client->createAuthUrl();
         header('Location: ' . filter_var($authUrl, FILTER_SANITIZE_URL));
     }
     if ($client->getAccessToken()) {
         $user = $oauth2->userinfo->get();
         $_SESSION['token'] = $client->getAccessToken();
         return array('firstname' => $user['given_name'], 'lastname' => $user['family_name'], 'key' => "google_{$user['id']}", 'avatar' => $user['picture'], 'email' => $user['email'], 'email_confirmed' => $user['verified_email']);
     } else {
         header("Location: {$client->createAuthUrl()}");
         die;
     }
     return false;
 }
コード例 #2
0
ファイル: AuthComponent.php プロジェクト: ntentan/ntentan
 public function getProfile()
 {
     if (Session::get('logged_in')) {
         return Session::get('user');
     } else {
         $this->redirectToLogin();
     }
 }
コード例 #3
0
ファイル: Ntentan.php プロジェクト: ntentan/ntentan
 public static function run()
 {
     Session::start();
     honam\TemplateEngine::prependPath('views/shared');
     honam\TemplateEngine::prependPath('views/layouts');
     honam\AssetsLoader::setSiteUrl(Url::path('public'));
     honam\AssetsLoader::appendSourceDir('assets');
     honam\AssetsLoader::setDestinationDir('public');
     honam\Helper::setBaseUrl(Url::path(''));
     self::getRouter()->execute(substr(utils\Input::server('REQUEST_URI'), 1));
 }
コード例 #4
0
 /**
  * @ntentan.action register
  * @ntentan.method POST
  * @param \paanoo\models\Users $user
  */
 public function saveRegistration(\ntentan\extensions\social\models\Users $user)
 {
     if ($user->save()) {
         $user->avatar = '';
         Session::set('logged_in', true);
         Session::set('user', $user->toArray());
         $this->performSuccessOperation();
     }
     View::set('model', $user);
 }