Example #1
0
 public function buy_credit()
 {
     // auth
     Util\Auth::isAuthorized($this->signedUser, 'member', true, '/');
     $playerForm = new \Own\Bus\Player\Form($this->player, 'player');
     $credits = $this->player->getCredits();
     $this->player->setCredits(0);
     // action
     $add = Util\Converter::toString('add', 'post');
     if (isset($add)) {
         $creditValidation = ['required' => true, 'integer' => true, 'minValue' => 1, 'maxValue' => 20];
         $playerForm->setFromPost(['credits']);
         $fieldCredits = Util\Validate::validate('credits', $playerForm->getModel()->getCredits(), $creditValidation);
         $validation = new \Rebond\Core\Form();
         $validation->addField($fieldCredits);
         $playerForm->setValidation($validation);
         if ($playerForm->getValidation()->isValid()) {
             $this->player->addCredits($credits);
             $this->player->save();
             Util\Session::siteSuccess('creditsBought', '/profile');
         } else {
             Util\Session::set('siteError', $playerForm->getValidation()->getMessage());
         }
     }
     // layout
     $tplPlayer = new Util\Template(Util\Template::MODULE, ['bus', 'player']);
     $tplPlayer->set('credits', $credits);
     $tplPlayer->set('player', $playerForm);
     return $this->response('tpl-default', ['title' => Util\Lang::lang('profile')], 'layout-home', ['column1' => $tplPlayer->render('buy-credit')]);
 }
Example #2
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());
     }
 }
Example #3
0
 public function validateFriendlyurl()
 {
     $v = Util\Validate::validate('friendlyUrl', $this->getModel()->getFriendlyUrl(), $this->friendlyUrlValidator);
     if ($v->getResult() == ResultType::ERROR) {
         return $v;
     }
     $options = [];
     $options['where'][] = ['page.friendly_url = ?', $this->getModel()->getFriendlyUrl()];
     $options['where'][] = ['page.id != ?', $this->getModel()->getId()];
     $options['where'][] = 'page.status IN (0,1)';
     $exist = Data::count($options);
     if ($exist >= 1) {
         $v->setResult(ResultType::ERROR);
         $v->setMessage('a page already exists with this url friendly title');
     }
     return $v;
 }
Example #4
0
 public function validateUpload()
 {
     $v = Util\Validate::validate('upload', $this->getModel()->getUpload(), $this->uploadValidator);
     if ($v->getResult() == ResultType::ERROR) {
         return $v;
     }
     $options = [];
     $options['where'][] = ['media.upload = ?', $this->getModel()->getUpload()];
     $options['where'][] = ['media.id != ?', $this->getModel()->getId()];
     $options['where'][] = 'media.status IN (0,1)';
     $exist = Data::count($options);
     if ($exist >= 1) {
         $v->setResult(ResultType::ERROR);
         $v->setMessage('a media already exists with this url');
     }
     return $v;
 }
Example #5
0
 public function validateTitle()
 {
     $v = Util\Validate::validate('title', $this->getModel()->getTitle(), $this->titleValidator);
     if ($v->getResult() == ResultType::ERROR) {
         return $v;
     }
     $db = new Util\Data();
     $options = [];
     $options['where'][] = ['folder.title = ?', $this->getModel()->getTitle()];
     $options['where'][] = ['folder.folderId != ?', $this->getModel()->getId()];
     $exist = $db->count($options);
     if ($exist >= 1) {
         $v->setResult(ResultType::ERROR);
         $v->setMessage('a folder already exists with this name');
     }
     return $v;
 }
Example #6
0
 public function edit()
 {
     // auth
     Util\Auth::isAuthorized($this->signedUser, 'member', false, '/profile/sign-in');
     $playerForm = new \Own\Bus\Player\Form($this->player);
     $save = Util\Converter::toString('save', 'post');
     if ($save != '') {
         $properties = ['country', 'hand', 'toss', 'acceptChallenge', 'sendNotificationEmail'];
         $playerForm->setFromPost($properties)->validate($properties);
         $fieldAvatar = Util\Validate::validate('avatar', $playerForm->getModel()->getUser()->getAvatarId(), ['media' => false, 'image' => true]);
         $playerForm->getValidation()->addField($fieldAvatar);
         if (!$playerForm->getValidation()->isValid()) {
             Util\Session::set('siteError', $playerForm->getValidation()->getMessage());
         } else {
             $this->player->save();
             $obj = Util\Media::uploadForm('avatarId');
             if ($obj->result == ResultType::SUCCESS) {
                 $this->signedUser->setAvatarId($obj->id);
             }
             if ($obj->result != ResultType::ERROR) {
                 $this->signedUser->save();
             } else {
                 Util\Session::set('siteError', $obj->message);
             }
             Util\Session::setAndRedirect('siteSuccess', 'Profile saved', '/profile');
         }
     }
     // view
     $this->setTpl();
     // main
     $tplMain = new Util\Template(Util\Template::MODULE, ['bus', 'player']);
     $tplMain->set('item', $playerForm);
     // layout
     $this->tplLayout->set('column1', $tplMain->render('editor-site'));
     // template
     $this->tplMaster->set('layout', $this->tplLayout->render('layout-center'));
     return $this->tplMaster->render('tpl-default');
 }
Example #7
0
 public function validateStatus()
 {
     return Util\Validate::validate('status', $this->getModel()->getStatus(), $this->statusValidator);
 }
Example #8
0
 public function validatePermission()
 {
     return Util\Validate::validate('permission', $this->getModel()->getPermissionId(), $this->permissionValidator);
 }
Example #9
0
 public function validateDisplayOrder()
 {
     return Util\Validate::validate('displayOrder', $this->getModel()->getDisplayOrder(), $this->displayOrderValidator);
 }
Example #10
0
 public function validateDescription()
 {
     return Util\Validate::validate('description', $this->getModel()->getDescription(), $this->descriptionValidator);
 }
Example #11
0
 public function validatePaging()
 {
     return Util\Validate::validate('paging', $this->getModel()->getPaging(), $this->pagingValidator);
 }
Example #12
0
 private function validEntity($entity)
 {
     $v = Validate::validate('entity', $entity, ['required' => true, 'name' => true]);
     if ($v->isValid()) {
         return true;
     }
     return false;
 }
Example #13
0
 public function validateVersion()
 {
     return Util\Validate::validate('version', $this->getModel()->getVersion(), $this->versionValidator);
 }
Example #14
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 #15
0
 public function validateType()
 {
     return Util\Validate::validate('type', $this->getModel()->getType(), $this->typeValidator);
 }
Example #16
0
 public function validateRole()
 {
     return Util\Validate::validate('role', $this->getModel()->getRoleId(), $this->roleValidator);
 }