Exemplo n.º 1
0
 public static function isAuthorized(\Rebond\Core\User\Model $user, $permission = null, $show = true, $redirect = null)
 {
     if (!isset($permission) || $permission == '') {
         return true;
     }
     if (!self::isAuth($user)) {
         if (isset($redirect)) {
             header('Location: ' . $redirect);
             exit;
         }
         return false;
     }
     $auth = \Rebond\Core\User\Data::hasAccess($user->getId(), $permission, false);
     if ($auth != 0) {
         return true;
     }
     if ($show) {
         Session::add('siteError', Lang::lang('errorAccess', [$permission]));
     }
     Log::log(Error::NOT_ENOUGH_PRIVILEGE, Lang::lang('errorAccess', [$permission]), __FILE__, __LINE__);
     if (isset($redirect)) {
         header('Location: ' . $redirect);
         exit;
     }
     return false;
 }
Exemplo n.º 2
0
 public function getUser($createIfNotExist = false)
 {
     if (!isset($this->user)) {
         $this->user = \Rebond\Core\User\Data::loadById($this->userId, $createIfNotExist);
     }
     return $this->user;
 }
Exemplo n.º 3
0
 public function changePassword($redirect, $checkCurrentPassword = true)
 {
     $currentPassword = $this->getModel()->getPassword();
     $this->setFromPost();
     $newPassword = Util\Converter::string('passwordnew', 'post');
     $fields = [];
     $fields['token'] = $this->validateToken();
     if ($checkCurrentPassword) {
         $fields['password'] = $this->validatePassword();
     }
     $fields['passwordnew'] = Util\Validate::validate('passwordnew', $newPassword, ['password' => true, 'required' => true, 'minLength' => 4, 'maxLength' => 40, 'different' => $this->getModel()->getPassword()]);
     $this->getValidation()->setFields($fields);
     if ($this->getValidation()->isValid()) {
         if (!$checkCurrentPassword || Service::validatePassword($currentPassword, $this->getModel()->getPassword())) {
             $this->getModel()->setPassword(Util\Security::encryptPassword($newPassword));
             \Rebond\Core\User\Data::savePassword($this->getModel());
             \Rebond\Core\UserSecurity\Data::deleteSecure($this->getModel()->getId(), \Rebond\Core\UserSecurity\Model::RESET);
             Util\Session::allSuccess('passwordChanged', $redirect);
         } else {
             Util\Session::set('allError', Util\Lang::lang('errorWrongPassword'));
         }
     } else {
         Util\Session::set('allError', $this->getValidation()->getMessage());
     }
 }
Exemplo n.º 4
0
Arquivo: Mail.php Projeto: vincium/lot
 public static function send($playerId, $notification)
 {
     $options = [];
     $options['clearSelect'] = true;
     $options['select'][] = \Own\Bus\Player\Data::getList(['id', 'user_id', 'username']);
     $options['select'][] = \Rebond\Core\User\Data::getList(['id', 'email'], 'player_user');
     $options['join'][] = 'core_user player_user ON player_user.id = player.user_id';
     $options['where'][] = 'send_notification_email = 1';
     $options['where'][] = ['player.id = ?', $playerId];
     $player = \Own\Bus\Player\Data::load($options);
     if (!isset($player)) {
         return false;
     }
     // send email
     $app = \Rebond\App::instance();
     $tpl = new Util\Template(Util\Template::MODULE, ['bus', 'notification']);
     $tpl->set('url', 'http://' . \Rebond\Config::getPath('siteUrl'));
     $tpl->set('player', $player);
     $tpl->set('notification', $notification);
     $tplMail = new Util\Template(Util\Template::SITE, ['mail']);
     $tplMail->set('title', Util\Lang::lang('notification'));
     $tplMail->set('site', $app->site()->getTitle());
     $tplMail->set('url', 'http://' . \Rebond\Config::getPath('siteUrl'));
     $tplMail->set('layout', $tpl->render('notification'));
     $message = \Swift_Message::newInstance()->setContentType('text/html')->setSubject($app->site()->getTitle() . ' - ' . Util\Lang::lang('notification'))->setFrom(\Rebond\Config::getMail('email'))->setTo($player->getUser()->getEmail())->setBody($tplMail->render('tpl-default'));
     return Util\Mail::send($message);
 }
