/** * Activate user account. * * @access public * @return View * @since 1.0.0 * @version 1.1.0, 2015-02-12 */ public function actionActivation() { // if user is logged, redirect to main page if (UserModel::isLogged()) { Route::factory('home')->redirectTo(); } // set page title $this->setTitle(__('Activate your new account')); // get code from URL $sCode = Router::getParam('code'); $bActivated = FALSE; // get activation code from DB $oResult = DB::query("SELECT c FROM \\Model\\User\\ActivationCode c WHERE c.code = :code")->param('code', $sCode)->single(); /* @var $oResult ActivationCodeModel */ // activate user if ($oResult instanceof ActivationCodeModel) { // Set user as activated $bActivated = TRUE; $oUser = $oResult->getUser(); $oUser->setActivation(TRUE); DB::flush(); // Remove activation code from DB DB::remove($oResult); DB::flush(); } // view return View::factory("user/frontend/register/activation")->bind('bActivated', $bActivated); }
/** * @access public * @since 1.0.0-dev, 2015-04-19 * @version 1.0.0-dev, 2015-04-19 */ public function actionDefault() { $this->setTitle(__('Sitemap')); $this->addBreadCrumb(__('Sitemap')); $aItems = []; $aItems[] = ['/', __('Front page')]; $aPages = \Plethora\DB::query("SELECT p FROM \\Model\\Page p WHERE p.published = 1")->execute(); foreach ($aPages as $oPage) { /* @var $oPage \Model\Page */ $aItems[] = [Route::factory('page')->path(['rewrite' => $oPage->getRewrite()]), $oPage->getTitle()]; } \Sitemap\SitemapGenerator::generate($aItems); return View::factory('sitemap/frontend/sitemap')->bind('aItems', $aItems); }
/** * Action used to do multileveled sort on model entities. * * @access public * @since 1.0.0-alpha * @version 1.0.0-alpha */ public function actionSortList() { // check access if (!\UserPermissions::hasPerm('backend_ajax_sort_list')) { Route::factory('home')->redirectTo(); } // @TODO: check permissions $sObjects = filter_input(INPUT_POST, 'objects'); $sModel = filter_input(INPUT_POST, 'model'); $aObjectsTmp = []; $aOrderNumber = []; // if list of objects is empty if (empty($sObjects)) { $this->setStatus('error'); return __('List of objects is empty.'); } // parse objects array from query string parse_str($sObjects, $aObjectsTmp); $aObjects = $aObjectsTmp['object']; // rewrite each object foreach ($aObjects as $iID => $sParentID) { if ($sParentID === 'null') { $sParentID = 0; } $iParentID = (int) $sParentID; if (!isset($aOrderNumber[$iParentID])) { $aOrderNumber[$iParentID] = 0; } $aObjects[$iID] = ['order_parent' => $iParentID, 'order' => $aOrderNumber[$iParentID]]; $aOrderNumber[$iParentID]++; } // check if particular model has `order` property if (!property_exists($sModel, 'order_number')) { $this->setStatus('error'); return __('Wrong node type.'); } // get all model instances $aEntities = DB::query('SELECT t FROM ' . $sModel . ' t WHERE t.id IN (:list)')->param('list', array_keys($aObjects))->execute(); foreach ($aEntities as $oEntity) { /* @var $oEntity ModelCore|ModelCore\Traits\Sortable */ $aObjData = $aObjects[$oEntity->getId()]; $oEntity->setOrderNumber($aObjData['order']); $oEntity->setOrderParent($aObjData['order_parent']); $oEntity->save(); DB::flush(); } return 'saved'; }
/** * ACTION - Particular page. * * @access public * @return View * @throws Exception\Code404 * @throws Exception\Fatal * @since 1.0.1-dev, 2015-04-11 * @version 1.2.0-dev */ public function actionPage() { $query = DB::query('SELECT p FROM \\Model\\Page p WHERE p.rewrite = :rewrite'); $query->param('rewrite', Router::getParam('rewrite')); $page = $query->single(); if (!$page instanceof Model\Page) { throw new Exception\Code404('Page does not exist.'); } $this->addBreadCrumb($page->getTitle()); $this->setTitle($page->getTitle()); $this->setDescription($page->getDescription()); $this->setKeywords($page->getKeywords()); $entityConfig = ViewEntity\Configurator::factory($page); $entityConfig->setFields(['content']); $viewEntity = ViewEntity::factory($entityConfig); return $viewEntity->getView(); }
/** * ACTION - User login. * * @access public * @return View * @since 1.0.2, 2013-12-07 * @version 1.0.7-dev, 2015-05-04 */ public function actionLogin() { $this->setTitle(Core::getAppName() . ' - ' . __('Login form')); $this->addBreadCrumb(__('Login form')); $oLoggedUser = Model\User::getLoggedUser(); if ($oLoggedUser instanceof Model\User) { Route::factory('user_profile')->redirectTo(['id' => $oLoggedUser->getId()]); } $failedLogins = \User\LoginFail::getCachedData(); if ($failedLogins > 4) { return View::factory('base/alert')->set('sType', 'danger')->set('sMsg', __('to.many.incorrect.logins')); } $oLoginForm = Form::factory('login'); $oLoginForm->addField(Form\Field\Text::factory('login', $oLoginForm)); $oLoginForm->addField(Form\Field\Password::factory('password', $oLoginForm)); if ($oLoginForm->isSubmittedAndValid()) { $sUsername = $oLoginForm->get('login'); $sPassword = $oLoginForm->get('password'); $sEncryptedPassword = Helper\Encrypter::factory()->encrypt($sUsername, $sPassword); $oUser = DB::query("SELECT u FROM \\Model\\User u WHERE u.login = :login AND u.password = :pass")->param('login', $sUsername)->param('pass', $sEncryptedPassword)->single(); if ($oUser instanceof Model\User) { Session::set('username', $sUsername); Session::set('uid', (int) $oUser->getId()); $oUser->setLoginDateNOW(); DB::flush(); # Get role permissions for particular user and set them in session \UserPermissions::reset(); Route::factory(Router::getCurrentRouteName())->redirectTo(); } else { $currentUrl = Router::currentUrl(); $alert = __('You have entered wrong username or password. Try again.'); \User\LoginFail::addLoginFail(); Session::flash($currentUrl, $alert, 'danger'); } } $oLoginForm->addToSuffix(View::factory('user/frontend/login_links')->render()); return View::factory('base/form')->bind('oForm', $oLoginForm); }
/** * Send user account recovery code. * * @access public * @param User $oUser * @since 1.0.0, 2015-02-17 * @version 2.1.0-dev * @return bool */ private function sendRecoveryCode(User $oUser) { $sUserAgent = filter_input(INPUT_SERVER, 'HTTP_USER_AGENT'); $sCodeToEncode = mb_strlen(uniqid()) * time() . $sUserAgent . $oUser->getLogin(); $sCode2 = sha1($sCodeToEncode); $sRecoveryCode = base64_encode($sCode2); DB::query('DELETE FROM \\Model\\User\\RecoveryCode r WHERE r.user = :user')->param('user', $oUser->getId())->execute(TRUE); $oRecoveryCode = new User\RecoveryCode(); $oRecoveryCode->setUser($oUser); $oRecoveryCode->setCode($sRecoveryCode); DB::persist($oRecoveryCode); DB::flush(); $sSubject = __('Account activation on :app', ['app' => Core::getAppName()]); $mailContent = View::factory("user/frontend/recovery/message")->render(['sLogin' => $oUser->getLogin(), 'sRecoveryCode' => $sRecoveryCode]); $mailView = View::factory('base/email'); $mailView->bind('sContent', $mailContent); $mailView->set('sTitle', $sSubject); return $oUser->sendEmail($sSubject, $mailView->render()); }
/** * Usuwanie rekordu o identyfikatorze $iId w modelu $sModel za pomocą * klauzuli DELETE. Zwraca TRUE, jeżeli rekord został prawidłowo usunięty. * * @static * @access public * @param integer $iId * @param string $sModel * @return boolean * @since 1.0.0-alpha * @version 1.0.0-alpha */ public static function delete($iId, $sModel) { DB::query("DELETE FROM " . $sModel . " m WHERE m.id = :id")->param('id', $iId)->execute(TRUE); return DB::$mResult ? TRUE : FALSE; }
/** * Generate result (containing entities list) for sort list. * * @access protected * @return array * @since 1.0.0-alpha * @version 1.0.0-alpha */ protected function alterSortQueryResult() { return DB::query('SELECT t FROM ' . $this->getModel()->getClass() . ' t ORDER BY t.order_number')->execute(); }
/** * Checks if value exists in database * * @static * @access public * @param string $mValue * @param string $sTableClass * @param string $sColumn * @return boolean|string * @since 1.0.0-alpha * @version 1.0.0-alpha */ public static function dbKeyValidation($mValue, $sTableClass, $sColumn) { # array if (is_array($mValue)) { if (empty($mValue)) { return TRUE; } $mParam = []; foreach ($mValue as $v) { if ($v != "" && !array_search($v, $mParam)) { $mParam[] = $v; } } $iDataAmount = count($mParam); if ($iDataAmount == 0) { return TRUE; } } else { if ($mValue == "") { return TRUE; } $iDataAmount = 1; $mParam = $mValue; } # Query DB::query("SELECT t.id FROM " . $sTableClass . " t WHERE t." . $sColumn . " IN (:param)")->param('param', $mParam)->execute(); # Checking result(s) if (count(DB::result()) != $iDataAmount) { if (is_array($mValue)) { return __('One of the values is incompatible with data from database.'); } else { return __('Value is incompatible with data from database.'); } } return TRUE; }
<?php \Plethora\Router\LocalActions::addLocalAction(__('Edit page'), 'page', 'backend')->setParameters(array('controller' => 'pages', 'action' => 'edit'))->setBuilder(function (\Plethora\Router\LocalActions\Action $oAction) { $sPageRewrite = (int) \Plethora\Router::getParam('rewrite'); $aPage = \Plethora\DB::query('SELECT p.id FROM \\Model\\Page p WHERE p.rewrite = :rewrite')->param('rewrite', $sPageRewrite)->single(); $oAction->setParameter('id', $aPage['id']); }); \Plethora\Router\LocalActions::addLocalAction(__('Preview'), 'backend', 'page')->setConditions(array('controller' => 'pages', 'action' => 'edit'))->setBuilder(function (\Plethora\Router\LocalActions\Action $oAction) { $iNewsID = (int) \Plethora\Router::getParam('id'); $oPage = \Plethora\DB::find('Model\\Page', $iNewsID); /* @var $oPage \Model\Page */ $oAction->setParameter('rewrite', $oPage->getRewrite()); });
/** * Generate result (containing entities list) for sort list. * * @access protected * @return array * @since 1.2.0-dev * @version 1.2.0-dev */ protected function alterSortQueryResult() { $iMenuID = Router::getParam('id'); $sModelClass = $this->getModel()->getClass(); return DB::query('SELECT t FROM ' . $sModelClass . ' t WHERE t.menu = :menu_id ORDER BY t.order_number')->param('menu_id', $iMenuID)->execute(); }