Пример #1
0
 public function index()
 {
     // auth
     Util\Auth::isAuthorized($this->signedUser, 'member', true, '/');
     $userForm = new \Rebond\Core\User\Form($this->signedUser, 'user');
     $playerForm = new \Own\Bus\Player\Form($this->player, 'player');
     // action
     $save = Util\Converter::toString('save', 'post');
     if (isset($save)) {
         if ($userForm->setFromPost()->validate()->isValid()) {
             if ($playerForm->setFromPost()->validate()->isValid()) {
                 $resultUpload = Util\Media::upload('avatarIduser', true);
                 if ($resultUpload['result'] == ResultType::ERROR) {
                     Util\Session::set('siteError', $resultUpload['message']);
                 } else {
                     if ($resultUpload['result'] == ResultType::SUCCESS) {
                         $this->signedUser->setAvatarId($resultUpload['mediaId']);
                     }
                     $this->signedUser->save();
                     $this->player->save();
                     Util\Session::siteSuccess('saved', '/profile');
                 }
             } else {
                 Util\Session::set('siteError', $playerForm->getValidation()->getMessage());
             }
         } else {
             Util\Session::set('siteError', $userForm->getValidation()->getMessage());
         }
     }
     // layout
     $tplPlayer = new Util\Template(Util\Template::MODULE, ['bus', 'player']);
     $tplPlayer->set('user', $userForm);
     $tplPlayer->set('player', $playerForm);
     return $this->response('tpl-default', ['title' => Util\Lang::lang('profile')], 'layout-home', ['column1' => $tplPlayer->render('editor')]);
 }
Пример #2
0
 public function index()
 {
     // auth
     Auth::isAdminAuthorized($this->signedUser, null, true, '/profile/sign-in');
     // prep
     $save = Converter::string('save', 'post');
     $form = new \Rebond\Core\User\Form($this->signedUser);
     // action
     if (isset($save)) {
         if ($form->setFromPost()->validate()->isValid()) {
             $obj = \Rebond\Util\Media::UploadForm('avatarId');
             if ($obj->result == ResultType::SUCCESS) {
                 $this->signedUser->setAvatarId($obj->id);
             }
             if ($obj->result != ResultType::ERROR) {
                 $this->signedUser->save();
                 Session::adminSuccess('saved', '/profile');
             } else {
                 Session::set('adminError', $obj->message);
             }
         } else {
             Session::set('adminError', $form->getValidation()->getMessage());
         }
     }
     // view
     $this->setTpl();
     $tplMain = new Template(Template::MODULE, ['core', 'user']);
     $tplMain->set('item', $form);
     // layout
     $this->tplLayout->set('column1', $tplMain->render('profile'));
     // master
     $this->tplMaster->set('layout', $this->tplLayout->render('layout-1-col'));
     $this->tplMaster->set('jsLauncher', 'profile');
     return $this->tplMaster->render('tpl-default');
 }
Пример #3
0
 public function register()
 {
     $signedUser = $this->app->user();
     // auth
     if (Util\Auth::isAuth($signedUser)) {
         header('Location: /profile');
         exit;
     }
     // check
     $user = new \Rebond\Core\User\Model();
     $form = new \Rebond\Core\User\Form($user);
     $tpl = new Util\Template(Util\Template::MODULE, ['app', 'User']);
     // register
     $register = Util\Converter::string('register', 'post');
     if (isset($register)) {
         if ($form->setFromPost()->validate()->isValid()) {
             $user->setStatus(0);
             $user->setPassword(Util\Security::encryptPassword($user->getPassword()));
             $avatarId = Util\Media::generateAvatar($user->getUsername());
             $user->setAvatarId($avatarId);
             $user->save();
             // send email
             if (Mail::register($this->app->site()->getTitle(), $user)) {
                 return $tpl->render('register-success');
             } else {
                 $user->setStatus(1);
                 $user->save();
                 $userRole = new \Rebond\Core\UserRole\Model();
                 $userRole->setUserId($user->getId());
                 $userRole->setRoleId(5);
                 // member
                 $userRole->save();
                 return $tpl->render('register-success-nomail');
             }
         } else {
             Session::set('siteError', $form->getValidation()->getMessage());
         }
     }
     // confirm email
     $confirm = Util\Converter::string('confirm');
     if (isset($confirm)) {
         $signedUser = \Rebond\Core\UserSecurity\Data::loadBySecure($confirm, \Rebond\Core\UserSecurity\Model::CONFIRM);
         if (isset($signedUser) && $signedUser->getId() != 0) {
             $userRole = new \Rebond\Core\UserRole\Model();
             $userRole->setUserId($signedUser->getId());
             $userRole->setRoleId(5);
             // member
             $userRole->save();
             Util\Session::set('allSuccess', Util\Lang::lang('hi', [$signedUser->getUsername()]));
             Util\Session::set('signedUser', $signedUser->getId());
             $this->app->setUser($signedUser);
             return $tpl->render('register-confirm');
         }
     }
     $tpl->set('item', $form);
     return $tpl->render('register');
 }