Exemplo n.º 5
0
 public function loadOwnBookings()
 {
     $isAllowed = Util\Auth::isAuthorized($this->signedUser, 'member', false);
     $json = [];
     $json['result'] = \Rebond\Core\ResultType::ERROR;
     if (!$isAllowed) {
         $json['message'] = Util\Lang::lang('accessNonAuthorized');
         return json_encode($json);
     }
     $weekAgo = new \DateTime();
     $weekAgo = $weekAgo->sub(new \DateInterval('P7D'));
     $weekAgo = $weekAgo->format('Y-m-d');
     $options = [];
     $options['select'][] = \Own\Bus\Player\Data::getList(['id'], 'book_player1');
     $options['select'][] = \Rebond\Core\User\Data::getList(['id', 'username', 'firstname', 'lastname'], 'book_player1_id');
     $options['select'][] = \Own\Bus\Player\Data::getList(['id'], 'book_player2');
     $options['select'][] = \Rebond\Core\User\Data::getList(['id', 'username', 'firstname', 'lastname'], 'book_player2_id');
     $options['join'][] = 'bus_player book_player1 ON book_player1.id = book.player1_id';
     $options['join'][] = 'core_user book_player1_id ON book_player1_id.id = book_player1.id';
     $options['join'][] = 'bus_player book_player2 ON book_player2.id = book.player2_id';
     $options['join'][] = 'core_user book_player2_id ON book_player2_id.id = book_player2.id';
     $options['where'][] = ['player1_id = ? OR player2_id = ?', $this->player->getId(), $this->player->getId()];
     $options['where'][] = ['booking_date > ?', $weekAgo];
     $options['limit'][] = 5;
     $options['order'][] = 'booking_date';
     $ownBookings = Book\Data::loadAll($options);
     $tplBook = new Util\Template(Util\Template::MODULE, ['bus', 'book']);
     $tplBook->set('items', $ownBookings);
     $tplBook->set('playerId', $this->player->getId());
     $json['html'] = $tplBook->render('own-bookings');
     $json['result'] = \Rebond\Core\ResultType::SUCCESS;
     return json_encode($json);
 }
Exemplo n.º 6
0
Arquivo: Form.php Projeto: vincium/lot
 public function buildUser()
 {
     $options = [];
     $options['clearSelect'] = true;
     $options['select'][] = \Rebond\Core\User\Data::getList(['id', 'username']);
     $models = \Rebond\Core\User\Data::loadAll($options);
     return Util\Form::buildDropdownList('userId' . $this->unique, $models, 'id', 'username', $this->getModel()->getUserId(), true);
 }
Exemplo n.º 7
0
 public function buildId()
 {
     $options = [];
     $options['clearSelect'] = true;
     $options['select'][] = \Rebond\Core\User\Data::getList(['id', 'username']);
     $options['where'][] = 'status = 1';
     $models = \Rebond\Core\User\Data::loadAll($options);
     return Util\Form::buildDropdownList('id' . $this->unique, $models, 'id', 'username', $this->getModel()->getId(), $this->idValidator['primaryKey']);
 }
Exemplo n.º 8
0
 public static function loadRanking($type, $page)
 {
     $options = [];
     $options['clearSelect'] = true;
     $options['select'][] = Data::getList(['id', 'user_id', 'country', 'experience', 'username', 'tour_ranking', 'tour_point', 'tour_diff', 'race_ranking', 'race_point', 'race_diff']);
     $options['select'][] = \Rebond\Core\User\Data::getList(['id', 'avatar_id'], 'player_user');
     $options['select'][] = \Rebond\Core\Media\Data::getList([], 'player_user_avatar');
     $options['leftJoin'][] = 'core_user player_user ON player_user.id = player.user_id';
     $options['leftJoin'][] = 'core_media player_user_avatar ON player_user_avatar.id = player_user.avatar_id';
     $options['where'][] = 'player.active = 1';
     $options['order'][] = 'player.' . $type . '_ranking, player.created_date';
     $options['limit'][] = $page * 20 . ', 20';
     return \Own\Bus\Player\Data::loadAll($options);
 }
