コード例 #1
0
 public function indexAction()
 {
     $emailValidator = new Zend_Validate_EmailAddress();
     $nameValidator = new Zend_Validate_NotEmpty(array(Zend_Validate_NotEmpty::STRING, Zend_Validate_NotEmpty::SPACE));
     $password1_Validator = new Zend_Validate();
     $password1_Validator->addValidator(new Zend_Validate_StringLength(array('min' => 6, 'max' => 12)))->addValidator(new Zend_Validate_Alnum());
     $password2_Validator = new Zend_Validate();
     $password2_Validator->addValidator(new Zend_Validate_StringLength(array('min' => 6, 'max' => 12)))->addValidator(new Zend_Validate_Alnum());
     $captcha = new Zend_Captcha_Image();
     $captcha->setName('captchaword')->setFont(APPLICATION_PATH . '/data/arial.ttf')->setFontSize(28)->setImgDir(APPLICATION_PATH . '/../public/img')->setImgUrl('/img')->setWordLen(5)->setDotNoiseLevel(20)->setExpiration(300);
     $request = $this->getRequest();
     $post = $request->getPost();
     // $passwordIdentical = new Zend_Validate_Identical(array('token' => $post['password1']));
     $messages = array();
     $error = array();
     $noValiError = true;
     if ($this->getRequest()->isPost()) {
         if (!$emailValidator->isValid($post['user-email'])) {
             $error['user-emailVali'] = '請輸入正確的Email帳號';
             $noValiError = false;
         }
         if (!$nameValidator->isValid($post['name'])) {
             $error['nameVali'] = '姓名必填';
             $noValiError = false;
         }
         if (!$password1_Validator->isValid($post['password1'])) {
             $error['password1_Vali'] = '1.密碼長度需介於6~12之間,而且只能使用數字、英文';
             $noValiError = false;
         }
         if (!$password2_Validator->isValid($post['password2'])) {
             $error['password2_Vali'] = '1.密碼長度需介於6~12之間,而且只能使用數字、英文';
             $noValiError = false;
         }
         if (isset($post['password1']) && isset($post['password2']) && !($post['password1'] == $post['password2'])) {
             $error['passwordIdentical'] = '2.密碼輸入不同';
             $noValiError = false;
         }
         if (!($post['agree'] == 1)) {
             $error['agreeVali'] = '需同意服務條款及隱私權政策,才可以註冊';
             $noValiError = false;
         }
         if (!$captcha->isValid($post['captchaword'])) {
             $error['captchawordVali'] = '認證碼輸入錯誤';
             $noValiError = false;
         }
         if ($noValiError) {
             // register process
             $this->_signup($post);
             $this->view->messages = $post;
             $this->redirect('index/index');
         } else {
             $this->_genCaptcha($captcha);
             $this->view->error = $error;
             $this->view->messages = $post;
         }
     } else {
         $this->_genCaptcha($captcha);
     }
 }
