Example #1
0
 public function sign_in()
 {
     // auth
     if (Auth::isAdminAuthorized($this->signedUser)) {
         Session::redirect('/');
     }
     // action
     $form = new \Rebond\Core\User\Form($this->signedUser);
     $form->signIn();
     if (Auth::isAdmin($form->getModel())) {
         Session::redirect('/');
     }
     if (Auth::isAuth($form->getModel())) {
         Session::setAndRedirect('siteError', Lang::lang('accessNonAuthorized'), 'http://' . \Rebond\Config::getPath('siteUrl'));
     }
     // view
     $this->setTpl();
     // main
     $tplMain = new Template(Template::MODULE, ['core', 'user']);
     $tplMain->set('item', $form);
     // master
     $this->tplMaster->set('column1', $tplMain->render('sign-in'));
     $this->tplMaster->set('jsLauncher', 'profile');
     return $this->tplMaster->render('tpl-signin');
 }
Example #2
0
 public function mastery()
 {
     // auth
     Util\Auth::isAuthorized($this->signedUser, 'member', false, '/profile/sign-in');
     \Own\Bus\Match\Data::checkMatchToView($this->player->getId());
     // params
     $form = true;
     $id = Util\Converter::toInt('id');
     if ($id == 0) {
         $player = $this->player;
     } else {
         $player = \Own\Bus\Player\Data::loadById($id);
         if (!isset($player)) {
             $player = $this->player;
         } else {
             if ($player->getId() != $this->player->getId()) {
                 $form = false;
             }
         }
     }
     $playerForm = new \Own\Bus\Player\Form($player);
     $save = Util\Converter::toString('save', 'post');
     if ($save != '') {
         $oldMastery = $this->player->getMasteryValues();
         $properties = \Own\Bus\Player\Service::getMasteryList();
         if (!$playerForm->setFromPost($properties)->validate($properties)->isValid()) {
             Util\Session::setAndRedirect('siteError', $playerForm->getValidation()->getMessage(), '/profile/mastery');
         }
         if (!$player->isValidMastery($oldMastery)) {
             Util\Session::setAndRedirect('siteError', 'Mastery skills could not be saved!', '/profile/mastery');
         }
         $player->save();
         Util\Session::setAndRedirect('siteSuccess', 'Mastery skills saved', '/profile/mastery');
     }
     // view
     $this->setTpl();
     // form
     $tplForm = new Util\Template(Util\Template::MODULE, ['bus', 'player']);
     $tplForm->set('form', $form);
     // layout
     $tplForm->set('item', $playerForm);
     $this->tplLayout->set('column1', $tplForm->render('form-mastery'));
     // template
     $this->tplMaster->set('layout', $this->tplLayout->render('layout-center'));
     return $this->tplMaster->render('tpl-default');
 }
Example #3
0
 public function tpl_edit()
 {
     // auth
     Util\Auth::isAdminAuthorized($this->signedUser, 'admin.designer', true, '/');
     // check
     $file = Util\Converter::string('f');
     $app = Util\Converter::string('app');
     $save = Util\Converter::string('save', 'post');
     if (empty($file)) {
         Util\Session::adminError('itemNotFound', [$file], '/designer/tpl');
     }
     $validator = Util\Validate::validateFilename('file', $file, true);
     if (!$validator->isValid()) {
         Util\Session::setAndRedirect('adminError', $validator->getMessage(), '/designer/tpl');
     }
     $filePath = FULL_PATH . 'views/www/';
     if (!empty($app)) {
         $filePath = FULL_PATH . 'Rebond/App/' . $app . '/template/';
         $validator = Util\Validate::validateAlphaNumeric('app', $app, true);
         if (!$validator->isValid()) {
             Util\Session::setAndRedirect('adminError', $validator->getMessage(), '/designer/tpl');
         }
     }
     if (!file_exists($filePath)) {
         Util\Session::adminError('itemNotFound', [$filePath], '/designer/tpl');
     }
     // action
     if (isset($save)) {
         $filePost = Util\Converter::string('file', 'post');
         $tplFile = Util\Converter::string('tpl-file', 'post');
         $appPost = Util\Converter::string('app', 'post');
         $file = FULL_PATH . 'views/' . \Rebond\Config::getPath('siteFolder') . '/' . $filePost;
         if (!empty($appPost)) {
             $file = \Rebond\Config::getPath('rebond') . 'App/' . $appPost . '/template/' . $filePost;
         }
         if (!isset($file) || Util\File::getExtension($file) != 'tpl') {
             Util\Session::adminError('fileNotFoundOrValid', [$file], '/designer/css');
         }
         if (!copy($file, Util\File::getNoExtension($file) . '-' . Util\Format::date(time(), 'string') . '.bak')) {
             Util\Session::adminError('itemNotCopied', [$file], '/designer/css');
         }
         file_put_contents($file, $tplFile);
         Util\Session::adminSuccess('saved', '/designer/tpl');
     }
     // view
     $this->setTpl();
     // main
     $tplMain = new Util\Template(Util\Template::SITE, ['admin', 'designer']);
     $tplMain->set('file', $file);
     $tplMain->set('app', $app);
     $tplMain->set('filePath', $filePath);
     $tplMain->set('editable', Util\File::getExtension($file) == 'tpl');
     // layout
     $this->tplLayout->set('column1', $tplMain->render('tpl-form'));
     // master
     $this->tplMaster->set('layout', $this->tplLayout->render('layout-1-col'));
     $this->tplMaster->set('jsLauncher', 'designerTpl');
     $this->tplMaster->addCss('/css/codemirror.css');
     $this->tplMaster->addJs('/js/codemirror/codemirror.js');
     $this->tplMaster->addJs('/js/codemirror/htmlmixed.js');
     $this->tplMaster->addJs('/js/codemirror/xml.js');
     $this->tplMaster->addJs('/js/codemirror/clike.js');
     $this->tplMaster->addJs('/js/codemirror/php.js');
     return $this->tplMaster->render('tpl-default');
 }