Exemplo n.º 9
0
Arquivo: Own.php Projeto: vincium/resa
 public function player()
 {
     Util\Auth::isAdminAuthorized($this->signedUser, 'member', true, '/');
     $playerId = Util\Converter::toInt('id');
     if (!isset($playerId)) {
         Util\Session::adminError('item.not.found', [Util\Lang::lang('player'), $playerId], '/own');
     }
     $user = \Rebond\Core\User\Data::loadById($playerId, true);
     $player = \Own\Bus\Player\Data::loadById($playerId, true);
     $userForm = new \Rebond\Core\User\Form($user);
     $playerForm = new \Own\Bus\Player\Form($player);
     // action
     $save = Util\Converter::toString('save', 'post');
     $membershipIds = Util\Converter::toArray('membership', 'post');
     if (isset($save)) {
         if ($user->getId() == 0) {
             $user->setUsername($user->getEmail());
             $user->setPassword(Util\Security::encryptPassword($user->getPassword()));
         }
         if ($userForm->setFromPost()->validate()->isValid()) {
             if ($playerForm->setFromPost()->validate()->isValid()) {
                 \Own\Bus\PlayerMembership\Data::deleteByPlayerId($player->getId());
                 $newMemberships = [];
                 if (isset($membershipIds)) {
                     foreach ($membershipIds as $membershipId) {
                         $playerMembership = new \Own\Bus\PlayerMembership\Model();
                         $playerMembership->setPlayerId($player->getId());
                         $playerMembership->setMembershipId($membershipId);
                         $newMemberships[] = $playerMembership;
                     }
                 }
                 \Own\Bus\PlayerMembership\Data::saveAll($newMemberships);
                 $user->save();
                 $player->save();
                 Util\Session::adminSuccess('saved', '/own/player?id=' . $user->getId());
             } else {
                 Util\Session::set('adminError', $playerForm->getValidation()->getMessage());
             }
         } else {
             Util\Session::set('adminError', $userForm->getValidation()->getMessage());
         }
     }
     $tplEditor = new Util\Template(Util\Template::SITE, ['admin']);
     $tplEditor->set('user', $userForm);
     $tplEditor->set('player', $playerForm);
     $tplInfo = new Util\Template(Util\Template::SITE, ['admin']);
     $tplInfo->set('user', $user);
     return $this->response('tpl-default', ['title' => Util\Lang::lang('own'), 'jsLauncher' => 'own'], 'layout-2-col', ['column1' => $tplEditor->render('player-editor'), 'column2' => $tplInfo->render('player-info')]);
 }
Exemplo n.º 10
0
 public static function loadByEmail($email, $password)
 {
     $user = Data::loadByEmail($email);
     if (!isset($user)) {
         return null;
     }
     if (!Util\Security::isValidPassword($password, $user->getPassword())) {
         // legacy security
         if ($user->getPassword() != Util\Security::encrypt($password)) {
             return null;
         }
         $user->setPassword(Util\Security::encryptPassword($password));
         \Rebond\Core\User\Data::savePassword($user);
         return $user;
     }
     return $user;
 }
Exemplo n.º 11
0
 public function ranking()
 {
     $id = Converter::toInt('id', 'get', $this->player->getLeagueId());
     $league = \Own\Bus\League\Data::loadById($id);
     if (!isset($league)) {
         $league = $this->player->getLeague();
     }
     // player not logged in
     if (!isset($league)) {
         Session::redirect('/league');
     }
     // view
     $this->setTpl();
     $cacheTime = $this->app->site()->getCacheTime();
     $cache = \Rebond\Util\Cache::getCache('league-ranking', $league->getId(), $cacheTime);
     if (isset($cache)) {
         // layout
         $this->tplLayout->set('column1', $cache);
     } else {
         $options = [];
         $options['clearSelect'] = true;
         $options['select'][] = \Own\Bus\Player\Data::getList(['id', 'user_id', 'country', 'experience', 'username', 'league_ranking', 'league_point', 'league_diff']);
         $options['select'][] = \Rebond\Core\User\Data::getList(['id', 'avatar_id'], 'player_user');
         $options['select'][] = \Rebond\Core\Media\Data::getList([], 'player_user_avatar');
         $options['leftJoin'][] = 'core_user player_user ON player_user.id = player.user_id';
         $options['leftJoin'][] = 'core_media player_user_avatar ON player_user_avatar.id = player_user.avatar_id';
         $options['where'][] = 'player.active = 1';
         $options['where'][] = 'player.league_id = ' . $league->getId();
         $options['order'][] = 'player.league_ranking, player.created_date';
         $players = \Own\Bus\Player\Data::loadAll($options);
         // main
         $tplMain = new Template(Template::SITE, ['www']);
         $tplMain->set('league', $league);
         $tplMain->set('player', $this->player);
         $tplMain->set('players', $players);
         // layout
         $cache = $tplMain->render('league-ranking');
         $this->tplLayout->set('column1', $cache);
         // cache
         \Rebond\Util\Cache::saveCache('league-ranking', $league->getId(), $cacheTime, $cache);
     }
     // template
     $this->tplMaster->set('layout', $this->tplLayout->render('layout-center'));
     return $this->tplMaster->render('tpl-default');
 }