コード例 #2
0
ファイル: AdEditForm.php プロジェクト: Tony133/zf-web
 public function init()
 {
     $subForm = new Zend_Form_SubForm();
     $subForm->setLegend('adsFields');
     $validateNonZeroValue = new Zend_Validate_GreaterThan(0);
     $validateDate = new Zend_Validate_Date('Y-m-d');
     $elementUserId = new Zend_Form_Element_Hidden('user_id');
     $elementLanguageId = new Zend_Form_Element_Hidden('language_id');
     $elementActive = new Zend_Form_Element_Hidden('active');
     $elementActive->setValue(1);
     $elementAdsCategoryId = new Zend_Form_Element_Select('ads_category_id');
     $elementAdsCategoryId->setLabel('adsCategoryId');
     $elementAdsCategoryId->setMultiOptions(Ads_Categories::getSelectOptions());
     $elementAdsCategoryId->addValidator($validateNonZeroValue);
     $elementAdsCategoryId->setRequired(true);
     $elementAdsTypeId = new Zend_Form_Element_Select('ads_type_id');
     $elementAdsTypeId->setLabel('adsTypeId');
     $elementAdsTypeId->setMultiOptions(Ads_Types::getSelectOptions());
     $elementAdsTypeId->addValidator($validateNonZeroValue);
     $elementAdsTypeId->setRequired(true);
     $elementValidBefore = new Standart_Form_Element_Date('valid_until');
     $elementValidBefore->setLabel('adsValidUntil');
     $elementValidBefore->addValidator($validateDate);
     $elementValidBefore->setRequired(true);
     $elementTitle = new Zend_Form_Element_Text('title');
     $elementTitle->setLabel('adsTitle');
     $elementTitle->setAttrib('size', 75);
     $elementTitle->setRequired(true);
     $elementDescription = new Zend_Form_Element_Textarea('description');
     $elementDescription->setLabel('adsDescription');
     $elementDescription->setRequired(true);
     $captchaImage = new Zend_Captcha_Image();
     $captchaImage->setFont(Standart_Main::getDirs('fonts', 'arial.ttf'));
     $captchaImage->setFontSize(30);
     $captchaImage->setWordlen(6);
     $captchaImage->setImgDir(Standart_Main::getDirs('wwwStatic', array('images', 'captcha')));
     $captchaImage->setImgUrl(Zend_Registry::get('config')->host->static . '/images/captcha/');
     $captchaImage->setWidth(175);
     $captchaImage->setHeight(75);
     $captchaImage->setName('captcha');
     $elementCaptcha = new Zend_Form_Element_Captcha('captcha', array('captcha' => $captchaImage));
     $elementDoSave = new Zend_Form_Element_Submit('doSave');
     $subForm->addElements(array($elementUserId, $elementLanguageId, $elementActive, $elementAdsCategoryId, $elementAdsTypeId, $elementValidBefore, $elementTitle, $elementDescription, $elementCaptcha));
     $this->addSubForm($subForm, 'ads');
     $this->addElement($elementDoSave);
 }
コード例 #3
0
 /**
  * login page : 1. Validation 2. Login process
  */
 public function indexAction()
 {
     $passwordValidator = new Zend_Validate();
     $passwordValidator->addValidator(new Zend_Validate_StringLength(array('min' => 6, 'max' => 12)))->addValidator(new Zend_Validate_Alnum());
     $emailValidator = new Zend_Validate_EmailAddress();
     $captcha = new Zend_Captcha_Image();
     $captcha->setName('captchaword')->setFont(APPLICATION_PATH . '/data/arial.ttf')->setFontSize(28)->setImgDir(APPLICATION_PATH . '/../public/img')->setImgUrl('/img')->setWordLen(5)->setDotNoiseLevel(20)->setExpiration(300);
     $request = $this->getRequest();
     $post = $request->getPost();
     $messages = array();
     $noValiError = true;
     if ($this->getRequest()->isPost()) {
         if (!$passwordValidator->isValid($post['password'])) {
             $messages['passwordVali'] = '密碼長度需介於6~12之間,而且只能使用數字、英文';
             $noValiError = false;
         }
         if (!$emailValidator->isValid($post['user-email'])) {
             $messages['user-emailVali'] = '請輸入正確的Email帳號';
             $noValiError = false;
         }
         if (!$captcha->isValid($post['captchaword'])) {
             $messages['captchawordVali'] = '認證碼輸入錯誤';
             $noValiError = false;
         }
         $messages['password'] = $post['password'];
         $messages['user-email'] = $post['user-email'];
         if ($noValiError) {
             // login process
             $this->_checkAccount($post);
             $this->view->messages = $messages;
         } else {
             $this->_genCaptcha($captcha);
             $this->view->messages = $messages;
         }
     } else {
         $this->_genCaptcha($captcha);
     }
     if (Zend_Auth::getInstance()->hasIdentity() && $noValiError) {
         $this->redirect('index/index');
     }
 }
