示例#1
0
 public function assignRoles($id)
 {
     if (count($_POST) > 0) {
         $roles = Model::load('system.user_roles')->getJustWithUserId($id);
         foreach ($roles as $role) {
             $role->delete();
         }
         foreach ($_POST as $roleId) {
             $role = Model::load('system.user_roles')->getNew();
             $role->user_id = $id;
             $role->role_id = $roleId;
             $role->save();
         }
         Ntentan::redirect($this->route);
     }
     $item = $this->model->getJustFirstWithId($id);
     $roles = Model::load('system.roles')->getAll();
     $assignedRoles = Model::load('system.user_roles')->getJustWithUserId($id, array('fields' => array('role_id')))->toArray();
     $structuredAssignedRoles = array();
     foreach ($assignedRoles as $assignedRole) {
         $structuredAssignedRoles[$assignedRole['role_id']] = true;
     }
     $this->set('roles', $roles);
     $this->set('assigned_roles', $structuredAssignedRoles);
     $this->set('item', (string) $item);
 }
示例#2
0
 public function preExecute()
 {
     if ($_SESSION["logged_in"] === true) {
         if (is_array($this->authenticated[$_SESSION['role_id']])) {
             foreach ($this->authenticated[$_SESSION['role_id']] as $authenticated) {
                 if (is_string($authenticated)) {
                     if (preg_match($authenticated, Ntentan::$route, $members)) {
                         return;
                     }
                 }
             }
             header($_SERVER["SERVER_PROTOCOL"] . " 404 Not Found");
             die;
         }
     } else {
         foreach ($this->anonymous as $anonymous) {
             if (Ntentan::$route === $this->controller->authComponent->loginRoute) {
                 $this->controller->authComponent->login();
                 break;
             } else {
                 if (preg_match("{$anonymous["path"]}", Ntentan::$route) > 0) {
                     if ($anonymous["access"] == "disallow") {
                         if (isset($anonymous["fallback"])) {
                             Ntentan::redirect($anonymous["fallback"]);
                         } else {
                             Ntentan::redirect($this->controller->authComponent->loginRoute . "&redirect=" . \urlencode(Ntentan::$route));
                         }
                     }
                 }
             }
         }
     }
 }
示例#3
0
 public function signin()
 {
     $oauthapp = new \YahooOAuthApplication(Ntentan::$config['social.yahoo.consumer_key'], Ntentan::$config['social.yahoo.consumer_secret'], Ntentan::$config['social.yahoo.app_id'], Ntentan::$config['social.yahoo.redirect_uri']);
     if (!isset($_REQUEST['openid_mode'])) {
         Ntentan::redirect($oauthapp->getOpenIDUrl($oauthapp->callback_url), true);
         die;
     }
     if ($_REQUEST['openid_mode'] == 'id_res') {
         $requestToken = new \YahooOAuthRequestToken($_REQUEST['openid_oauth_request_token'], '');
         $_SESSION['yahoo_oauth_request_token'] = $requestToken->to_string();
         $oauthapp->token = $oauthapp->getAccessToken($requestToken);
         $_SESSION['yahoo_oauth_access_token'] = $oauthapp->token->to_string();
     }
     $profile = $oauthapp->getProfile()->profile;
     if (is_object($profile)) {
         if (is_array($profile->emails)) {
             foreach ($profile->emails as $email) {
                 if ($email->primary == 'true') {
                     $email = $email->handle;
                     break;
                 }
             }
         }
         return array('firstname' => $profile->givenName, 'lastname' => $profile->familyName, 'key' => "yahoo_{$profile->guid}", 'avatar' => $profile->image->imageUrl, 'email' => $email, 'email_confirmed' => true);
     }
     die('Failed');
 }
示例#4
0
 public function add()
 {
     $model = $this->getModel();
     $description = $model->describe();
     $entityCode = str_replace(' ', '_', $this->entity);
     $this->set("heading_level", $this->headingLevel);
     $this->set("headings", $this->headings);
     $this->set("fields", $description["fields"]);
     $this->set("entity", $this->entity);
     $this->set('entity_code', $entityCode);
     $this->view->template = "admin_component_add.tpl.php";
     if ($this->consoleMode) {
         $addExtensionMethodName = Ntentan::camelize(Ntentan::plural($entityCode), ".", "", true) . 'AdminAdd';
         if (method_exists($this->controller, $addExtensionMethodName)) {
             $addExtensionMethod = new ReflectionMethod($this->controller, $addExtensionMethodName);
             $addExtensionMethod->invoke($this->controller);
         }
     }
     if (count($_POST) > 0) {
         $model->setData($_POST);
         $id = $model->save();
         if ($id > 0) {
             $route = $this->consoleMode ? $this->consoleModeRoute : $this->route;
             Ntentan::redirect("{$route}?n=1&i=" . base64_encode($model));
         } else {
             $this->set("data", $_POST);
             $this->set("errors", $model->invalidFields);
         }
     }
 }
示例#5
0
 public function package($package)
 {
     $subPaths = array_keys($_SESSION['menu']['sub'][$package]);
     \ntentan\Ntentan::redirect("{$package}/{$subPaths[0]}");
 }
示例#6
0
 public function logout()
 {
     $_SESSION = array();
     Ntentan::redirect($this->loginRoute);
 }