Exemplo n.º 12
0
 public function user()
 {
     if (isset($this->signedUser)) {
         return $this->signedUser;
     }
     if ($this->step != Config::STEP_RUNNING) {
         return new \Rebond\Core\User\Model();
     }
     $session = Util\Session::int('signedUser');
     $cookie = Util\Converter::string('signedUser', 'cookie');
     if ($session != 0) {
         $this->signedUser = \Rebond\Core\User\Data::loadById($session);
     } else {
         if ($cookie != '') {
             $this->signedUser = \Rebond\Core\UserSecurity\Data::loadBySecure($cookie, \Rebond\Core\UserSecurity\Model::REMEMBER);
         }
     }
     if (isset($this->signedUser) && $this->signedUser->getId() != 0) {
         if ($this->signedUser->getIsDev()) {
             $this->setLogLevel(Config::ENV_LOCAL);
         }
         if ($session != $this->signedUser->getId()) {
             Util\Session::set('signedUser', $this->signedUser->getId());
         }
         return $this->signedUser;
     }
     return new \Rebond\Core\User\Model();
 }
Exemplo n.º 13
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');
 }
Exemplo n.º 14
0
 protected static function mapper(array $row, $alias = 'user_settings')
 {
     $model = new \Rebond\Cms\UserSettings\Model(false);
     if (isset($row[$alias . 'Id'])) {
         $model->setId($row[$alias . 'Id']);
     }
     if (isset($row[$alias . 'UserId'])) {
         $model->setUserId($row[$alias . 'UserId']);
         $model->setUser(\Rebond\Core\User\Data::join($row, $alias . '_user'));
     }
     if (isset($row[$alias . 'MediaView'])) {
         $model->setMediaView($row[$alias . 'MediaView']);
     }
     if (isset($row[$alias . 'MediaPaging'])) {
         $model->setMediaPaging($row[$alias . 'MediaPaging']);
     }
     if (isset($row[$alias . 'ContentPaging'])) {
         $model->setContentPaging($row[$alias . 'ContentPaging']);
     }
     if (isset($row[$alias . 'Paging'])) {
         $model->setPaging($row[$alias . 'Paging']);
     }
     return $model;
 }
Exemplo n.º 15
0
 public function uploadify()
 {
     $json = [];
     $json['result'] = ResultType::ERROR;
     // check
     $id = Converter::int('userId', 'post', 0);
     $this->signedUser = \Rebond\Core\User\Data::loadById($id);
     if (!isset($this->signedUser)) {
         $json['message'] = Lang::lang('accessNonAuthorized');
         return json_encode($json);
     }
     if (!$this->hasPrivilege('admin.media.upload')) {
         return $this->noPrivilege('admin.media.upload');
     }
     $folderId = Converter::int('folderId', 'post');
     $isSelectable = Converter::int('isSelectable', 'post', 1);
     if (!isset($folderId)) {
         $json['message'] = Lang::lang('errorInvalidParameters');
         return json_encode($json);
     }
     $upload = \Rebond\Util\Media::upload('', $_FILES['Filedata']);
     $originalName = $_FILES['Filedata']['name'];
     if ($upload == ResultType::ERROR) {
         $json['message'] = Lang::lang('errorFileUpload', [$originalName]);
         Log::log(Error::MEDIA_NOT_SAVED, $json['message'], __FILE__, __LINE__);
         return json_encode($json);
     }
     list($w, $h) = getimagesize(\Rebond\Config::getPath('media') . $upload);
     $ext = \Rebond\Util\File::getExtension(\Rebond\Config::getPath('media') . $upload);
     $noExt = \Rebond\Util\File::getNoExtension($originalName);
     $media = new \Rebond\Core\Media\Model();
     $media->setFolderId($folderId);
     $media->setTitle($noExt);
     $media->setAlt($noExt);
     $media->setOriginalFilename($originalName);
     $media->setExtension($ext);
     $media->setWidth($w);
     $media->setHeight($h);
     $media->setFilesize(filesize(\Rebond\Config::getPath('media') . $upload));
     $mimeType = new \finfo(FILEINFO_MIME_TYPE);
     $media->setMimetype($mimeType->file(\Rebond\Config::getPath('media') . $upload));
     $media->setUpload($upload);
     $media->setIsSelectable($isSelectable);
     $media->save();
     $json['result'] = ResultType::SUCCESS;
     $json['id'] = $media->getId();
     $json['message'] = Lang::lang('mediaUploaded', [$originalName]);
     return json_encode($json);
 }