Пример #4
0
 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')]);
 }
Пример #5
0
 public function user_edit()
 {
     // auth
     Auth::isAdminAuthorized($this->signedUser, 'admin.user', true, '/user');
     // check
     $save = Converter::string('save', 'post');
     $id = \Rebond\Util\Converter::int('id');
     $user = \Rebond\Core\User\Data::loadById($id, true);
     $id = $user->getId();
     $form = new \Rebond\Core\User\Form($user);
     // action
     if (isset($save)) {
         Auth::isAdminAuthorized($this->signedUser, 'admin.user.edit', true, '/user/edit?id=' . $id);
         if ($form->setFromPost()->validate()->isValid()) {
             if ($user->getId() == 0) {
                 $user->setPassword(\Rebond\Util\Security::encryptPassword($user->getPassword()));
             }
             $user->save();
             $userSettings = \Rebond\Cms\UserSettings\Data::loadByUserId($user->getId());
             if (!isset($userSettings)) {
                 $userSettings = new \Rebond\Cms\UserSettings\Model();
                 $userSettings->setUserId($user->getId());
                 $userSettings->save();
             }
             Session::adminSuccess('saved', '/user');
         } else {
             Session::set('adminError', $form->getValidation()->getMessage());
         }
     }
     // 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)) {
         if ($id == 0) {
             $this->tplLayout->set('column1', $tplMain->render('register'));
         } else {
             $this->tplLayout->set('column1', $tplMain->render('editor'));
         }
     } else {
         $this->tplLayout->set('column1', $tplMain->render('view'));
     }
     // master
     $this->tplMaster->set('layout', $this->tplLayout->render('layout-1-col'));
     $this->tplMaster->set('jsLauncher', 'userEdit');
     return $this->tplMaster->render('tpl-default');
 }
Пример #6
0
 public function register()
 {
     $signedUser = $this->app->user();
     // auth
     if (Util\Auth::isAuth($signedUser)) {
         header('Location: /profile');
         exit;
     }
     // check
     $user = new \Rebond\Core\User\Model();
     $form = new \Rebond\Core\User\Form($user);
     $tpl = new Util\Template(Util\Template::MODULE, ['app', 'User']);
     // register
     $register = Util\Converter::toString('register', 'post');
     if (isset($register)) {
         if ($form->setFromPost()->validate(['username', 'email', 'password'])->isValid()) {
             $user->setStatus(0);
             $user->setPassword(Util\Security::encryptPassword($user->getPassword()));
             $resultUpload = Util\Media::upload($user->getUsername());
             if ($resultUpload['result'] == ResultType::ERROR) {
                 Util\Session::set('siteError', $resultUpload['message']);
             } else {
                 if ($resultUpload['result'] == ResultType::SUCCESS) {
                     $user->setAvatarId($resultUpload['mediaId']);
                 }
                 $user->save();
             }
             // send email
             if (Mail::register($this->app->site()->getTitle(), $user)) {
                 return $tpl->render('register-success');
             }
             // mail could not be sent
             $user->setStatus(1);
             $userRole = new \Rebond\Core\UserRole\Model();
             $userRole->setUserId($user->getId());
             $userRole->setRoleId(\Rebond\Core\Role\Model::MEMBER);
             $userRole->save();
             return $tpl->render('register-success-nomail');
         } else {
             Util\Session::set('siteError', $form->getValidation()->getMessage());
         }
     }
     // confirm email
     $confirm = Util\Converter::toString('confirm');
     if (isset($confirm)) {
         $signedUser = \Rebond\Core\UserSecurity\Service::getUserBySecure($confirm, \Rebond\Core\UserSecurity\Model::CONFIRM);
         if (isset($signedUser) && $signedUser->getId() != 0) {
             $userRole = new \Rebond\Core\UserRole\Model();
             $userRole->setUserId($signedUser->getId());
             $userRole->setRoleId(\Rebond\Core\Role\Model::MEMBER);
             $userRole->save();
             Util\Session::set('allSuccess', Util\Lang::lang('hi', [$signedUser->getUsername()]));
             Util\Session::set('signedUser', $signedUser->getId());
             $this->app->setUser($signedUser);
             return $tpl->render('register-confirm');
         }
     }
     $tpl->set('item', $form);
     return $tpl->render('register');
 }
Пример #7
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');
 }