private function validate($aLinkCategoryData) { $oFlash = Flash::getFlash(); $oFlash->setArrayToCheck($aLinkCategoryData); $oFlash->checkForValue('name', 'name_required'); $oFlash->finishReporting(); }
/** * The render method for the login page type. When on a login page type, this is given the login action as determined by the page type. Can be either null (default), 'password_forgotten', or 'password_reset' (or any other string of which a template "$sLoginType_action_$sAction" exists). * */ public function renderFrontend($sAction = 'login') { $aOptions = @unserialize($this->getData()); $sLoginType = isset($aOptions[self::MODE_SELECT_KEY]) ? $aOptions[self::MODE_SELECT_KEY] : 'login'; $this->oUser = Session::getSession()->getUser(); if ($this->oUser) { $sAction = 'logout'; } $oTemplate = $this->constructTemplate($sLoginType); if ($oTemplate->hasIdentifier('function_template')) { $oFunctionTemplate = null; try { $oFunctionTemplate = $this->constructTemplate("{$sLoginType}_action_{$sAction}"); } catch (Exception $e) { //Fallback to the default function template for the specified action $oFunctionTemplate = $this->constructTemplate("login_action_{$sAction}"); } $oTemplate->replaceIdentifier('function_template', $oFunctionTemplate, null, Template::LEAVE_IDENTIFIERS); } if ($this->oUser && $this->oPage) { $oPage = $this->oPage; if (Session::getSession()->hasAttribute('login_referrer_page')) { $oPage = Session::getSession()->getAttribute('login_referrer_page'); Session::getSession()->resetAttribute('login_referrer_page'); } if (!$this->oPage->getIsProtected() || Session::getSession()->getUser()->mayViewPage($this->oPage)) { $oTemplate->replaceIdentifier('fullname', Session::getSession()->getUser()->getFullName()); $oTemplate->replaceIdentifier('name', Session::getSession()->getUser()->getUsername()); $oTemplate->replaceIdentifier('action', LinkUtil::link(FrontendManager::$CURRENT_NAVIGATION_ITEM->getLink(), null, array('logout' => 'true'))); } else { $oFlash = Flash::getFlash(); $oFlash->addMessage('login.logged_in_no_access'); } } $oTemplate->replaceIdentifier('login_title', TranslationPeer::getString($sAction == 'password_forgotten' ? 'wns.login.password_reset' : 'wns.login')); $sOrigin = isset($_REQUEST['origin']) ? $_REQUEST['origin'] : LinkUtil::linkToSelf(); $oTemplate->replaceIdentifier('origin', $sOrigin); if ($sAction !== 'logout') { $oLoginPage = $this->oPage ? $this->oPage->getLoginPage() : null; $sLink = null; if ($oLoginPage === null) { $sLink = LinkUtil::link('', 'LoginManager'); } else { $sLink = LinkUtil::link($oLoginPage->getFullPathArray()); } $oTemplate->replaceIdentifier('action', $sLink); } if ($sAction === 'login') { $oLoginPage = $this->oPage ? $this->oPage->getLoginPage() : null; $sLink = null; if ($oLoginPage === null) { $sLink = LinkUtil::link(array(), 'LoginManager', array('password_forgotten' => 'true')); } else { $sLink = LinkUtil::link($oLoginPage->getFullPathArray(), null, array('password_forgotten' => 'true')); } $oTemplate->replaceIdentifier('password_forgotten_action', $sLink); } return $oTemplate; }
public function validate($aDocumentData, $oDocument) { $oFlash = Flash::getFlash(); $oFlash->setArrayToCheck($aDocumentData); if ($this->iDocumentId === null) { $oFlash->addMessage('document.requires_file'); } $oFlash->finishReporting(); }
public function uploadFile($sFileKey = 'file', $aOptions = null, $bCreateType = false) { $oFlash = Flash::getFlash(); $oFlash->checkForFileUpload($sFileKey); $oFlash->finishReporting(); if (!Flash::noErrors()) { throw new ValidationException(); } $aFileInfo = $_FILES[$sFileKey]; if ($aOptions['document_id']) { $oDocument = DocumentQuery::create()->findPk($aOptions['document_id']); } else { $oDocument = new Document(); } if ($oDocument === null) { throw new LocalizedException("wns.file_upload.document_not_found"); } $sFileName = $aOptions['name']; $aName = explode('.', $sFileName); if (count($aName) > 1) { array_pop($aName); } $sFileName = implode('.', $aName); $iDocumentTypeId = null; try { $iDocumentTypeId = $this->accepts($aOptions['name'], $aOptions['type']); } catch (Exception $e) { if ($bCreateType) { $aName = explode('.', $aOptions['name']); $sExtension = null; if (count($aName) > 1) { $sExtension = array_pop($aName); } $aMimeType = explode('/', $aOptions['type']); if ($sExtension === null) { $sExtension = $aMimeType[1]; } if ($sExtension === null) { throw new LocalizedException("wns.file_upload.unknown_document_type"); } $oDocumentType = new DocumentType(); $oDocumentType->setExtension($sExtension); $oDocumentType->setMimetype(implode('/', $aMimeType)); $oDocumentType->save(); $iDocumentTypeId = $oDocumentType->getId(); } else { throw $e; } } $oDocument->setData(fopen($aFileInfo['tmp_name'], "r")); $this->updateDocument($oDocument, $aOptions, $sFileName, $iDocumentTypeId); $oDocument->save(); return $oDocument->getId(); }
private function validate($aSubscriberData, $oSubscriber) { $oFlash = Flash::getFlash(); $oFlash->setArrayToCheck($aSubscriberData); $oFlash->checkForValue('name', 'name_required'); $oFlash->checkForEmail('email', 'valid_email'); if (SubscriberQuery::create()->exclude($oSubscriber)->filterByEmail($aSubscriberData['email'])->count() > 0) { $oFlash->addMessage('duplicate_email'); } $oFlash->finishReporting(); }
private function validate($aDocumentTypeData, $oType) { $oFlash = Flash::getFlash(); $oFlash->setArrayToCheck($aDocumentTypeData); if ($oFlash->checkForValue('extension', 'extension_required') & $oFlash->checkForValue('mimetype', 'mimetype_required')) { if (($oType->getExtension() !== $aDocumentTypeData['extension'] || $oType->getMimetype() !== $aDocumentTypeData['mimetype']) && DocumentTypeQuery::create()->filterByExtension($aDocumentTypeData['extension'])->filterByMimetype($aDocumentTypeData['mimetype'])->count() > 0) { $oFlash->addMessage('document_type_duplicate'); } } $oFlash->finishReporting(); }
private function validate($aDocumentationPartData) { $oFlash = Flash::getFlash(); $oFlash->setArrayToCheck($aDocumentationPartData); $oFlash->checkForValue('name', 'documentation_part_name_required'); $oFlash->checkForValue('documentation_id', 'documentation_required'); if ($aDocumentationPartData['is_published']) { $oFlash->checkForValue('body', 'documentation_part_body_required'); $oFlash->checkForValue('key', 'key_required'); } $oFlash->finishReporting(); }
private function validate($aStringData) { $oFlash = Flash::getFlash(); $oFlash->setArrayToCheck($aStringData); $oFlash->checkForValue('string_key', 'string.key_required'); // if string is new, or string_key has changed, then the existence of the string_key has to be checked if ($this->sStringId === null || $this->sStringId !== $aStringData['string_key']) { if (TranslationQuery::create()->filterByStringKey($aStringData['string_key'])->count() > 0) { $oFlash->addMessage('string.key_exists'); } } $oFlash->finishReporting(); }
private function validate($aLanguageData, $oLanguage) { $oFlash = Flash::getFlash(); $oFlash->setArrayToCheck($aLanguageData); $oFlash->checkForLength('language_id', 2, 5, 'language_id_required'); if ($oFlash->checkForValue('path_prefix', 'path_prefix_required')) { $oFlash->checkForValue('path_prefix', 'path_prefix_unique'); } if (LanguageQuery::create()->filterByPathPrefix($aLanguageData['path_prefix'])->filterById($aLanguageData['language_id'], Criteria::NOT_EQUAL)->count() > 0) { $oFlash->addMessage('path_prefix_unique'); } $oFlash->finishReporting(); }
private function validate($aRoleData, $oRole) { $oFlash = Flash::getFlash(); $oFlash->setArrayToCheck($aRoleData); if ($oFlash->checkForValue('role_key', 'role_key_required')) { if ($oCheckRole = RoleQuery::create()->filterByRoleKey($aRoleData['role_key'])->findOne()) { if (!Util::equals($oCheckRole, $oRole)) { $oFlash->addMessage('role_key_exists'); } } } $oFlash->finishReporting(); }
private function validate($aTagData) { $oFlash = Flash::getFlash(); $oFlash->setArrayToCheck($aTagData); $oFlash->checkForValue('name', 'tag_name_required'); $oCriteria = TagQuery::create()->filterByName($aTagData['name']); if ($this->iTagId !== null) { $oCriteria->exclude($this->iTagId); } if ($oCriteria->count() > 0) { $oFlash->addMessage('tag_name_exists'); } $oFlash->finishReporting(); }
public function __construct($oFlash = null) { $aParameters = array(); if ($oFlash === null) { $oFlash = Flash::getFlash(); } if (is_array($oFlash)) { $aParameters = $oFlash; } else { $oFlash->finishReporting(); foreach ($oFlash->getMessages() as $sMessageKey) { $aParameters[$sMessageKey] = $oFlash->getMessageProperties($sMessageKey); } } parent::__construct('wns.exception_validation', $aParameters, get_class($this)); }
private function validate($aDocumentationData, $oDocumentation) { $oFlash = Flash::getFlash(); $oFlash->setArrayToCheck($aDocumentationData); $oFlash->checkForValue('name', 'name_required'); $oFlash->checkForValue('key', 'key_required'); if (!LanguageInputWidgetModule::isMonolingual()) { $oDocumentation->setLanguageId($aDocumentationData['language_id']); $oFlash->checkForValue('language_id', 'language_required'); } else { $oLanguage = LanguageQuery::create()->findOne(); $oDocumentation->setLanguageId($oLanguage->getId()); } $oCheckDocumentation = DocumentationQuery::create()->filterByLanguageId($oDocumentation->getLanguageId())->filterByKey($aDocumentationData['key'])->findOne(); if ($oCheckDocumentation && !Util::equals($oDocumentation, $oCheckDocumentation)) { $oFlash->addMessage('documentation_unique_required'); } $oFlash->finishReporting(); }
private function validate($aUserData, $oUser) { $oFlash = Flash::getFlash(); $oFlash->setArrayToCheck($aUserData); $oFlash->checkForValue('username', 'username_required'); $oFlash->checkForValue('first_name', 'first_name_required'); $oFlash->checkForValue('last_name', 'last_name_required'); $oFlash->checkForEmail('email', 'valid_email'); if ($oUser->isNew() || $aUserData['username'] !== $oUser->getUsername()) { $oCheckedUser = UserQuery::create()->filterByUsername($aUserData['username'])->findOne(); if ($oCheckedUser !== null && $oCheckedUser->getId() !== $oUser->getId()) { $oFlash->addMessage('username_exists'); } } if ($aUserData['force_password_reset']) { // Nothing to validate, pass } else { if ($aUserData['password'] !== '') { if ($oUser->isSessionUser() && $oUser->getPassword() != null) { if ($aUserData['old_password'] == '') { $oFlash->addMessage('old_password_required'); } else { if (!PasswordHash::comparePassword($aUserData['old_password'], $oUser->getPassword())) { $oFlash->addMessage('old_password_invalid'); } } } if ($aUserData['password'] !== $aUserData['password_confirm']) { $oFlash->addMessage('password_confirm'); } PasswordHash::checkPasswordValidity($aUserData['password'], $oFlash); } else { if ($oUser->isNew()) { $oFlash->addMessage('password_new'); } } } $oFlash->finishReporting(); }
public function renderFile() { $aCurrentValues = $this->oFormStorage->saveCurrentValuesToSession(); $oFlash = Flash::getFlash(); $oFlash->setArrayToCheck($aCurrentValues); $bHasCaptcha = false; foreach ($this->oFormStorage->getFormObjects() as $oFormObject) { if ($oFormObject instanceof CaptchaObject) { $bHasCaptcha = true; } if ($oFormObject->shouldExcludeFromReport()) { continue; } if ($oFormObject->isRequired()) { $oFlash->checkForValue($oFormObject->getName()); } $oEmailItemTemplateInstance = clone $this->oEmailItemTemplate; $oEmailItemTemplateInstance->replaceIdentifier('name', $oFormObject->getName()); $oEmailItemTemplateInstance->replaceIdentifier('label', $oFormObject->getLabel()); $oEmailItemTemplateInstance->replaceIdentifier('value', $oFormObject->getCurrentValue()); $this->oEmailTemplate->replaceIdentifierMultiple('form_content', $oEmailItemTemplateInstance); } if ($bHasCaptcha && !FormFrontendModule::validateRecaptchaInput()) { $oFlash->addMessage('captcha_code_required'); } $oFlash->finishReporting(); if (Flash::noErrors()) { $oEmail = new EMail(TranslationPeer::getString('wns.form_module.email_subject', null, null, array('page' => $this->sPageName)), $this->oEmailTemplate); $oEmail->addRecipient($this->sEmailAddress); $oEmail->send(); $this->oFormStorage->deleteCurrentValuesFromSession(); LinkUtil::redirect($_REQUEST['origin'] . '?form_success=true'); } else { $oFlash->stick(); LinkUtil::redirect($_REQUEST['origin']); } }
private function validate($aData) { $oFlash = Flash::getFlash(); $oFlash->setArrayToCheck($aData); if (!isset($aData['journal_ids'])) { $oFlash->addMessage('journal_ids_required'); } $oFlash->finishReporting(); }
private function validate($aPageData) { $oFlash = Flash::getFlash(); $oFlash->setArrayToCheck($aPageData); $oFlash->checkForValue('name', 'page.name_required'); if ($aPageData['name'] != null && $aPageData['name'] != $this->oPage->getName()) { if (PagePeer::pageIsNotUnique($aPageData['name'], $this->oPage->getParent(), $this->oPage->getId())) { $oFlash->addMessage('page.name_unique_required'); } } if (isset($aPageData['edited_languages'])) { foreach ($aPageData['edited_languages'] as $iCounter => $sLanguageId) { if ($aPageData['is_active'][$iCounter] && $aPageData['page_title'][$iCounter] == '') { $oFlash->addMessage('page_title_required'); $oFlash->addAffectedIndex('page_title_required', $iCounter); } } } $oFlash->finishReporting(); }
private function validate($aNewsletterData, $oNewsletter) { $oFlash = Flash::getFlash(); $oFlash->setArrayToCheck($aNewsletterData); $oFlash->checkForValue('subject', 'subject_required'); $oFlash->checkForValue('template_name', 'template_required'); $oFlash->finishReporting(); }
public static function loginNewPassword($sReferrer = '') { $oFlash = Flash::getFlash(); $oUser = UserQuery::create()->filterByUsername(trim($_REQUEST['recover_username']))->isActive()->findOne(); if ($oUser === null || md5($oUser->getPasswordRecoverHint()) !== $_REQUEST['recover_hint']) { $oFlash->addMessage('login.recovery.invalid'); return 'login'; } if ($_POST['new_password'] === '') { $oFlash->addMessage('login.empty_fields'); } PasswordHash::checkPasswordValidity($_POST['new_password'], $oFlash); if ($_POST['new_password'] !== $_POST['new_password_retype']) { $oFlash->addMessage('password_confirm'); } $oFlash->finishReporting(); if (!Flash::noErrors()) { return 'password_reset'; } //No errors – set new password, login and redirect UserPeer::ignoreRights(true); $oUser->setPassword($_POST['new_password']); $oUser->setPasswordRecoverHint(null); $oUser->save(); self::login($_POST['recover_username'], $_POST['new_password'], $sReferrer); return 'login'; }
/** * processSubscribe() * * @param int/array subscriber group * @param Template object * * Description * • validate subscriber * • create/update subscriber and subscriptions * • notify subscriber in case it is a new subscription * • display confirm message independent the success of the action (previous existence of subscriber is not disclosed) * @return void */ private function processSubscribe($iSubscriberGroupId, $oTemplate) { $oFlash = Flash::getFlash(); $oFlash->checkForEmail('subscriber_email', 'email_required_for_subscription'); $oFlash->finishReporting(); if (Flash::noErrors()) { $this->oSubscriber = SubscriberQuery::create()->filterByEmail($_POST['subscriber_email'])->findOne(); // Create new subscriber if it does not exist yet if ($this->oSubscriber === null) { $this->oSubscriber = new Subscriber(); $this->oSubscriber->setEmail($_POST['subscriber_email']); $this->oSubscriber->setPreferredLanguageId(isset($_REQUEST['preferred_language_id']) ? $_REQUEST['preferred_language_id'] : Session::language()); $this->oSubscriber->setName(isset($_POST['name']) ? $_POST['name'] : $this->oSubscriber->getEmail()); $this->oSubscriber->setCreatedAt(date('c')); } // Add newsletter subscription if it does not exist yet $bHasNewSubscription = false; if ($iSubscriberGroupId && !$this->oSubscriber->hasSubscriberGroupMembership($iSubscriberGroupId)) { $bHasNewSubscription = $this->oSubscriber->addSubscriberGroupMembershipBySubscriberGroupId($iSubscriberGroupId) !== null; } SubscriberGroupMembershipPeer::ignoreRights(true); SubscriberPeer::ignoreRights(true); $this->oSubscriber->save(); $sConfirmMessage = TranslationPeer::getString('wns.newsletter.subscribe.success'); // Notifiy only if a new subscription has been added, otherwise ignore if ($bHasNewSubscription) { if (Settings::getSetting('newsletter', 'optin_confirmation_required', true)) { $sConfirmMessage = TranslationPeer::getString('wns.newsletter.subscribe_opt_in.success'); $this->notifySubscriberOptIn($iSubscriberGroupId); } else { $this->notifySubscriber(); } } $oTemplate->replaceIdentifier('message', $sConfirmMessage); } }
private function validate($aData) { $oFlash = Flash::getFlash(); $oFlash->setArrayToCheck($aData); $oFlash->checkForValue('title', 'journal_entry.title_required'); $oFlash->checkForValue('journal_id', 'journal_entry.journal_id_required'); if ($aData['is_published']) { $oFlash->checkForValue('text', 'journal_entry.text_required'); } $oFlash->finishReporting(); }
public function writeFlashValue($oTemplateIdentifier) { return Flash::getFlash()->getMessage($oTemplateIdentifier->getValue()); }
public function render() { $this->preRender(); $oTemplate = null; if (!Session::getSession()->isAuthenticated() || !Session::getSession()->getUser()->getIsBackendLoginEnabled()) { if (Session::getSession()->isAuthenticated() && !Session::getSession()->getUser()->getIsBackendLoginEnabled()) { Flash::getFlash()->addMessage('admin_login_denied'); Session::getSession()->logout(); } self::setContentLanguage(Session::language()); $oTemplate = new Template('login', array(DIRNAME_TEMPLATES, 'admin'), false, true); $oLoginWindowWidget = new LoginWindowWidgetModule(); LoginWindowWidgetModule::includeResources(); } else { $oTemplate = new Template('main', array(DIRNAME_TEMPLATES, 'admin'), false, true); $this->renderAdmin($oTemplate); } $oTemplate->replaceIdentifier("title", Settings::getSetting('admin', 'title', 'no title set in config/config.yml for admin'), null, Template::LEAVE_IDENTIFIERS); $oTemplate->replaceIdentifier('module_name', $this->sModuleName); $oTemplate->replaceIdentifier('module_display_name', AdminModule::getDisplayNameByName($this->sModuleName)); $oTemplate->render(); }
private function handleNewJournalComment($oPage, $oEntry) { $oFlash = Flash::getFlash(); // Validate form and create new comment and $oComment = new JournalComment(); $oComment->setUsername($_POST['comment_name']); $oFlash->checkForValue('comment_name', 'comment_name_required'); $oComment->setEmail($_POST['comment_email']); $oFlash->checkForEmail('comment_email', 'comment_email_required'); if ($oEntry->getJournal()->getUseCaptcha() && !Session::getSession()->isAuthenticated() && !FormFrontendModule::validateRecaptchaInput() && !isset($_POST['preview'])) { $oFlash->addMessage('captcha_required'); } $oPurifierConfig = HTMLPurifier_Config::createDefault(); $oPurifierConfig->set('Cache.SerializerPath', MAIN_DIR . '/' . DIRNAME_GENERATED . '/' . DIRNAME_CACHES . '/purifier'); $oPurifierConfig->set('HTML.Doctype', 'XHTML 1.0 Transitional'); $oPurifierConfig->set('AutoFormat.AutoParagraph', true); $oPurifier = new HTMLPurifier($oPurifierConfig); $_POST['comment_text'] = $oPurifier->purify($_POST['comment_text']); $oComment->setText($_POST['comment_text']); $oFlash->checkForValue('comment_text', 'comment_required'); $oFlash->finishReporting(); if (isset($_POST['preview'])) { $oComment->setCreatedAt(date('c')); $_POST['preview'] = $oComment; } else { if (Flash::noErrors()) { $oEntry->addJournalComment($oComment); // Post is considered as spam $bIsProblablySpam = isset($_POST['important_note']) && $_POST['important_note'] != null; $sCommentNotificationTemplate = 'e_mail_comment_notified'; // Prevent publication if comments are not enabled or post is spam if (!$oEntry->getJournal()->getEnableComments() || $bIsProblablySpam) { if (!Session::getSession()->isAuthenticated()) { $oComment->setIsPublished(false); $sCommentNotificationTemplate = 'e_mail_comment_moderated'; } } $oComment->save(); // Notify new comment if ($oEntry->getJournal()->getNotifyComments()) { $oEmailContent = JournalPageTypeModule::templateConstruct($sCommentNotificationTemplate, $oPage->getPagePropertyValue('journal:template_set', 'default')); $oEmailContent->replaceIdentifier('email', $oComment->getEmail()); $oEmailContent->replaceIdentifier('user', $oComment->getUsername()); if ($bIsProblablySpam) { $oEmailContent->replaceIdentifier('this_comment_is_spam_note', TranslationPeer::getString('journal.this_comment_is_spam_note', null, null, array('important_note_content' => $_POST['important_note']))); } $oEmailContent->replaceIdentifier('comment', $oComment->getText()); $oEmailContent->replaceIdentifier('entry', $oEntry->getTitle()); $oEmailContent->replaceIdentifier('journal', $oEntry->getJournal()->getName()); $oEmailContent->replaceIdentifier('entry_link', LinkUtil::absoluteLink(LinkUtil::link($oEntry->getLink($oPage)))); $oEmailContent->replaceIdentifier('deactivation_link', LinkUtil::absoluteLink(LinkUtil::link(array('journal_comment_moderation', $oComment->getActivationHash(), 'deactivate'), 'FileManager'), null, LinkUtil::isSSL())); $oEmailContent->replaceIdentifier('activation_link', LinkUtil::absoluteLink(LinkUtil::link(array('journal_comment_moderation', $oComment->getActivationHash(), 'activate'), 'FileManager'), null, LinkUtil::isSSL())); $oEmailContent->replaceIdentifier('deletion_link', LinkUtil::absoluteLink(LinkUtil::link(array('journal_comment_moderation', $oComment->getActivationHash(), 'delete'), 'FileManager'), null, LinkUtil::isSSL())); $sSubject = TranslationPeer::getString('journal.notification_subject', null, null, array('entry' => $oEntry->getTitle())); $oEmail = new EMail($sSubject, $oEmailContent); $oSender = $oEntry->getUserRelatedByCreatedBy(); $oEmail->addRecipient($oSender->getEmail(), $oSender->getFullName()); $oEmail->send(); } $oSession = Session::getSession(); Flash::getFlash()->unfinishReporting()->addMessage('journal.has_new_comment', array(), "journal_entry.new_comment_thank_you" . ($oEntry->getJournal()->getEnableComments() || $oSession->isAuthenticated() ? '' : '.moderated'), 'new_comment_thank_you_message', 'p')->stick(); LinkUtil::redirect(LinkUtil::link($oEntry->getLink($oPage)) . "#comments"); } } }