Exemplo n.º 16
0
Arquivo: Data.php Projeto: vincium/lot
 private static function link($linkTournament = false, $linkLeague = false, $players = false, $needBothPlayers = true)
 {
     $join = 'join';
     if (!$needBothPlayers) {
         $join = 'leftJoin';
     }
     $option = [];
     $option['clearSelect'] = true;
     $options['select'][] = self::getList(['id', 'player_match1_id', 'player_match2_id', 'surface', 'current_set', 'best_of_sets', 'type', 'winner_id', 'position', 'tournament_id', 'league_id', 'status', 'scheduled']);
     $options['select'][] = \Own\Bus\PlayerMatch\Data::getList(['id', 'player_id', 'seed', 'has_viewed', 'set1', 'set2', 'set3', 'set4', 'set5', 'points', 'level'], 'match_player_match1');
     $options['select'][] = \Own\Bus\PlayerMatch\Data::getList(['id', 'player_id', 'seed', 'has_viewed', 'set1', 'set2', 'set3', 'set4', 'set5', 'points', 'level'], 'match_player_match2');
     $options['select'][] = \Own\Bus\Player\Data::getList(['id', 'username', 'user_id', 'country', 'experience'], 'match_player_match1_player');
     if ($players) {
         $options['select'][] = \Rebond\Core\User\Data::getList(['id', 'avatar_id'], 'match_player_match1_player_user');
         $options['select'][] = \Rebond\Core\Media\Data::getList([], 'match_player_match1_player_user_avatar');
     }
     $options['select'][] = \Own\Bus\Player\Data::getList(['id', 'username', 'user_id', 'country', 'experience'], 'match_player_match2_player');
     if ($players) {
         $options['select'][] = \Rebond\Core\User\Data::getList(['id', 'avatar_id'], 'match_player_match2_player_user');
         $options['select'][] = \Rebond\Core\Media\Data::getList([], 'match_player_match2_player_user_avatar');
     }
     if ($linkTournament) {
         $options['select'][] = \Own\Bus\Tournament\Data::getList(['id', 'title', 'size', 'classification'], 'match_tournament');
     }
     if ($linkLeague) {
         $options['select'][] = \Own\Bus\League\Data::getList(['id', 'title'], 'match_league');
     }
     $options[$join][] = 'bus_player_match match_player_match1 ON match_player_match1.id = match.player_match1_id';
     $options[$join][] = 'bus_player_match match_player_match2 ON match_player_match2.id = match.player_match2_id';
     $options[$join][] = 'bus_player match_player_match1_player ON match_player_match1_player.id = match_player_match1.player_id';
     if ($players) {
         $options['leftJoin'][] = 'core_user match_player_match1_player_user ON match_player_match1_player_user.id = match_player_match1_player.user_id';
         $options['leftJoin'][] = 'core_media match_player_match1_player_user_avatar ON match_player_match1_player_user_avatar.id = match_player_match1_player_user.avatar_id';
     }
     $options[$join][] = 'bus_player match_player_match2_player ON match_player_match2_player.id = match_player_match2.player_id';
     if ($players) {
         $options['leftJoin'][] = 'core_user match_player_match2_player_user ON match_player_match2_player_user.id = match_player_match2_player.user_id';
         $options['leftJoin'][] = 'core_media match_player_match2_player_user_avatar ON match_player_match2_player_user_avatar.id = match_player_match2_player_user.avatar_id';
     }
     if ($linkTournament) {
         $options['leftJoin'][] = 'bus_tournament match_tournament ON match_tournament.id = match.tournament_id';
     }
     if ($linkLeague) {
         $options['leftJoin'][] = 'bus_league match_league ON match_league.id = match.league_id';
     }
     return $options;
 }
Exemplo n.º 17
0
 public function past()
 {
     $page = Converter::toInt('page', 'get', 1);
     $options = [];
     $options['where'][] = 'tournament.status IN (3,4)';
     $options['where'][] = 'tournament.start_date < NOW()';
     $count = \Own\Bus\Tournament\Data::count($options);
     $options['clearSelect'] = true;
     $options['select'][] = \Own\Bus\Tournament\Data::getList(['id', 'title', 'size', 'classification', 'start_date', 'end_date', 'surface', 'winner_id']);
     $options['select'][] = \Own\Bus\Player\Data::getList(['id', 'username', 'user_id', 'country', 'experience'], 'tournament_winner');
     $options['select'][] = \Rebond\Core\User\Data::getList(['id', 'avatar_id'], 'tournament_winner_user');
     $options['select'][] = \Rebond\Core\Media\Data::getList([], 'tournament_winner_user_avatar');
     $options['join'][] = 'bus_player tournament_winner ON tournament_winner.id = tournament.winner_id';
     $options['leftJoin'][] = 'core_user tournament_winner_user ON tournament_winner_user.id = tournament_winner.user_id';
     $options['leftJoin'][] = 'core_media tournament_winner_user_avatar ON tournament_winner_user_avatar.id = tournament_winner_user.avatar_id';
     $options['order'][] = 'tournament.start_date DESC';
     $options['limit'][] = ($page - 1) * 20 . ', 20';
     $past = \Own\Bus\Tournament\Data::loadAll($options);
     $registeredIds = \Own\Bus\TournamentPlayer\Data::loadRegistered($this->player->getId());
     // view
     $this->setTpl();
     // filter
     $tplFilter = new Template(Template::SITE, ['www']);
     $tplFilter->set('current', $page);
     $tplFilter->set('count', $count);
     $tplFilter->set('url', '/tournament/past?page=');
     // main
     $tplMain = new Template(Template::SITE, ['www']);
     $tplMain->set('past', $past);
     $tplMain->set('registeredIds', $registeredIds);
     // layout
     $this->tplLayout->set('column1', $tplFilter->render('tour-past-filter'));
     $this->tplLayout->add('column1', $tplMain->render('tour-past'));
     // template
     $this->tplMaster->set('layout', $this->tplLayout->render('layout-center'));
     return $this->tplMaster->render('tpl-default');
 }
