Beispiel #1
0
 public static function validatePassword($password, $encryptedPassword)
 {
     if (Util\Security::isValidPassword($password, $encryptedPassword)) {
         return true;
     }
     // legacy security
     if ($encryptedPassword == Util\Security::encrypt($password)) {
         return true;
     }
     return false;
 }
Beispiel #2
0
 public static function saveSecure(\Rebond\Core\User\Model $user, $type)
 {
     $ip = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : '';
     $secure = Util\Security::encrypt($user->getEmail() . $ip);
     if ($type == Model::REMEMBER) {
         $expire = time() + 60 * 60 * 24 * 7;
         // 7 days
         setcookie('signedUser', $secure, $expire, '/', Util\Nav::removePort(\Rebond\Config::getPath('siteUrl')));
         $options = [];
         $options['where'][] = ['user_id = ?', $user->getId()];
         $options['where'][] = ['type = ?', Model::REMEMBER];
         $userSecure = Data::load($options);
         if (isset($userSecure)) {
             return $userSecure;
         }
     }
     $userSecure = new Model();
     $userSecure->setUserId($user->getId());
     $userSecure->setSignIn($user->getEmail());
     $userSecure->setSecure($secure);
     $userSecure->setType($type);
     $userSecure->save();
     return $secure;
 }
Beispiel #3
0
 public function view()
 {
     $matchId = Util\Converter::toInt('id');
     $live = Util\Converter::toBool('live');
     $key = Util\Converter::toString('key');
     $options = [];
     $options['where'][] = 'match.id = ' . $matchId;
     $options['where'][] = 'match.status IN (' . MatchStatus::PLAYING . ', ' . MatchStatus::FINISHED . ')';
     $match = \Own\Bus\Match\Data::load($options);
     if (!isset($match)) {
         Util\Session::siteError('matchNotFound', null, '/match/schedule');
     }
     if ($this->player == null) {
         $this->player = new \Own\Bus\Player\Model();
     }
     $realKey = \Rebond\Util\Security::encrypt($match->getId());
     $hasViewed = $match->hasViewed($this->player->getId());
     $options = [];
     $options['where'][] = ['match_id = ?', $match->getId()];
     $options['order'][] = 'id';
     $matchLog = \Own\Bus\Log\Data::loadAll($options);
     if ($live && count($matchLog) == 0) {
         $live = false;
         Util\Session::set('siteError', Util\Lang::lang('noMatchLog'));
         $key = $realKey;
     }
     // auth
     if (!$live) {
         if ($match->getStatus() == MatchStatus::PLAYING) {
             Util\Session::siteError('matchPlaying', null, '/match/schedule');
         }
         if ($key != $realKey && !$hasViewed && count($matchLog) > 0 && ($this->player->getId() == $match->getPlayerMatch1()->getPlayerId() || $this->player->getId() == $match->getPlayerMatch2()->getPlayerId())) {
             $live = true;
         }
     }
     // view
     $this->setTpl();
     // main
     $tplMain = new Util\Template(Util\Template::SITE, ['www']);
     $tplMain->set('match', $match);
     if ($live) {
         $logs = [];
         foreach ($matchLog as $log) {
             $logs[] = $log->toArray();
         }
         $tplMain->set('logs', $logs);
         $isLive = !$hasViewed && $match->getModifiedDate() > time() - 1800 ? 1 : 0;
         $tplMain->set('isLive', $isLive);
         $tplMain->set('key', $realKey);
         $tpl = 'match-view-live';
         $this->tplMaster->set('bodyClass', 'body-' . $match->getSurface());
     } else {
         if ($key == $realKey) {
             $match->setViewed($this->player->getId());
             \Own\Bus\Notification\Data::updateViewedByPlayerIdAndMatchId($this->player->getId(), $match->getId());
         }
         $tpl = 'match-view';
         $options = [];
         $options['where'][] = ['match_id = ?', $match->getId()];
         $notification = \Own\Bus\Notification\Data::load($options);
         $tplMain->set('notification', $notification);
         $tplMain->set('serveLabels', \Own\Bus\PlayerMatch\Service::getServeLabels());
         $tplMain->set('player1ServeStats', \Own\Bus\PlayerMatch\Service::getServeStats($match->getPlayerMatch1()));
         $tplMain->set('player2ServeStats', \Own\Bus\PlayerMatch\Service::getServeStats($match->getPlayerMatch2()));
         $tplMain->set('returnLabels', \Own\Bus\PlayerMatch\Service::getReturnLabels());
         $tplMain->set('player1ReturnStats', \Own\Bus\PlayerMatch\Service::getReturnStats($match->getPlayerMatch1()));
         $tplMain->set('player2ReturnStats', \Own\Bus\PlayerMatch\Service::getReturnStats($match->getPlayerMatch2()));
         $tplMain->set('otherLabels', \Own\Bus\PlayerMatch\Service::getOtherLabels());
         $tplMain->set('player1OtherStats', \Own\Bus\PlayerMatch\Service::getOtherStats($match->getPlayerMatch1()));
         $tplMain->set('player2OtherStats', \Own\Bus\PlayerMatch\Service::getOtherStats($match->getPlayerMatch2()));
         $tplMain->set('attitudeLabels', \Own\Bus\PlayerMatch\Service::getAttitudeLabels());
         $tplMain->set('player1AttitudeStats', \Own\Bus\PlayerMatch\Service::getAttitudeStats($match->getPlayerMatch1()));
         $tplMain->set('player2AttitudeStats', \Own\Bus\PlayerMatch\Service::getAttitudeStats($match->getPlayerMatch2()));
         $tplMain->set('mentalLabels', \Own\Bus\PlayerMatch\Service::getMentalLabels());
         $tplMain->set('player1MentalStats', \Own\Bus\PlayerMatch\Service::getMentalStats($match->getPlayerMatch1()));
         $tplMain->set('player2MentalStats', \Own\Bus\PlayerMatch\Service::getMentalStats($match->getPlayerMatch2()));
         $tplMain->set('shotLabels', \Own\Bus\PlayerMatch\Service::getShotLabels());
         $tplMain->set('player1ShotStats', \Own\Bus\PlayerMatch\Service::getShotStats($match->getPlayerMatch1()));
         $tplMain->set('player2ShotStats', \Own\Bus\PlayerMatch\Service::getShotStats($match->getPlayerMatch2()));
         $tplMain->set('notificationCount', \Own\Bus\Notification\Data::countByPlayerId($this->player->getId()));
     }
     // layout
     $this->tplLayout->set('column1', $tplMain->render($tpl));
     // template
     $this->tplMaster->set('layout', $this->tplLayout->render('layout-center'));
     return $this->tplMaster->render('tpl-default');
 }
Beispiel #4
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');
 }