Example #4
0
 public function index()
 {
     // auth
     Util\Auth::isAuthorized($this->signedUser, 'member', false, '/profile/sign-in');
     \Own\Bus\Match\Data::getCurrentMatch($this->player->getId(), [1, 2, 3]);
     $playLeague = Util\Converter::toBool('league');
     $playPractice = Util\Converter::toString('play', 'post');
     $lastMatchPlayed = (new \Rebond\Util\DateTime())->getTimestamp() - $this->player->getLastMatchPlayed()->getTimestamp();
     // minimum in 2 minutes, maximum 10 matches per day
     $scheduled = $lastMatchPlayed > Engine::DAY * 60 * 6 ? 120 : Engine::DAY * 60 * 6 - $lastMatchPlayed;
     $options = [];
     $options['where'][] = 'configuration.property = \'nextMonth\'';
     $nextMonth = \Own\Bus\Configuration\Data::load($options);
     if ($playLeague && time() + $scheduled > (int) $nextMonth->getValue()) {
         Util\Session::setAndRedirect('siteError', Util\Lang::lang('leagueMonthFinished'), '/match');
     }
     if ($playLeague || $playPractice != '') {
         $match = new \Own\Bus\Match\Model();
         $playerMatch1 = new \Own\Bus\PlayerMatch\Model();
         $playerMatch2 = new \Own\Bus\PlayerMatch\Model();
         if ($playLeague) {
             $match->setSurface($this->player->getLeague()->getSurface());
             $match->setType(MatchType::LEAGUE);
             $match->setLeagueId($this->player->getLeagueId());
             $match->setBestOfSets($this->player->getLeague()->getBestOfSets());
             $player2 = \Own\Bus\Player\Data::searchByLeague($this->player->getId(), $this->player->getLeagueId());
         } else {
             $surface = Util\Converter::toInt('surface', 'post');
             $level = Util\Converter::toInt('level', 'post');
             if (!in_array($level, [-1, 0, 1])) {
                 $level = 0;
             }
             $match->setType(MatchType::PRACTICE);
             $match->setSurface($surface);
             $player2 = \Own\Bus\Player\Data::searchByLevel($level, $this->player->getExperience(), $this->player->getId());
         }
         if (!isset($player2)) {
             Util\Session::setAndRedirect('siteError', Util\Lang::lang('noPlayerFound'), '/match');
         }
         \Own\Bus\Player\Data::updateIsInMatch($this->player->getId(), $player2->getId());
         $playerMatch1->setPlayerId($this->player->getId());
         $playerMatch1->setLevel($this->player->calculateLevel());
         $playerMatch1->save();
         $playerMatch2->setPlayerId($player2->getId());
         $playerMatch2->setLevel($player2->calculateLevel());
         $playerMatch2->save();
         $match->setPlayerMatch1Id($playerMatch1->getId());
         $match->setPlayerMatch2Id($playerMatch2->getId());
         $scheduledDate = \Rebond\Util\DateTime::createFromTimestamp(time() + $scheduled);
         $match->setScheduled($scheduledDate);
         $match->setStatus(MatchStatus::READY);
         $match->save();
         Util\Session::setAndRedirect('siteSuccess', 'Match scheduled ' . $scheduledDate->format(), '/match/vs?matchId=' . $match->getId());
     }
     // view
     $this->setTpl();
     // main
     $tplMain = new Util\Template(Util\Template::SITE, ['www']);
     $tplMain->set('surface', [1 => 'Clay', 2 => 'Grass', 3 => 'Hard']);
     $tplMain->set('level', [-1 => Util\Lang::lang('opponentWeak'), 0 => Util\Lang::lang('opponentEqual'), 1 => Util\Lang::lang('opponentStrong')]);
     $tplMain->set('league', $this->player->getLeague());
     $tplMain->set('scheduled', $scheduled);
     // layout
     $this->tplLayout->set('column1', $tplMain->render('match-play'));
     // template
     $this->tplMaster->set('layout', $this->tplLayout->render('layout-center'));
     return $this->tplMaster->render('tpl-default');
 }
Example #5
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');
 }