Exemplo n.º 18
0
 protected static function mapper(array $row, $alias = 'user_role')
 {
     $model = new \Rebond\Core\UserRole\Model(false);
     if (isset($row[$alias . 'UserId'])) {
         $model->setUserId($row[$alias . 'UserId']);
         $model->setUser(\Rebond\Core\User\Data::join($row, $alias . '_user'));
     }
     if (isset($row[$alias . 'RoleId'])) {
         $model->setRoleId($row[$alias . 'RoleId']);
         $model->setRole(\Rebond\Core\Role\Data::join($row, $alias . '_role'));
     }
     return $model;
 }
Exemplo n.º 19
0
 protected static function mapper(array $row, $alias = 'log')
 {
     $model = new \Rebond\Core\Log\Model(false);
     if (isset($row[$alias . 'Id'])) {
         $model->setId($row[$alias . 'Id']);
     }
     if (isset($row[$alias . 'Code'])) {
         $model->setCode($row[$alias . 'Code']);
     }
     if (isset($row[$alias . 'UserId'])) {
         $model->setUserId($row[$alias . 'UserId']);
         $model->setUser(\Rebond\Core\User\Data::join($row, $alias . '_user'));
     }
     if (isset($row[$alias . 'Ip'])) {
         $model->setIp($row[$alias . 'Ip']);
     }
     if (isset($row[$alias . 'RequestUri'])) {
         $model->setRequestUri($row[$alias . 'RequestUri']);
     }
     if (isset($row[$alias . 'Referer'])) {
         $model->setReferer($row[$alias . 'Referer']);
     }
     if (isset($row[$alias . 'Message'])) {
         $model->setMessage($row[$alias . 'Message']);
     }
     if (isset($row[$alias . 'Trace'])) {
         $model->setTrace($row[$alias . 'Trace']);
     }
     if (isset($row[$alias . 'File'])) {
         $model->setFile($row[$alias . 'File']);
     }
     if (isset($row[$alias . 'Line'])) {
         $model->setLine($row[$alias . 'Line']);
     }
     if (isset($row[$alias . 'Status'])) {
         $model->setStatus($row[$alias . 'Status']);
     }
     if (isset($row[$alias . 'CreatedDate'])) {
         $model->setCreatedDate($row[$alias . 'CreatedDate']);
     }
     if (isset($row[$alias . 'ModifiedDate'])) {
         $model->setModifiedDate($row[$alias . 'ModifiedDate']);
     }
     return $model;
 }
Exemplo n.º 20
0
 public function register()
 {
     $userGadget = new \Own\App\User\Gadget($this->app);
     $register = $userGadget->register();
     $this->signedUser = $this->app->user();
     if ($this->signedUser->getId() != 0) {
         $player = \Own\Bus\Player\Data::loadByUserId($this->signedUser->getId());
         if ($player == null) {
             $player = \Own\Bus\Player\Service::create($this->signedUser);
         }
         $player->setActive(true);
         $player->save();
     }
     $email = Util\Converter::toString('email', 'post');
     if (isset($email)) {
         $user = \Rebond\Core\User\Data::loadByEmail($email);
     }
     // view
     $this->setTpl();
     // layout
     $this->tplLayout->set('column1', $register);
     // template
     $this->tplMaster->set('layout', $this->tplLayout->render('layout-center'));
     return $this->tplMaster->render('tpl-default');
 }
Exemplo n.º 21
0
 public function buildPublisher()
 {
     $options = [];
     $options['clearSelect'] = true;
     $options['select'][] = \Rebond\Core\User\Data::getList(['id', 'title']);
     $models = \Rebond\Core\User\Data::loadAll($options);
     return Util\Form::buildDropdownList('publisherId' . $this->unique, $models, 'id', 'title', $this->getModel()->getPublisherId(), $this->publisherValidator['foreignKey']);
 }
