Example #1
0
 public function __construct($name = null)
 {
     parent::__construct();
     // FORM Attribute
     $this->setAttributes(array('action' => '', 'method' => 'POST', 'class' => 'form-horizontal', 'role' => 'form', 'name' => 'login-form', 'id' => 'login-form'));
     // Fullname
     $this->add(array('name' => 'fullname', 'type' => 'Text', 'attributes' => array('class' => 'form-control', 'id' => 'inputFullname', 'placeholder' => 'Họ tên'), 'options' => array('label' => 'Họ tên', 'label_attributes' => array('for' => 'inputEmail3', 'class' => 'col-sm-3 control-label'))));
     // Username
     $this->add(array('name' => 'username', 'type' => 'Text', 'attributes' => array('class' => 'form-control', 'id' => 'inputUsername', 'placeholder' => 'Tên đăng nhập'), 'options' => array('label' => 'Tên đăng nhập', 'label_attributes' => array('for' => 'inputEmail3', 'class' => 'col-sm-3 control-label'))));
     // Email
     $this->add(array('name' => 'email', 'type' => 'Text', 'attributes' => array('class' => 'form-control', 'id' => 'inputEmail', 'placeholder' => 'Email'), 'options' => array('label' => 'Email', 'label_attributes' => array('for' => 'inputEmail3', 'class' => 'col-sm-3 control-label'))));
     // Password
     $this->add(array('name' => 'password', 'type' => 'Password', 'attributes' => array('class' => 'form-control', 'id' => 'inputPassword', 'placeholder' => 'Password'), 'options' => array('label' => 'Password', 'label_attributes' => array('for' => 'inputPassword3', 'class' => 'col-sm-3 control-label'))));
     //Confirm Password
     $this->add(array('name' => 'confirm-password', 'type' => 'Password', 'attributes' => array('class' => 'TextInput', 'id' => 'inputConfirmPassword', 'placeholder' => 'Nhập lại mật khẩu'), 'options' => array('label' => 'Nhập lại mật khẩu', 'label_attributes' => array('for' => 'inputEmail3', 'class' => 'col-sm3 control-label'))));
     // Password
     $this->add(array('name' => 'phone', 'type' => 'Text', 'attributes' => array('class' => 'form-control', 'id' => 'inputPhone', 'placeholder' => 'Di động'), 'options' => array('label' => 'Di động', 'label_attributes' => array('for' => 'inputPassword3', 'class' => 'col-sm-3 control-label'))));
     $captchaObj = new \Zend\Captcha\Image();
     $captchaObj->setImgDir(CAPTCHA_PATH . '/images');
     $captchaObj->setImgUrl(CAPTCHA_URL . '/images');
     $captchaObj->setFont(CAPTCHA_PATH . '/fonts/times.ttf');
     $captchaObj->setFontSize(25);
     $captchaObj->setWordlen(5);
     $captchaObj->setWidth(200);
     $captchaObj->setHeight(50);
     $captchaObj->setDotNoiseLevel(100);
     $captchaObj->setLineNoiseLevel(5);
     // Captcha
     $this->add(array('name' => 'captcha', 'type' => 'Captcha', 'attributes' => array('class' => 'form-control', 'id' => 'inputCaptcha'), 'options' => array('label' => 'Mã an toàn', 'captcha' => $captchaObj)));
     $this->add(array('name' => 'my-button-submit', 'type' => 'Button', 'attributes' => array('type' => 'submit', 'class' => 'actionButton'), 'options' => array('label' => 'Tạo tài khoản')));
 }
Example #2
0
 public function captcha2_check()
 {
     $path = BASEPATH . '../resources/captcha/' . (date('Y') . '/' . date('m') . '/' . date('d'));
     if (!file_exists($path)) {
         mkdir($path, 0777, TRUE);
     }
     $session = new Zend\Session\Container('ZEND_PARANGARI');
     $obj = new Zend\Captcha\Image();
     $obj->setSession($session);
     echo $obj->getWord() == 'h4c984' ? 'VALID' : 'INVALID';
     echo "<br/>";
     $v = $session->offsetGet('text1');
     var_dump($v);
 }
