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()); } }
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')]); }
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; }
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; }
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; }
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'); }
public function validateStatus() { return Util\Validate::validate('status', $this->getModel()->getStatus(), $this->statusValidator); }
public function validatePermission() { return Util\Validate::validate('permission', $this->getModel()->getPermissionId(), $this->permissionValidator); }
public function validateDisplayOrder() { return Util\Validate::validate('displayOrder', $this->getModel()->getDisplayOrder(), $this->displayOrderValidator); }
public function validateDescription() { return Util\Validate::validate('description', $this->getModel()->getDescription(), $this->descriptionValidator); }
public function validatePaging() { return Util\Validate::validate('paging', $this->getModel()->getPaging(), $this->pagingValidator); }
private function validEntity($entity) { $v = Validate::validate('entity', $entity, ['required' => true, 'name' => true]); if ($v->isValid()) { return true; } return false; }
public function validateVersion() { return Util\Validate::validate('version', $this->getModel()->getVersion(), $this->versionValidator); }
public function validateType() { return Util\Validate::validate('type', $this->getModel()->getType(), $this->typeValidator); }
public function validateRole() { return Util\Validate::validate('role', $this->getModel()->getRoleId(), $this->roleValidator); }