Ejemplo n.º 1
0
 public function listUser()
 {
     if (!$this->hasPrivilege('admin.user')) {
         return $this->noPrivilege('admin.user');
     }
     $json = [];
     $json['result'] = ResultType::ERROR;
     // check
     $hashParam = Converter::string('hash', 'post');
     $hash = explode('/', $hashParam);
     $status = isset($hash[0]) && $hash[0] != '' ? $hash[0] : 'active';
     $page = isset($hash[1]) && $hash[1] != '' ? (int) $hash[1] : 1;
     $options = [];
     if ($status == 'active') {
         $options['where'][] = 'user.status IN (0,1)';
     } else {
         $options['where'][] = 'user.status = 2';
     }
     $userCount = \Rebond\Core\User\Data::count($options);
     // get user settings
     $userSettings = \Rebond\Cms\UserSettings\Data::loadByUserId($this->signedUser->getId());
     $listCount = 10;
     if (isset($userSettings)) {
         $listCount = (int) $userSettings->getPagingValue();
     }
     if ($page < 1) {
         $page = 1;
     }
     if ($page > ceil($userCount / $listCount) && $userCount > 0) {
         $page = ceil($userCount / $listCount);
     }
     // add paging and order
     $options['limit'][] = ($page - 1) * $listCount . ', ' . $listCount;
     $options['order'][] = 'user.modified_date DESC';
     $users = \Rebond\Core\User\Data::loadAll($options);
     $tpl = new Template(Template::MODULE, ['core', 'user']);
     $tpl->set('items', $users);
     $tplFilter = new Template(Template::MODULE, ['core', 'user']);
     $tplFilter->set('current', $page);
     $tplFilter->set('maxByPage', $listCount);
     $tplFilter->set('count', $userCount);
     $tplFilter->set('status', $status);
     $tplFilter->set('url', '#!/' . $status . '/');
     $tplLayout = new Template(Template::SITE, ['admin']);
     $tplLayout->set('column1', $tplFilter->render('filter-full'));
     $tplLayout->set('column2', $tpl->render('listing'));
     $json['result'] = ResultType::SUCCESS;
     $json['message'] = Lang::lang('listUpdated') . ' (' . count($users) . ')';
     $json['html'] = $tplLayout->render('layout-2-row');
     return json_encode($json);
 }
