Exemplo n.º 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;
 }
Exemplo n.º 2
0
 public function login()
 {
     $this->authMethodInstance = $this->getAuthMethod();
     $this->authMethodInstance->setPasswordCryptFunction($this->parameters->get('password_crypt', function ($password, $storedPassword) {
         return md5($password) == $storedPassword;
     }));
     $this->authMethodInstance->setUsersModel($this->parameters->get('users_model'));
     $userModelFields = $this->parameters->get('users_model_fields');
     $this->authMethodInstance->setUsersModelFields($userModelFields);
     View::set('login_data', [$userModelFields['username'] => Input::post($userModelFields['username']), $userModelFields['password'] => Input::post($userModelFields['password'])]);
     if ($this->loggedIn()) {
         $this->performSuccessOperation();
     } else {
         if ($this->authMethodInstance->login()) {
             Session::set('logged_in', true);
             $this->performSuccessOperation();
         } else {
             $this->performFailureOperation();
         }
     }
 }
Exemplo n.º 3
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);
 }