Exemplo n.º 22
0
 protected static function mapper(array $row, $alias = 'feedback')
 {
     $model = new \Rebond\Core\Feedback\Model(false);
     if (isset($row[$alias . 'Id'])) {
         $model->setId($row[$alias . 'Id']);
     }
     if (isset($row[$alias . 'UserId'])) {
         $model->setUserId($row[$alias . 'UserId']);
         $model->setUser(\Rebond\Core\User\Data::join($row, $alias . '_user'));
     }
     if (isset($row[$alias . 'Title'])) {
         $model->setTitle($row[$alias . 'Title']);
     }
     if (isset($row[$alias . 'Type'])) {
         $model->setType($row[$alias . 'Type']);
     }
     if (isset($row[$alias . 'Description'])) {
         $model->setDescription($row[$alias . 'Description']);
     }
     if (isset($row[$alias . 'Status'])) {
         $model->setStatus($row[$alias . 'Status']);
     }
     if (isset($row[$alias . 'CreatedDate'])) {
         $model->setCreatedDate($row[$alias . 'CreatedDate']);
     }
     if (isset($row[$alias . 'ModifiedDate'])) {
         $model->setModifiedDate($row[$alias . 'ModifiedDate']);
     }
     return $model;
 }
Exemplo n.º 23
0
 protected static function mapper(array $row, $alias = 'user_security')
 {
     $model = new \Rebond\Core\UserSecurity\Model(false);
     if (isset($row[$alias . 'Id'])) {
         $model->setId($row[$alias . 'Id']);
     }
     if (isset($row[$alias . 'UserId'])) {
         $model->setUserId($row[$alias . 'UserId']);
         $model->setUser(\Rebond\Core\User\Data::join($row, $alias . '_user'));
     }
     if (isset($row[$alias . 'SignIn'])) {
         $model->setSignIn($row[$alias . 'SignIn']);
     }
     if (isset($row[$alias . 'Secure'])) {
         $model->setSecure($row[$alias . 'Secure']);
     }
     if (isset($row[$alias . 'Type'])) {
         $model->setType($row[$alias . 'Type']);
     }
     if (isset($row[$alias . 'CreatedDate'])) {
         $model->setCreatedDate($row[$alias . 'CreatedDate']);
     }
     return $model;
 }
Exemplo n.º 24
0
 public function forgotPassword()
 {
     $signedUser = $this->app->user();
     // auth
     if (Util\Auth::isAuth($signedUser)) {
         header('Location: /profile');
         exit;
     }
     $form = new \Rebond\Core\User\Form($signedUser);
     $tpl = new Util\Template(Util\Template::MODULE, ['app', 'User']);
     // action
     // request
     $requestForgotPassword = Util\Converter::toString('requestForgotPassword', 'post');
     if (isset($requestForgotPassword)) {
         $email = Util\Converter::toString('email', 'post');
         if ($email == '') {
             Util\Session::set(Util\Lang::lang('siteError', 'emptyEmailAddress'));
         } else {
             $user = \Rebond\Core\User\Data::loadByEmail($email);
             if (isset($user)) {
                 Util\Mail::resetPassword($this->app->site()->getTitle(), $user);
                 return $tpl->render('forgot-password-send');
             } else {
                 Util\Session::set('siteError', Util\Lang::lang('emailAddressNotFound'));
             }
         }
     }
     // reset password form
     $reset = Util\Converter::toString('reset');
     if (isset($reset)) {
         $user = \Rebond\Core\UserSecurity\Service::getUserBySecure($reset, \Rebond\Core\UserSecurity\Model::RESET);
         if (isset($user)) {
             $form = new \Rebond\Core\User\Form($user);
             // reset password
             $resetPassword = Util\Converter::toString('resetPassword', 'post');
             if (isset($resetPassword)) {
                 $form->changePassword('/profile', false);
             }
             $tpl = new Util\Template(Util\Template::MODULE, ['app', 'User']);
             $tpl->set('item', $form);
             $tpl->set('checkCurrentPassword', false);
             return $tpl->render('password-change');
         }
     }
     $tpl = new Util\Template(Util\Template::MODULE, ['app', 'User']);
     $tpl->set('item', $form);
     return $tpl->render('forgot-password');
 }