Ejemplo n.º 2
0
 public function index()
 {
     // check
     $this->db = new \Rebond\Util\Data();
     $this->authFile = \Rebond\Config::getPath('config') . 'authentication.txt';
     $this->queryTables = 'SELECT COUNT(TABLE_NAME) FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = \'' . \Rebond\Config::getDb('name') . '\'';
     $this->queryCheckUser = '******';
     $this->info = [];
     $isAuth = Session::int('auth');
     $action = Converter::string('action');
     // action
     if ($isAuth == 0) {
         $this->step = 'auth';
         // check auth
         if (!file_exists($this->authFile)) {
             $auth = \Rebond\Util\Security::encrypt(time());
             File::save($this->authFile, 'w', $auth);
         } else {
             $auth = File::read($this->authFile, 'r');
         }
         if (isset($_POST['submitAuth'])) {
             if ($auth == $_POST['auth']) {
                 Session::set('auth', 1);
                 $isAuth = 1;
                 unlink($this->authFile);
                 $this->step = 'db';
                 $this->info[] = '<p class="bg-success">You have been authenticated!</p>';
             } else {
                 $this->info[] = '<p class="bg-error">The identification number you entered is incorrect. Please try again.</p>';
             }
         }
     }
     if ($isAuth == 1) {
         // check db
         $tableCount = $this->db->count($this->queryTables);
         $userTable = $this->db->selectOne($this->queryCheckUser);
         if ($tableCount != 0 && $tableCount !== self::TABLECOUNT) {
             $this->info[] = '<p class="bg-error">Your database contains ' . $tableCount . ' table(s). A fresh install of Rebond should contain ' . self::TABLECOUNT . ' tables. Please check your database name to make sure that you want to install Rebond in this database.</p>';
         }
         if (count($userTable) == 0) {
             $this->step = 'db';
             if ($action == 'db') {
                 $scripts = \Rebond\Util\File::getFiles('files/install');
                 sort($scripts);
                 foreach ($scripts as $script) {
                     $result = $this->db->runScript('files/install', $script);
                     if ($result['status'] == \Rebond\Core\ResultType::SUCCESS) {
                         $this->info[] = '<p>' . $script . '... success.</p>';
                     } else {
                         $this->info[] = '<p>' . $script . '... failed: <span class="error">' . $result['message'] . '</span></p>';
                         break;
                     }
                 }
                 $tableCount = $this->db->count($this->queryTables);
                 $userTable = $this->db->selectOne($this->queryCheckUser);
                 if (count($userTable) == 0) {
                     $this->info[] = '<p class="bg-error">The database has NOT been installed correctly. Please try to reinstall the database.</p>';
                 } else {
                     $this->info[] = '<p class="bg-success">The database has been installed successfully.</p>';
                     $this->step = 'db-ok';
                 }
             }
             // check user
         } else {
             if (\Rebond\Core\User\Data::count() == 0) {
                 $this->step = 'user';
                 $user = new \Rebond\Core\User\Model();
                 $userForm = new \Rebond\Core\User\Form($user);
                 if (isset($_POST['submitUser'])) {
                     if ($userForm->setFromPost()->validate()->isValid()) {
                         $user->setPassword(Security::encryptPassword($user->getPassword()));
                         $user->setIsAdmin(true);
                         $user->setIsDev(true);
                         $user->save();
                         $this->step = 'ready';
                     } else {
                         Session::set('adminError', $userForm->getValidation()->getMessage());
                     }
                 }
                 // ready
             } else {
                 $this->step = 'ready';
                 if ($action == 'launch') {
                     $adminPath = \Rebond\Config::getPath('admin');
                     $sitePath = \Rebond\Config::getPath('site');
                     rename($adminPath . 'index.php', $adminPath . 'index_install.php');
                     rename($adminPath . 'index_admin.php', $adminPath . 'index.php');
                     rename($sitePath . 'index.php', $sitePath . 'index_install.php');
                     rename($sitePath . 'index_cms.php', $sitePath . 'index.php');
                     $db = new \Rebond\Util\Data();
                     $db->backup('launch');
                     Session::kill('auth');
                     Session::setAndRedirect('signedUser', 1, '/configuration/site');
                 }
             }
         }
     }
     // menu
     $tplMenu = new Template(Template::SITE, ['admin', 'install']);
     $tplMenu->set('menuAuth', $this->step == 'auth' ? ' class="active"' : '');
     $tplMenu->set('menuDb', in_array($this->step, ['db', 'db-ok']) ? ' class="active"' : '');
     $tplMenu->set('menuUser', $this->step == 'user' ? ' class="active"' : '');
     $tplMenu->set('menuReady', $this->step == 'ready' ? ' class="active"' : '');
     // main
     $tplMain = new Template(Template::SITE, ['admin', 'install']);
     // layout
     $this->tplLayout->set('column1', $tplMenu->render('menu'));
     $this->tplLayout->add('column1', implode($this->info));
     if ($this->step == 'user') {
         if (!isset($user)) {
             $userForm = new \Rebond\Core\User\Form();
             $userForm->setFromPost();
         }
         $tplMain->set('form', $userForm);
     }
     $this->tplLayout->add('column1', $tplMain->render($this->step));
     // master
     $this->tplMaster->set('layout', $this->tplLayout->render('layout-1-col'));
     $this->tplMaster->set('jsLauncher', 'install');
     $this->tplMaster->addCss('/css/normalize.css');
     $this->tplMaster->addCss('/css/rebond.css');
     $this->tplMaster->addCss('/css/custom.css');
     $this->tplMaster->addJs('//code.jquery.com/jquery-2.1.3.min.js');
     $this->tplMaster->addJs('/js/rebond.js');
     $this->tplMaster->addJs('/js/custom.js');
     return $this->tplMaster->render('tpl-install');
 }