コード例 #4
0
 public function contentAction()
 {
     $this->view->messages = $this->_helper->flashMessenger->getMessages();
     $url = $this->_getParam('url');
     $proxy = new SxCms_Page_Proxy();
     $page = $proxy->getPageByUrl($url, null, $this->_getParam('lng', 'nl'));
     if ($page->getId() === false) {
         throw new Zend_Controller_Action_Exception('Page not found', 404);
     }
     $identity = Zend_Auth::getInstance()->getIdentity();
     if (!$page->isAllowed($identity)) {
         $this->_forward('unauthorized', 'index', null, array('url' => $this->view->url()));
         return;
     }
     if ($page->isExpired()) {
         throw new Zend_Controller_Action_Exception('Page expired', 404);
     }
     if ($page->getInvisible()) {
         throw new Zend_Controller_Action_Exception('Page expired', 404);
     }
     /** Gebruik Nederlandse vertaling indien nodig * */
     if ($page->hasContentFallback()) {
         $pageFallback = $proxy->getPageById($page->getId(), 'nl');
         $page->setContent($pageFallback->getContent());
     }
     $this->view->page = $page;
     $this->_helper->layout->setLayout($page->getLayout());
     if ($page->getType() == SxCms_Page::SUMMARY) {
         $children = $proxy->getPagesByParentId($page->getId(), null, $this->_getParam('lng', 'nl'), true, true);
         $childrenArr = array();
         foreach ($children as $child) {
             $pageFallback = false;
             if ($child->hasSummaryFallback()) {
                 $pageFallback = $proxy->getPageById($child->getId(), 'nl');
                 $child->setSummary($pageFallback->getSummary());
             }
             array_push($childrenArr, $child);
         }
         $this->view->children = $childrenArr;
         $this->renderScript('index/summary.phtml');
         return;
     }
     if ($page->getType() == SxCms_Page::ARTICLE) {
         $this->view->comment = new SxCms_Comment();
         $captchaSession = new Zend_Session_Namespace('captcha');
         $captchaSession->setExpirationHops(3);
         if ($captchaSession->token) {
             $captcha = $captchaSession->token;
         } else {
             $captcha = new Zend_Captcha_Image();
             $captcha->setName('captcha')->setWordLen(6)->setDotNoiseLevel(20)->setLineNoiseLevel(0)->setFont(APPLICATION_PATH . '/var/fonts/BRLNSR.TTF')->setImgDir(APPLICATION_ROOT . '/public_html/images/captcha');
             $captcha->generate();
             $captchaSession->token = $captcha;
         }
         $this->view->captcha = $captcha;
     }
     if ($page->getPageform()) {
         if ($this->getRequest()->isGet()) {
             $this->view->captchaId = $this->generateCaptcha();
         }
         $pageformproxy = new SxModule_Pageform_Proxy();
         $subscription = new SxModule_Pageform_Subscription();
         $pageform = $pageformproxy->getActiveById($page->getPageform(), $_SESSION['System']['lng']);
         $this->view->pageform = $pageform;
         if ($this->getRequest()->isPost() && $this->_getParam('comment-submit')) {
             $this->view->errors = array();
             $validator = new SxCms_Comment_BaseValidator();
             $validator->setCaptcha($captcha)->setUserCaptcha($this->_getParam('captcha'));
             $comment = new SxCms_Comment();
             $comment->setMessage($this->_getParam('message'));
             $author = new SxCms_Comment_Author();
             $author->setName($this->_getParam('name'))->setEmail($this->_getParam('email'))->setWebsite($this->_getParam('website'));
             $comment->setPage($page);
             $comment->setCommenter($author);
             if (!$validator->validate($comment)) {
                 $this->view->errors = $validator->getErrors();
                 $this->view->comment = $comment;
                 $this->view->userCaptcha = $this->_getParam('captcha');
             } else {
                 $mapper = new SxCms_Comment_DataMapper();
                 $mapper->save($comment);
                 $captchaSession->unsetAll();
                 $this->_helper->flashMessenger->addMessage('Uw bericht werd succcesvol verwerk.
                 Na goedkeuring door een administrator zal dit op de website verschijnen.');
                 $this->_helper->redirector->gotoRoute(array('url' => $page->getLink()), 'content');
             }
         }
         if ($this->getRequest()->isPost() && $this->_getParam('pageform-submit')) {
             $data = $this->_getParam('pageform');
             $subscription->setPageformId($pageform->getId())->setPageformname($pageform->getName())->setIp($this->getRequest()->getServer('REMOTE_ADDR'))->setAgent($this->getRequest()->getServer('HTTP_USER_AGENT'))->setLng($this->_getParam('lng'))->setUrl('http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);
             foreach ($pageform->getField() as $field) {
                 if (isset($data[$field->getKey()])) {
                     # Tijd instellen
                     if ($field->getFieldType() == 'text' && $field->getValidation() == 'time' && is_array($data[$field->getKey()])) {
                         $data[$field->getKey()] = $data[$field->getKey()]['hh'] . ':' . $data[$field->getKey()]['mm'];
                     }
                     # Tijd & datum instellen
                     if ($field->getFieldType() == 'text' && $field->getValidation() == 'datetime' && is_array($data[$field->getKey()])) {
                         $data[$field->getKey()] = $data[$field->getKey()]['date'] . ' ' . $data[$field->getKey()]['hh'] . ':' . $data[$field->getKey()]['mm'];
                     }
                 }
                 $metaObject = new SxModule_Pageform_Subscription_Meta();
                 $metaObject->setFieldId($field->getId())->setLabel($field->getTsl()->getName())->setName($field->getKey())->setValue(isset($data[$field->getKey()]) ? $data[$field->getKey()] : null);
                 $subscription->addMeta($metaObject);
             }
             $fielderrors = APPLICATION_ROOT . '/application/var/locale/fielderrors.tmx';
             $validator = new SxModule_Pageform_Subscription_Validator();
             $validator->setTmx(new Zend_Translate('tmx', $fielderrors, $_SESSION['System']['lng']));
             //$validator->setTmx( new Zend_Translate('tmx', APPLICATION_ROOT . '/application/var/locale/pageform.tmx', $_SESSION['System']['lng']) );
             $captchaOk = true;
             if ($pageform->getCaptcha()) {
                 $captchaOk = false;
                 $captcha = $this->_getParam('captcha');
                 if ($this->validateCaptcha($captcha)) {
                     $captchaOk = true;
                 }
             }
             $this->view->captchaId = $this->generateCaptcha();
             if ($captchaOk) {
                 if ($validator->validate($subscription, $pageform)) {
                     $subscription->save();
                     if ($pageform->getMailoption() == 1) {
                         $mail = new Zend_Mail('utf-8');
                         $mail->setSubject('Formulier verzonden op website: ' . $pageform->getName())->setFrom(Zend_Registry::get('config')->company->email, "formulier: " . $pageform->getName());
                         $body = 'Datum : ' . date('Y-m-d H:i:s') . "\n";
                         foreach ($subscription->getMeta() as $meta) {
                             $body .= " " . $meta->getLabel() . ": " . $meta->getValue() . "\n";
                         }
                         $mail->setBodyText($body);
                         $mail->addTo($pageform->getMailto());
                         $mail->send();
                     }
                     if ($pageform->getTsl()->getConfirm() == 1) {
                         foreach ($subscription->getMeta() as $meta) {
                             if ($meta->getLabel() == $pageform->getTsl()->getConfirmto()) {
                                 $sendto = $meta->getValue();
                             }
                         }
                         $mail = new Zend_Mail('utf-8');
                         $mail->setSubject($pageform->getTsl()->getConfirmsubject())->setFrom(Zend_Registry::get('config')->company->email, Zend_Registry::get('config')->company->name);
                         $mail->setBodyHtml($pageform->getTsl()->getConfirmcontent());
                         $mail->addTo($sendto);
                         $mail->send();
                     }
                     $subscription = new SxModule_Pageform_Subscription();
                     $this->view->message = "Formulier verzonden!";
                 } else {
                     $this->view->error = "Er ging iets mis...";
                     //var_dump($subscription->getMeta());
                     //exit;
                 }
             } else {
                 $this->view->error = "Neem de captcha code correct over...";
             }
         }
         $this->view->subscription = $subscription;
     }
     $this->view->mode = $this->_getParam('mode') ? $this->_getParam('mode') : '';
     $this->view->messages = Sanmax_MessageStack::getInstance('SxModule_Pageform_Subscription');
 }