Exemplo n.º 25
0
 public function user_role()
 {
     // auth
     Auth::isAdminAuthorized($this->signedUser, 'admin.user', true, '/user');
     // check
     $id = \Rebond\Util\Converter::int('id');
     $save = \Rebond\Util\Converter::int('save', 'post');
     $roleIds = \Rebond\Util\Converter::arr('role', 'post');
     $user = \Rebond\Core\User\Data::loadById($id);
     if (!isset($user)) {
         Session::adminError('itemNotFound', [$id], '/user');
     }
     $form = new \Rebond\Core\User\Form($user);
     // action
     if (isset($save)) {
         Auth::isAdminAuthorized($this->signedUser, 'admin.user.edit', true, '/user/user-role?id=' . $id);
         \Rebond\Core\UserRole\Data::deleteByUserId($user->getId());
         $newRoles = [];
         if (isset($roleIds)) {
             foreach ($roleIds as $roleId) {
                 $userRole = new \Rebond\Core\UserRole\Model();
                 $userRole->setUserId($user->getId());
                 $userRole->setRoleId($roleId);
                 $newRoles[] = $userRole;
             }
         }
         \Rebond\Core\UserRole\Data::saveAll($newRoles);
         Session::adminSuccess('saved', '/user');
     }
     // view
     $this->setTpl();
     // main
     $tplMain = new Template(Template::MODULE, ['core', 'user']);
     $tplMain->set('item', $form);
     // layout
     if (Auth::isAdminAuthorized($this->signedUser, 'admin.user.edit', false)) {
         $this->tplLayout->set('column1', $tplMain->render('editor-role'));
     } else {
         // @todo create viewer-role template
         $this->tplLayout->set('column1', $tplMain->render('editor-role'));
     }
     // master
     $this->tplMaster->set('layout', $this->tplLayout->render('layout-1-col'));
     return $this->tplMaster->render('tpl-default');
 }
Exemplo n.º 26
0
 protected static function mapEntity(Model $model, $row, $alias = 'content')
 {
     if (isset($row[$alias . 'Id'])) {
         $model->setId($row[$alias . 'Id']);
     }
     if (isset($row[$alias . 'ModuleId'])) {
         $model->setModuleId($row[$alias . 'ModuleId']);
         $model->setModule(\Rebond\Cms\Module\Data::join($row, $alias . '_module'));
     }
     if (isset($row[$alias . 'ContentGroup'])) {
         $model->setContentGroup($row[$alias . 'ContentGroup']);
     }
     if (isset($row[$alias . 'FilterId'])) {
         $model->setFilterId($row[$alias . 'FilterId']);
         $model->setFilter(\Rebond\Cms\Filter\Data::join($row, $alias . '_filter'));
     }
     if (isset($row[$alias . 'AuthorId'])) {
         $model->setAuthorId($row[$alias . 'AuthorId']);
         $model->setAuthor(\Rebond\Core\User\Data::join($row, $alias . '_author'));
     }
     if (isset($row[$alias . 'PublisherId'])) {
         $model->setPublisherId($row[$alias . 'PublisherId']);
         $model->setPublisher(\Rebond\Core\User\Data::join($row, $alias . '_publisher'));
     }
     if (isset($row[$alias . 'Title'])) {
         $model->setTitle($row[$alias . 'Title']);
     }
     if (isset($row[$alias . 'UrlFriendlyTitle'])) {
         $model->setUrlFriendlyTitle($row[$alias . 'UrlFriendlyTitle']);
     }
     if (isset($row[$alias . 'UseExpiration'])) {
         $model->setUseExpiration($row[$alias . 'UseExpiration']);
     }
     if (isset($row[$alias . 'GoLiveDate'])) {
         $model->setGoLiveDate($row[$alias . 'GoLiveDate']);
     }
     if (isset($row[$alias . 'ExpiryDate'])) {
         $model->setExpiryDate($row[$alias . 'ExpiryDate']);
     }
     if (isset($row[$alias . 'PublishedDate'])) {
         $model->setPublishedDate($row[$alias . 'PublishedDate']);
     }
     if (isset($row[$alias . 'Version'])) {
         $model->setVersion($row[$alias . 'Version']);
     }
     if (isset($row[$alias . 'CreatedDate'])) {
         $model->setCreatedDate($row[$alias . 'CreatedDate']);
     }
     if (isset($row[$alias . 'ModifiedDate'])) {
         $model->setModifiedDate($row[$alias . 'ModifiedDate']);
     }
     return $model;
 }
Exemplo n.º 27
0
 public function validateEmail($checkExisting = true)
 {
     $vrf = Util\Validate::validate('email', $this->getModel()->getEmail(), $this->emailValidator);
     if ($vrf->getResult() == \Rebond\Core\ResultType::ERROR) {
         return $vrf;
     }
     if ($checkExisting && \Rebond\Core\User\Data::emailExists($this->getModel()->getEmail(), $this->getModel()->getId()) > 0) {
         $vrf->setResult(\Rebond\Core\ResultType::ERROR);
         $vrf->setMessage(Util\Lang::lang('emailExist'));
     }
     return $vrf;
 }