Example #3
0
 public function index01Action()
 {
     echo "<h3 style='color:red;font-weight:bold'>" . __METHOD__ . "</h3>";
     //Tạo đối tượng chaptcha Image
     $captchaImg = new \Zend\Captcha\Image();
     //Thiết lập đường dẫn đấn thư mục hình ảnh chứa captcha
     $captchaImg->setImgDir(CAPTCHA_PATH . "images");
     //Thiết lập url cho hình ảnh captcha
     $captchaImg->setImgUrl(CAPTCHA_URL . "images");
     //Thiết lập font
     $captchaImg->setFont(CAPTCHA_PATH . "fonts/Vharis.ttf");
     //font-size
     $captchaImg->setFontSize(30);
     //length-char
     $captchaImg->setWordlen(5);
     //width-height cho captcha
     $captchaImg->setWidth(180);
     $captchaImg->setHeight(70);
     //set dấu chấm và đường chéo
     $captchaImg->setDotNoiseLevel(70);
     $captchaImg->setLineNoiseLevel(5);
     //Thiết lập ký tự xuất hiện
     AbstractWord::$VN = array("t");
     AbstractWord::$CN = array("r");
     //Phát sinh captcha
     $captchaImg->generate();
     $imgUrl = $captchaImg->getImgUrl() . $captchaImg->getId() . $captchaImg->getSuffix();
     return new ViewModel(array("imgUrl" => $imgUrl));
 }
 /**
  * Submit a webform
  * @return Ambigous <\Zend\Http\Response, \Zend\Stdlib\ResponseInterface>|Ambigous <unknown, \Zend\Form\Form>
  */
 public function bfAction()
 {
     //set container for additional params
     $arr_additional_params = array();
     $form_id = $this->params()->fromRoute("fid");
     $reg_id = $this->params()->fromRoute("reg_id", NULL);
     $arr_additional_params["reg_id"] = $reg_id;
     //check if reg id is encoded, if not, do not process
     if (is_numeric($reg_id)) {
         $this->flashMessenger()->addErrorMessage("An error occured attempting to load data");
         //redirect back to form
         return $this->redirect()->toRoute("majestic-external-forms/bf", array("fid" => $form_id));
     }
     //end if
     //load comm history id
     $comm_history_id = $this->params()->fromQuery("cid", "");
     if ($comm_history_id != "") {
         $arr_additional_params["cid"] = $comm_history_id;
     }
     //end if
     //check form id has been set
     if (!is_string($form_id)) {
         echo "Form could not be loaded. Required information is not available.";
         exit;
     }
     //end if
     try {
         //load form details
         $arr_return = $this->getExternalFormsModel()->loadForm($form_id, $reg_id, $arr_additional_params);
         $arr_return["additional_data"] = $arr_additional_params;
         //add plain form url
         $arr_return["form_url"] = $this->url()->fromRoute("majestic-external-forms/bf", array("fid" => $form_id));
     } catch (\Exception $e) {
         //@TODO do something with the error
         // var_dump($e->getMessage() . " : " . $e->getPrevious()); exit;
         die("The requested form could not be loaded. Response: " . $this->frontControllerErrorHelper()->formatErrors($e));
     }
     //end catch
     if ($arr_return["objFormRawData"]->secure_form == "1") {
         if (!isset($_SERVER['HTTPS']) || strtolower($_SERVER['HTTPS']) != "on" && $_SERVER["HTTPS"] != 1 && $_SERVER["SERVER_PORT"] != "443") {
             header("location:https://" . $_SERVER[HTTP_HOST] . $_SERVER[REQUEST_URI]);
         }
         //end if
     }
     //end if
     //should the user be logged in?
     if ($arr_return["objFormRawData"]->user_login == 1) {
         $objUserSession = FrontUserSession::isLoggedIn();
         if (!$objUserSession) {
             $this->flashMessenger()->addInfoMessage("User must be logged in in order to access form");
             //redirect to login screen
             return $this->redirect()->toRoute("front-user-login");
         }
         //end if
     }
     //end if
     //should the contact be specified
     if ($arr_return["objFormRawData"]->id_required == 1 && $reg_id == "") {
         echo "Form could not be loaded. Contact ID is not set";
         exit;
     }
     //end if
     //should the form be redirected on loading?
     if ($arr_return["objFormRawData"]->redirect_on_load != "") {
         header("location:" . $arr_return["objFormRawData"]->redirect_on_load);
         exit;
     }
     //end if
     //extract form from result
     $form = $arr_return["objForm"];
     //does form have password access enabled?
     //@TODO set proper session data
     if ($arr_return["objFormRawData"]->form_password != "" && $_SESSION["form_data"]["password"] != $arr_return["objFormRawData"]->form_password) {
         $form = new \Zend\Form\Form();
         $form->add(array("type" => "password", "name" => "password", "attributes" => array("id" => "password", "required" => "required"), "options" => array("label" => "Form Password")));
         $form->add(array("type" => "submit", "name" => "submit", "attributes" => array("value" => "Submit")));
         $request = $this->getRequest();
         if ($request->isPost()) {
             if ($request->getPost("password") == $arr_return["objFormRawData"]->form_password) {
                 $_SESSION["form_data"]["password"] = $request->getPost("password");
                 return $this->redirect()->toRoute("majestic-external-forms/bf", array("fid" => $form_id, "reg_id" => $reg_id));
             }
             //end if
         }
         //end if
         if ($_SESSION["form_data"]["password"] != $arr_return["objFormRawData"]->form_password) {
             $arr_return["form"] = $form;
             return $arr_return;
         }
         //end if
     }
     //end if
     //is form captcha enabled?
     if ($arr_return["objFormRawData"]->captcha == 1) {
         if (!is_dir("./public/captcha")) {
             mkdir("./public/captcha", 0755, TRUE);
         }
         //end if
         $objCaptcha = new \Zend\Captcha\Image(array('expiration' => '300', 'wordlen' => '7', 'font' => 'data/fonts/arial.ttf', 'fontSize' => '20', 'imgDir' => 'public/captcha', 'imgUrl' => '/captcha', 'lineNoiseLevel' => 1, 'dotNoiseLevel' => 1));
         $form->add(array("name" => "captcha", "type" => "Zend\\Form\\Element\\Captcha", "attributes" => array("id" => "captcha", "required" => "required", "autocomplete" => "off"), "options" => array("label" => "Human verification", "captcha" => $objCaptcha)));
     }
     //end if
     $arr_return["form_posted"] = FALSE;
     $request = $this->getRequest();
     if ($request->isPost()) {
         if ($form->has("captcha")) {
             if (!$objCaptcha->isValid($request->getPost("captcha"), $request->getPost())) {
                 $form->setData($request->getPost());
                 $this->flashMessenger()->addErrorMessage("CAPTCHA validation failed");
                 $arr_return["form"] = $form;
                 return $arr_return;
             }
             //end if
         }
         //end if
         //set form post flag to stop javascript loading on form error
         $arr_return["form_posted"] = TRUE;
         $form->setData($request->getPost());
         if ($form->isValid($request->getPost())) {
             try {
                 //submit the form
                 $objResult = $this->getExternalFormsModel()->processFormSubmit($form_id, $form->getData(), $arr_additional_params);
                 //unset form password
                 if (isset($_SESSION["form_data"]["password"])) {
                     unset($_SESSION["form_data"]["password"]);
                 }
                 //end if
                 //redirect to post submit page
                 return $this->redirect()->toRoute("majestic-external-forms/bfs", array("fid" => $form_id, "reg_id" => $objResult->data->reg_id_encoded));
             } catch (\Exception $e) {
                 //extract errors from the request return by the API
                 $arr_response = explode("||", $e->getMessage());
                 $objResponse = json_decode($arr_response[1]);
                 //check if user is logged in to display links to duplicate contacts
                 $objUserSession = FrontUserSession::isLoggedIn();
                 if (is_object($objResponse) && is_object($objUserSession)) {
                     switch ($objResponse->HTTP_RESPONSE_CODE) {
                         case 409:
                             //duplicates found
                             //extract message
                             $arr_t = explode(":", $objResponse->HTTP_RESPONSE_MESSAGE);
                             $id_string = array_pop($arr_t);
                             $this->flashMessenger()->addErrorMessage(trim(str_replace(array("{", "}"), "", $id_string)));
                             //extract ids and create links to each
                             preg_match('~{(.*?)}~', $id_string, $output);
                             $arr_contact_ids = explode(",", $output[1]);
                             if (is_array($arr_contact_ids) && count($arr_contact_ids) > 0) {
                                 foreach ($arr_contact_ids as $k => $id) {
                                     $this->flashMessenger()->addInfoMessage("<a href=\"" . $this->url()->fromRoute("front-contacts", array("action" => "view-contact", "id" => $id)) . "\" target=\"_blank\" title=\"View Contact\">Click to view duplicate {$id}</a>");
                                     if ($k > 19) {
                                         break;
                                     }
                                     //end if
                                 }
                                 //end foreach
                             }
                             //end if
                             break;
                         default:
                             //add errors to the form already where set
                             //@TODO this needs some work, messages  should be generated back into the form directly...
                             if (is_object($objResponse) && isset($objResponse->data)) {
                                 foreach ($objResponse->data as $k => $objField) {
                                     if (is_object($objField) && isset($objField->messages) && isset($objField->attributes->name)) {
                                         if ($form->has($objField->attributes->name)) {
                                             $arr_message = (array) $objField->messages;
                                             $form->get($objField->attributes->name)->setMessages($arr_message);
                                             $form->get($objField->attributes->name)->setValue($request->getPost($objField->attributes->name));
                                         }
                                         //end if
                                     }
                                     //end if
                                 }
                                 //end if
                             }
                             //end if
                             //set form errors
                             $form = $this->frontFormHelper()->formatFormErrors($form, $e->getMessage());
                             break;
                     }
                     //end switch
                 } else {
                     //@TODO this needs some work, messages  should be generated back into the form directly...
                     if (is_object($objResponse) && isset($objResponse->data)) {
                         foreach ($objResponse->data as $k => $objField) {
                             if (is_object($objField) && isset($objField->messages) && isset($objField->attributes->name)) {
                                 if ($form->has($objField->attributes->name)) {
                                     $arr_message = (array) $objField->messages;
                                     $form->get($objField->attributes->name)->setMessages($arr_message);
                                     $form->get($objField->attributes->name)->setValue($request->getPost($objField->attributes->name));
                                 }
                                 //end if
                             }
                             //end if
                         }
                         //end if
                     }
                     //end if
                     //set form errors
                     $form = $this->frontFormHelper()->formatFormErrors($form, $e->getMessage());
                 }
                 //end if
             }
             //end catch
         }
         //end if
     }
     //end if
     $arr_return["form"] = $form;
     $arr_return["form_id"] = $form_id;
     if ($reg_id != "") {
         $arr_return["reg_id"] = $reg_id;
     }
     //end if
     return $arr_return;
 }