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;
 }
Example #2
0
 public static function postLogin()
 {
     /*$menu = array();
             
             if(Ntentan::$config['wyf.has_roles'] == 'true')
             {
                 // Get the roles the user is attached to
                 $userRoles = Model::load('system.user_roles')->getAll(
                     array(
                         'conditions' => array(
                             'user_id' => $_SESSION['user']['id']
                         )
                     )
                 );
     
                 foreach($userRoles->toArray() as $userRole)
                 {
                     $role = Model::load('system.roles')->getJustFirstWithId($userRole['role_id']);
                     $menu = array_merge(json_decode($role->menu_tree, true), $menu);
                 }
             }
             else
             {
                 require Ntentan::$appHome . Ntentan::$modulesPath . "/menu.php";
             }        
             
             $sideMenu = array();
             
             foreach($menu as $path => $menuItem)
             {
                 $sideMenu[] = array(
                     'label' => $menuItem['label'],
                     'path' => $path
                 );
                 
                 if($menuItem['type'] == 'group')
                 {
                     $_SESSION['menu']['sub'][$path] = $menuItem['children'];
                 }
             }
             
             $_SESSION['menu']['main'] = $sideMenu;
             
             if(self::$bootstrapClass !== false)
             {
                 try{
                     $bootstrapMethod = new \ReflectionMethod(self::$bootstrapClass, "login");
                     $bootstrapMethod->invoke(null, $this);
                 }
                 catch(\ReflectionException $e)
                 {
                     //Do nothing
                 }
             }*/
     return \ntentan\controllers\Redirect::path('dashboard');
 }
Example #3
0
 public function logout()
 {
     Session::reset();
     Redirect::path($this->parameters->get('login_route', "/login"));
 }
 private function performSuccessOperation()
 {
     switch ($this->onSignin) {
         case self::ON_SUCCESS_REDIRECT:
             Redirect::path($this->redirectUrl);
             break;
         case self::ON_SUCCESS_CALL_FUNCTION:
             $decomposed = explode("::", $this->signinFunction);
             $className = $decomposed[0];
             $methodName = $decomposed[1];
             $method = new \ReflectionMethod($className, $methodName);
             $method->invoke(null, $this->controller);
             break;
     }
 }
Example #5
0
 public function delete($id, $confirm = null)
 {
     $model = $this->getModel();
     $primaryKey = $model->getDescription()->getPrimaryKey()[0];
     $item = $model->fetchFirst([$primaryKey => $id]);
     if ($confirm == 'yes') {
         $item->delete();
         return Redirect::action('');
     } else {
         View::set('item', $item);
         View::set('delete_yes_url', Url::action("delete/{$id}", ['confirm' => 'yes']));
         View::set('delete_no_url', Url::action(''));
     }
 }