当前位置: 首页>>代码示例>>PHP>>正文


PHP Zend_Validate_Alnum::isValid方法代码示例

本文整理汇总了PHP中Zend_Validate_Alnum::isValid方法的典型用法代码示例。如果您正苦于以下问题:PHP Zend_Validate_Alnum::isValid方法的具体用法?PHP Zend_Validate_Alnum::isValid怎么用?PHP Zend_Validate_Alnum::isValid使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Zend_Validate_Alnum的用法示例。


在下文中一共展示了Zend_Validate_Alnum::isValid方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: testBasic

 /**
  * Ensures that the validator follows expected behavior
  *
  * @return void
  */
 public function testBasic()
 {
     $valuesExpected = array('abc123' => true, 'abc 123' => false, 'abcxyz' => true, 'AZ@#4.3' => false, 'aBc123' => true, '' => false);
     foreach ($valuesExpected as $input => $result) {
         $this->assertEquals($result, $this->_validator->isValid($input));
     }
 }
开发者ID:jorgenils,项目名称:zend-framework,代码行数:12,代码来源:AlnumTest.php

示例2: testAllowWhiteSpace

 /**
  * Ensures that the allowWhiteSpace option works as expected
  *
  * @return void
  */
 public function testAllowWhiteSpace()
 {
     $this->_validator->allowWhiteSpace = true;
     $valuesExpected = array('abc123' => true, 'abc 123' => true, 'abcxyz' => true, 'AZ@#4.3' => false, 'aBc123' => true, '' => false, ' ' => true, "\n" => true, " \t " => true, 'foobar1' => true);
     foreach ($valuesExpected as $input => $result) {
         $this->assertEquals($result, $this->_validator->isValid($input), "Expected '{$input}' to be considered " . ($result ? '' : 'in') . "valid");
     }
 }
开发者ID:jorgenils,项目名称:zend-framework,代码行数:13,代码来源:AlnumTest.php

示例3: testInvalidValueResultsInProperValidationFailureErrors

 /**
  * @return void
  * @deprecated Since 1.5.0
  */
 public function testInvalidValueResultsInProperValidationFailureErrors()
 {
     $this->assertFalse($this->_validator->isValid('#'));
     $errors = $this->_validator->getErrors();
     $arrayExpected = array(Zend_Validate_Alnum::NOT_ALNUM);
     $this->assertThat($errors, $this->identicalTo($arrayExpected));
 }
开发者ID:lortnus,项目名称:zf1,代码行数:11,代码来源:AlnumTest.php

示例4: testIntegerValidation

 /**
  * @ZF-7475
  */
 public function testIntegerValidation()
 {
     $this->assertTrue($this->_validator->isValid(1));
 }
开发者ID:jsnshrmn,项目名称:Suma,代码行数:7,代码来源:AlnumTest.php

示例5: resetpassprocessAction

 /**
  * Processes the new password and stores in DB
  *
  * @return void
  */
 public function resetpassprocessAction()
 {
     if ($this->getRequest()->isPost()) {
         $password = $this->getRequest()->getPost('password');
         $passwordConfirm = $this->getRequest()->getPost('passwordConfirm');
         $guid = $this->getRequest()->getPost('guid');
         //check valid password
         $passwordLengthValidator = new Zend_Validate_StringLength(array('min' => MIN_PASS_CHAR, 'max' => MAX_PASS_CHAR));
         $alNumValidator = new Zend_Validate_Alnum();
         $error = false;
         if (strcmp($password, $passwordConfirm) != 0) {
             $this->_helper->flashMessenger->addMessage('Your passwords do not match.');
             $error = true;
         }
         if (!$passwordLengthValidator->isValid($password)) {
             if (!$alNumValidator->isValid($password)) {
                 $this->_helper->flashMessenger->addMessage('You password must only consist of letters and numbers.');
                 $error = true;
             } else {
                 $this->_helper->flashMessenger->addMessage('Passwords must be between ' . MIN_PASS_CHAR . ' and ' . MAX_CHAR_PASS . ' characters in length.');
                 $error = true;
             }
         }
         //if validation errors, store data in view
         if ($error) {
             $session = new Zend_Session_Namespace();
             $session->flashMessengerClass = 'flashMessagesRed';
             $session->guid = $guid;
             $this->_redirect('/login/resetpass/id/' . $guid . '/');
         } else {
             //register use and redirect to success page
             $options = $this->getInvokeArg('bootstrap')->getOptions();
             $salt = $options['password']['salt'];
             $user = new Model_DbTable_Users();
             $passwordReset = new Model_DbTable_PasswordReset();
             $id = $passwordReset->getID($guid);
             $result = $user->changePassword($id, sha1($password . $salt));
             $username = $user->getUsername($id);
             $email = $user->getEmail($id);
             if ($result != null) {
                 $passwordReset->delete($passwordReset->getAdapter()->quoteInto('guid = ?', $guid));
                 //send email with username and password.
                 $html = '<p>Your new login information is below:</p>' . '<p>Username: ' . $username . '</p>' . '<p>Password: ' . $password . '</p>';
                 $text = "Your new login information is below:\n" . "Username: {$username} . \nPassword: {$password} \n";
                 $this->sendMail($username, $email, $html, $text, 'Account Information');
                 $session = new Zend_Session_Namespace();
                 $session->flashMessengerClass = 'flashMessagesGreen';
                 $this->_helper->flashMessenger->addMessage('Your password has been successfully reset.');
                 $this->_redirect('/login/index/');
             } else {
                 $session = new Zend_Session_Namespace();
                 $session->flashMessengerClass = 'flashMessagesRed';
                 $this->_helper->flashMessenger->addMessage('Your password could not be reset.');
                 $this->_helper->redirector->gotoRoute(array(), 'forgot-password');
             }
         }
     } else {
         $this->_helper->redirector->gotoRoute(array(), 'forgot-password');
     }
 }
开发者ID:seedbank,项目名称:old-repo,代码行数:65,代码来源:AccountController.php

示例6: _validateInputRule

 /**
  * Validate value by attribute input validation rule
  *
  * @param string $value
  * @return string
  */
 protected function _validateInputRule($value)
 {
     // skip validate empty value
     if (empty($value)) {
         return true;
     }
     $label = $this->getAttribute()->getStoreLabel();
     $validateRules = $this->getAttribute()->getValidateRules();
     if (!empty($validateRules['input_validation'])) {
         switch ($validateRules['input_validation']) {
             case 'alphanumeric':
                 $validator = new Zend_Validate_Alnum(true);
                 $validator->setMessage(Mage::helper('customer')->__('"%s" invalid type entered.', $label), Zend_Validate_Alnum::INVALID);
                 $validator->setMessage(Mage::helper('customer')->__('"%s" has not only alphabetic and digit characters.', $label), Zend_Validate_Alnum::NOT_ALNUM);
                 $validator->setMessage(Mage::helper('customer')->__('"%s" is an empty string.', $label), Zend_Validate_Alnum::STRING_EMPTY);
                 if (!$validator->isValid($value)) {
                     return $validator->getMessages();
                 }
                 break;
             case 'numeric':
                 $validator = new Zend_Validate_Digits();
                 $validator->setMessage(Mage::helper('customer')->__('"%s" invalid type entered.', $label), Zend_Validate_Digits::INVALID);
                 $validator->setMessage(Mage::helper('customer')->__('"%s" contains not only digit characters.', $label), Zend_Validate_Digits::NOT_DIGITS);
                 $validator->setMessage(Mage::helper('customer')->__('"%s" is an empty string.', $label), Zend_Validate_Digits::STRING_EMPTY);
                 if (!$validator->isValid($value)) {
                     return $validator->getMessages();
                 }
                 break;
             case 'alpha':
                 $validator = new Zend_Validate_Alpha(true);
                 $validator->setMessage(Mage::helper('customer')->__('"%s" invalid type entered.', $label), Zend_Validate_Alpha::INVALID);
                 $validator->setMessage(Mage::helper('customer')->__('"%s" has not only alphabetic characters.', $label), Zend_Validate_Alpha::NOT_ALPHA);
                 $validator->setMessage(Mage::helper('customer')->__('"%s" is an empty string.', $label), Zend_Validate_Alpha::STRING_EMPTY);
                 if (!$validator->isValid($value)) {
                     return $validator->getMessages();
                 }
                 break;
             case 'email':
                 $validator = new Zend_Validate_EmailAddress();
                 $validator->setMessage(Mage::helper('customer')->__('"%s" invalid type entered.', $label), Zend_Validate_EmailAddress::INVALID);
                 $validator->setMessage(Mage::helper('customer')->__('"%s" is not a valid email address.', $label), Zend_Validate_EmailAddress::INVALID_FORMAT);
                 $validator->setMessage(Mage::helper('customer')->__('"%s" is not a valid hostname.', $label), Zend_Validate_EmailAddress::INVALID_HOSTNAME);
                 $validator->setMessage(Mage::helper('customer')->__('"%s" is not a valid hostname.', $label), Zend_Validate_EmailAddress::INVALID_MX_RECORD);
                 $validator->setMessage(Mage::helper('customer')->__('"%s" is not a valid hostname.', $label), Zend_Validate_EmailAddress::INVALID_MX_RECORD);
                 $validator->setMessage(Mage::helper('customer')->__('"%s" is not a valid email address.', $label), Zend_Validate_EmailAddress::DOT_ATOM);
                 $validator->setMessage(Mage::helper('customer')->__('"%s" is not a valid email address.', $label), Zend_Validate_EmailAddress::QUOTED_STRING);
                 $validator->setMessage(Mage::helper('customer')->__('"%s" is not a valid email address.', $label), Zend_Validate_EmailAddress::INVALID_LOCAL_PART);
                 $validator->setMessage(Mage::helper('customer')->__('"%s" exceeds the allowed length.', $label), Zend_Validate_EmailAddress::LENGTH_EXCEEDED);
                 if (!$validator->isValid($value)) {
                     return array_unique($validator->getMessages());
                 }
                 break;
             case 'url':
                 $parsedUrl = parse_url($value);
                 if ($parsedUrl === false || empty($parsedUrl['scheme']) || empty($parsedUrl['host'])) {
                     return array(Mage::helper('customer')->__('"%s" is not a valid URL.', $label));
                 }
                 $validator = new Zend_Validate_Hostname();
                 if (!$validator->isValid($parsedUrl['host'])) {
                     return array(Mage::helper('customer')->__('"%s" is not a valid URL.', $label));
                 }
                 break;
             case 'date':
                 $format = Mage::app()->getLocale()->getDateFormat(Varien_Date::DATE_INTERNAL_FORMAT);
                 $validator = new Zend_Validate_Date($format);
                 $validator->setMessage(Mage::helper('customer')->__('"%s" invalid type entered.', $label), Zend_Validate_Date::INVALID);
                 $validator->setMessage(Mage::helper('customer')->__('"%s" is not a valid date.', $label), Zend_Validate_Date::INVALID_DATE);
                 $validator->setMessage(Mage::helper('customer')->__('"%s" does not fit the entered date format.', $label), Zend_Validate_Date::FALSEFORMAT);
                 break;
         }
     }
     return true;
 }
开发者ID:votanlean,项目名称:Magento-Pruebas,代码行数:79,代码来源:Abstract.php

示例7: editAction

 public function editAction()
 {
     $layoutPath = APPLICATION_PATH . '/templates/' . TEMPLATE_USED;
     $option = array('layout' => 'hethong/layout', 'layoutPath' => $layoutPath);
     Zend_Layout::startMvc($option);
     $translate = Zend_Registry::get('Zend_Translate');
     $this->view->title = 'Quản lý tài khoản - ' . $translate->_('TEXT_DEFAULT_TITLE');
     $this->view->headTitle($this->view->title);
     $id = $this->_getParam('id', 0);
     $userModel = new Front_Model_Users();
     $employeesModel = new Front_Model_Employees();
     $groupsModel = new Front_Model_Groups();
     $list_employees = $employeesModel->fetchAll();
     $list_groups = $groupsModel->fetchAll();
     $error_message = array();
     $success_message = '';
     $user_info = $userModel->fetchRow('user_id=' . $id);
     if (!$user_info) {
         $error_message[] = 'Không tìm thấy thông tin của tài khoản.';
     }
     if ($this->_request->isPost()) {
         $username = trim($this->_arrParam['username']);
         $password = trim($this->_arrParam['password']);
         $employee = $this->_arrParam['employee'];
         $group = $this->_arrParam['group'];
         $status = $this->_arrParam['status'];
         $validator_length = new Zend_Validate_StringLength(array('min' => 4, 'max' => 12));
         $validator_username = new Zend_Validate_Alnum(array('allowWhiteSpace' => false));
         //kiem tra dữ liệu
         if (!$validator_length->isValid($username)) {
             $error_message[] = 'Tên tài khoản phải bằng hoặc hơn 4 ký tự và nhỏ hơn hoặc bằng 12 ký tự.';
         }
         if (!$validator_username->isValid($username)) {
             $error_message[] = 'Tên tài khoản không không được chứa khoảng trắng.';
         }
         if ($password) {
             if (!$validator_length->isValid($password)) {
                 $error_message[] = 'Mật khẩu phải bằng hoặc hơn 4 ký tự và nhỏ hơn hoặc bằng 12 ký tự.';
             }
         }
         //check username đã tồn tại
         $check_username = $userModel->fetchRow('username="' . $username . '" and username !="' . $user_info->username . '"');
         if ($check_username) {
             $error_message[] = 'Tên đăng nhập <strong>' . $username . '</strong> đã tồn tại.';
         }
         //check employee
         $check_employee = $userModel->fetchRow('em_id=' . $employee . ' and em_id !=' . $user_info->em_id);
         if ($check_employee) {
             $error_message[] = 'Nhân viên <strong>' . $this->view->viewGetName($employee) . '</strong> đã có tài khoản rồi.';
         }
         if (!sizeof($error_message)) {
             $current_time = new Zend_Db_Expr('NOW()');
             $userModel->update(array('em_id' => $employee, 'group_id' => $group, 'username' => $username, 'status' => $status, 'date_modified' => $current_time), 'user_id=' . $id);
             if ($password) {
                 $userModel->update(array('password' => md5($password)), 'user_id=' . $id);
             }
             $user_info->em_id = $employee;
             $user_info->group_id = $group;
             $user_info->username = $username;
             $user_info->status = $status;
             $success_message = 'Đã cập nhật thông tin tài khoản thành công.';
         }
     }
     $this->view->user_info = $user_info;
     $this->view->success_message = $success_message;
     $this->view->error_message = $error_message;
     $this->view->list_groups = $list_groups;
     $this->view->list_employees = $list_employees;
 }
开发者ID:rongandat,项目名称:phanloaicanbo,代码行数:69,代码来源:UsersController.php

示例8:

 $recaptcha = new Zend_Service_ReCaptcha($public_key, $private_key);
 if (isset($_POST['send'])) {
     // validate the user input
     //
     if (empty($_POST['recaptcha_response_field'])) {
         $errors['recaptcha'] = 'reCAPTCHA field is required';
     } else {
         $result = $recaptcha->verify($_POST['recaptcha_challenge_field'], $_POST['recaptcha_response_field']);
         if (!$result->isValid()) {
             $errors['recaptcha'] = 'Try again';
         }
     }
     // Validate nmae
     //
     $val = new Zend_Validate_Alnum(TRUE);
     if (!$val->isValid($_POST['name'])) {
         $errors['name'] = 'Name is required';
     }
     // Validate email address
     //
     $val = new Zend_Validate_EmailAddress();
     if (!$val->isValid($_POST['email'])) {
         $errors['email'] = 'Email address is required';
     }
     // Validate comments
     //
     $val = new Zend_Validate_StringLength(10);
     if (!$val->isValid($_POST['comments'])) {
         $errors['comments'] = 'Required';
     }
     if (!$errors) {
开发者ID:colasad,项目名称:code,代码行数:31,代码来源:process_comments.php

示例9: _validateInputRule

 /**
  * Validate value by attribute input validation rule
  *
  * @param string $value
  * @return string
  */
 protected function _validateInputRule($value)
 {
     // skip validate empty value
     if (empty($value)) {
         return true;
     }
     $label = Mage::helper('customer')->__($this->getAttribute()->getStoreLabel());
     $validateRules = $this->getAttribute()->getValidateRules();
     if (!empty($validateRules['input_validation'])) {
         switch ($validateRules['input_validation']) {
             case 'alphanumeric':
                 $validator = new Zend_Validate_Alnum(true);
                 $validator->setMessage(Mage::helper('customer')->__('"%s" invalid type entered.', $label), Zend_Validate_Alnum::INVALID);
                 $validator->setMessage(Mage::helper('customer')->__('"%s" has not only alphabetic and digit characters.', $label), Zend_Validate_Alnum::NOT_ALNUM);
                 $validator->setMessage(Mage::helper('customer')->__('"%s" is an empty string.', $label), Zend_Validate_Alnum::STRING_EMPTY);
                 if (!$validator->isValid($value)) {
                     return $validator->getMessages();
                 }
                 break;
             case 'numeric':
                 $validator = new Zend_Validate_Digits();
                 $validator->setMessage(Mage::helper('customer')->__('"%s" invalid type entered.', $label), Zend_Validate_Digits::INVALID);
                 $validator->setMessage(Mage::helper('customer')->__('"%s" contains not only digit characters.', $label), Zend_Validate_Digits::NOT_DIGITS);
                 $validator->setMessage(Mage::helper('customer')->__('"%s" is an empty string.', $label), Zend_Validate_Digits::STRING_EMPTY);
                 if (!$validator->isValid($value)) {
                     return $validator->getMessages();
                 }
                 break;
             case 'alpha':
                 $validator = new Zend_Validate_Alpha(true);
                 $validator->setMessage(Mage::helper('customer')->__('"%s" invalid type entered.', $label), Zend_Validate_Alpha::INVALID);
                 $validator->setMessage(Mage::helper('customer')->__('"%s" has not only alphabetic characters.', $label), Zend_Validate_Alpha::NOT_ALPHA);
                 $validator->setMessage(Mage::helper('customer')->__('"%s" is an empty string.', $label), Zend_Validate_Alpha::STRING_EMPTY);
                 if (!$validator->isValid($value)) {
                     return $validator->getMessages();
                 }
                 break;
             case 'email':
                 /**
                 $this->__("'%value%' appears to be a DNS hostname but the given punycode notation cannot be decoded")
                 $this->__("Invalid type given. String expected")
                 $this->__("'%value%' appears to be a DNS hostname but contains a dash in an invalid position")
                 $this->__("'%value%' does not match the expected structure for a DNS hostname")
                 $this->__("'%value%' appears to be a DNS hostname but cannot match against hostname schema for TLD '%tld%'")
                 $this->__("'%value%' does not appear to be a valid local network name")
                 $this->__("'%value%' does not appear to be a valid URI hostname")
                 $this->__("'%value%' appears to be an IP address, but IP addresses are not allowed")
                 $this->__("'%value%' appears to be a local network name but local network names are not allowed")
                 $this->__("'%value%' appears to be a DNS hostname but cannot extract TLD part")
                 $this->__("'%value%' appears to be a DNS hostname but cannot match TLD against known list")
                 */
                 $validator = new Zend_Validate_EmailAddress();
                 $validator->setMessage(Mage::helper('customer')->__('"%s" invalid type entered.', $label), Zend_Validate_EmailAddress::INVALID);
                 $validator->setMessage(Mage::helper('customer')->__('"%s" is not a valid email address.', $label), Zend_Validate_EmailAddress::INVALID_FORMAT);
                 $validator->setMessage(Mage::helper('customer')->__('"%s" is not a valid hostname.', $label), Zend_Validate_EmailAddress::INVALID_HOSTNAME);
                 $validator->setMessage(Mage::helper('customer')->__('"%s" is not a valid hostname.', $label), Zend_Validate_EmailAddress::INVALID_MX_RECORD);
                 $validator->setMessage(Mage::helper('customer')->__('"%s" is not a valid hostname.', $label), Zend_Validate_EmailAddress::INVALID_MX_RECORD);
                 $validator->setMessage(Mage::helper('customer')->__('"%s" is not a valid email address.', $label), Zend_Validate_EmailAddress::DOT_ATOM);
                 $validator->setMessage(Mage::helper('customer')->__('"%s" is not a valid email address.', $label), Zend_Validate_EmailAddress::QUOTED_STRING);
                 $validator->setMessage(Mage::helper('customer')->__('"%s" is not a valid email address.', $label), Zend_Validate_EmailAddress::INVALID_LOCAL_PART);
                 $validator->setMessage(Mage::helper('customer')->__('"%s" exceeds the allowed length.', $label), Zend_Validate_EmailAddress::LENGTH_EXCEEDED);
                 $validator->setMessage(Mage::helper('customer')->__("'%value%' appears to be an IP address, but IP addresses are not allowed"), Zend_Validate_Hostname::IP_ADDRESS_NOT_ALLOWED);
                 $validator->setMessage(Mage::helper('customer')->__("'%value%' appears to be a DNS hostname but cannot match TLD against known list"), Zend_Validate_Hostname::UNKNOWN_TLD);
                 $validator->setMessage(Mage::helper('customer')->__("'%value%' appears to be a DNS hostname but contains a dash in an invalid position"), Zend_Validate_Hostname::INVALID_DASH);
                 $validator->setMessage(Mage::helper('customer')->__("'%value%' appears to be a DNS hostname but cannot match against hostname schema for TLD '%tld%'"), Zend_Validate_Hostname::INVALID_HOSTNAME_SCHEMA);
                 $validator->setMessage(Mage::helper('customer')->__("'%value%' appears to be a DNS hostname but cannot extract TLD part"), Zend_Validate_Hostname::UNDECIPHERABLE_TLD);
                 $validator->setMessage(Mage::helper('customer')->__("'%value%' does not appear to be a valid local network name"), Zend_Validate_Hostname::INVALID_LOCAL_NAME);
                 $validator->setMessage(Mage::helper('customer')->__("'%value%' appears to be a local network name but local network names are not allowed"), Zend_Validate_Hostname::LOCAL_NAME_NOT_ALLOWED);
                 $validator->setMessage(Mage::helper('customer')->__("'%value%' appears to be a DNS hostname but the given punycode notation cannot be decoded"), Zend_Validate_Hostname::CANNOT_DECODE_PUNYCODE);
                 if (!$validator->isValid($value)) {
                     return array_unique($validator->getMessages());
                 }
                 break;
             case 'url':
                 $parsedUrl = parse_url($value);
                 if ($parsedUrl === false || empty($parsedUrl['scheme']) || empty($parsedUrl['host'])) {
                     return array(Mage::helper('customer')->__('"%s" is not a valid URL.', $label));
                 }
                 $validator = new Zend_Validate_Hostname();
                 if (!$validator->isValid($parsedUrl['host'])) {
                     return array(Mage::helper('customer')->__('"%s" is not a valid URL.', $label));
                 }
                 break;
             case 'date':
                 $validator = new Zend_Validate_Date(Varien_Date::DATE_INTERNAL_FORMAT);
                 $validator->setMessage(Mage::helper('customer')->__('"%s" invalid type entered.', $label), Zend_Validate_Date::INVALID);
                 $validator->setMessage(Mage::helper('customer')->__('"%s" is not a valid date.', $label), Zend_Validate_Date::INVALID_DATE);
                 $validator->setMessage(Mage::helper('customer')->__('"%s" does not fit the entered date format.', $label), Zend_Validate_Date::FALSEFORMAT);
                 if (!$validator->isValid($value)) {
                     return array_unique($validator->getMessages());
                 }
                 break;
         }
     }
//.........这里部分代码省略.........
开发者ID:xiaoguizhidao,项目名称:emporiodopara,代码行数:101,代码来源:Abstract.php

示例10: setName

 /** Set the name to query
  * @access Public
  * @param string $name
  * @return string
  * @throws Pas_Geo_Mapit_Exception
  */
 public function setName($name)
 {
     if (is_string($name)) {
         $validator = new Zend_Validate_Alnum($allowWhiteSpace = true);
         if (!$validator->isValid($name)) {
             throw new Pas_Geo_Mapit_Exception('That string is not valid', 500);
         } else {
             return $this->_name = $name;
         }
     } else {
         throw new Pas_Geo_Mapit_Exception('The names to search for must be a string', 500);
     }
 }
开发者ID:lesleyauk,项目名称:findsorguk,代码行数:19,代码来源:Areas.php

示例11: validateFormAndGetCRL

 private function validateFormAndGetCRL(&$validationErrors)
 {
     $registry = Zend_Registry::getInstance();
     $translate = $registry->get("Zend_Translate");
     $validationErrors = array();
     $crl = new SSLCRL();
     $validate_alnum_wspace = new Zend_Validate_Alnum(array('allowWhiteSpace' => true));
     // TODO: validate id field?
     $id = $_POST['crl_id'];
     $crl->setId($id);
     $name = $_POST['crl_name'];
     if (!$validate_alnum_wspace->isValid($name)) {
         $validationErrors['crl_name'] = $translate->translate("The CRL name must be only alpha-numeric characters");
     }
     $crl->setDisplayName($_POST['crl_name']);
     if (isset($_FILES['crl_file']) && !empty($_FILES['crl_file']['name'])) {
         if (!$_FILES['crl_file']['error']) {
             $contents = file_get_contents($_FILES['crl_file']['tmp_name']);
             if ($contents !== false) {
                 $crl->setContent($contents);
             } else {
                 $validationErrors['crl_file'] = $translate->translate("There was an error getting contents of CRL file.");
             }
         } else {
             $validationErrors['crl_file'] = $translate->translate("There was an error uploading file: ") . $_FILES['content']['error'];
         }
     } else {
         if (empty($id)) {
             $validationErrors['crl_file'] = $translate->translate("Please upload a CRL file.");
         }
     }
     return $crl;
 }
开发者ID:kyroskoh,项目名称:apigrove,代码行数:33,代码来源:CertificateController.php

示例12: registerAction

 public function registerAction()
 {
     //Check to see if user is already login
     if ($this->loggedEmail) {
         $this->_redirect('/');
         return;
     }
     //get referrer
     $ns = new Zend_Session_Namespace('referrer');
     $this->view->referby = $ns->referrer;
     if ($this->getRequest()->isPost()) {
         //Validation
         // Valid email address?
         if (!Zend_Validate::is($this->_request->getPost('email'), 'EmailAddress') && $this->_request->getPost('email') != 'me2@localhost') {
             $this->view->errors[] = "Invalid e-mail address.";
         }
         //E-mail cannot already exist in the database
         $user = new Default_Model_User();
         $foundUser = $user->getUserByEmail($this->_request->getPost('email'));
         if (isset($foundUser->id)) {
             $this->view->errors[] = "Email address already in database.";
         }
         //Handle must be between 2-20 characters
         $validator = new Zend_Validate_StringLength(2, 20);
         if (!$validator->isValid($this->_request->getPost('handle'))) {
             $this->view->errors[] = "Handle must be between 2 and 14 characters.";
         }
         // Handle must consist solely of alphanumeric characters
         $validHandle = new Zend_Validate_Alnum();
         if (!$validHandle->isValid($this->_request->getPost('handle'))) {
             $this->view->errors[] = "Handle must consist of letters and numbers.";
         }
         // end valid handle
         // Handle cannot already exist in database
         $foundUser = $user->getUserByHandle($this->_request->getPost('handle'));
         if (isset($foundUser->id)) {
             $this->view->errors[] = "Handle already exists in database.";
         }
         // Password must between 6 to 20 characters
         $validPswd = new Zend_Validate_StringLength(6, 20);
         if (!$validPswd->isValid($this->_request->getPost('password'))) {
             $this->view->errors[] = "Password must be at least 6 characters.";
         }
         // end valid password
         // First name must not be empty
         $validFirstName = new Zend_Validate_NotEmpty();
         if (!$validFirstName->isValid($this->_request->getPost('first_name'))) {
             $this->view->errors[] = "Please provide your first name.";
         }
         // end valid first name
         // Last name must not be empty
         $validLastName = new Zend_Validate_NotEmpty();
         if (!$validLastName->isValid($this->_request->getPost('last_name'))) {
             $this->view->errors[] = "Please provide your last name.";
         }
         // end valid last name
         // Valid gender?
         if (!Zend_Validate::is($this->_request->getPost('gender'), 'NotEmpty')) {
             $this->view->errors[] = "Please identify your gender.";
         }
         // end valid gender
         //Address not empty?
         if (!Zend_Validate::is($this->_request->getPost('address'), 'NotEmpty')) {
             $this->view->errors[] = "Please enter your address.";
         }
         //if errors exist, prepopulate the form
         if (count($this->view->errors) > 0) {
             $this->view->email = $this->_request->getPost('email');
             $this->view->handle = $this->_request->getPost('handle');
             $this->view->first_name = $this->_request->getPost('first_name');
             $this->view->last_name = $this->_request->getPost('last_name');
             $this->view->gender = $this->_request->getPost('gender');
             $this->view->address = $this->_request->getPost('address');
         } else {
             //No errors, add user to the database and send confirmation e-mail
             //Generate random keys used for registration confirmation
             $registrationKey = $this->_helper->generator(32, 'alpha');
             // Prepare the data array for database insertion
             $data = array('email' => $this->_request->getPost('email'), 'password' => md5($this->_request->getPost('password')), 'registration_key' => $registrationKey, 'handle' => $this->_request->getPost('handle'), 'first_name' => $this->_request->getPost('first_name'), 'last_name' => $this->_request->getPost('last_name'), 'gender' => $this->_request->getPost('gender'), 'address' => $this->_request->getPost('address'), 'created_at' => date('Y-m-d H:i:s'), 'updated_at' => date('Y-m-d H:i:s'), 'last_login' => date('Y-m-d H:i:s'), 'referby' => $this->_request->getPost('referrer'));
             //Create a new mail object
             try {
                 $mail = new Zend_Mail();
                 // Set the From, To, and Subject headers
                 $mail->setFrom($this->config->email->from_admin);
                 $mail->addTo($this->_request->getPost('email'), "{$this->_request->getPost('first_name')}\n\t\t\t\t\t {$this->_request->getPost('last_name')}");
                 $mail->setSubject('Your game account has been created');
                 // Retrieve the e-mail template
                 include "emailTemplates/_email-confirm-registration.phtml";
                 // Attach the e-mail template to the e-mail and send it
                 $mail->setBodyText($email);
                 $mail->send();
                 $this->view->success = 1;
             } catch (Exception $e) {
                 $this->view->errors[] = "We were unable to send your confirmation \t\t\n\t\t\t\t\t\t e-mail.\n\t\t\t\t\tPlease contact {$this->config->email->support}.";
             }
             //If succcessful at sending mail, insert into database
             if ($this->view->success == 1) {
                 // Insert the registration data into the database
                 $user = new Default_Model_User();
                 $user->insert($data);
//.........这里部分代码省略.........
开发者ID:statcode,项目名称:zend-gamers-controller,代码行数:101,代码来源:GamersController.php

示例13: IsValidUsername

 public static function IsValidUsername($username)
 {
     $validator = new Zend_Validate_Alnum();
     //validates only if the username contain alphebetical and numeric values.
     return $validator->isValid($username);
 }
开发者ID:vinnivinsachi,项目名称:Vincent-DR,代码行数:6,代码来源:User.php

示例14: indexAction

 /**
  * The default action is "indexAction", unless explcitly set to something else.
  */
 public function indexAction()
 {
     // STAGE 4: Apply business logic to create a presentation model for the view.
     $origRequest = $this->getInvokeArg('origRequest');
     $this->view->rerouteToReason = $this->getInvokeArg('rerouteToReason');
     $this->view->origRequestUri = $origRequest->REQUEST_URI;
     // if no credentials
     if (empty($_REQUEST['username'])) {
         // should be _POST, but this makes demo easier to tweak
         // STAGE 5: Choose view template and submit presentation model to view template for rendering.
         // if an admin area was requested, and authentication has been enabled in config.ini
         if (isset($this->authSpace->authenticationId)) {
             ZFDemo_Log::log(_('already have authentication id, showing logout form'));
             $this->_forward('logoutDecision');
             // show logout form
         } else {
             ZFDemo_Log::log(_('no authentication id, showing login form'));
             $this->renderToSegment('body');
             // show login form
         }
         return;
     }
     // prepare to authenticate credentials received from a form
     require_once 'Zend/Auth/Result.php';
     require_once 'Zend/Auth/Adapter/Digest.php';
     $config = Zend_Registry::get('config');
     $username = trim($_REQUEST['username']);
     // ought to be _POST, but this simplifies experimentation
     $password = trim($_REQUEST['password']);
     // by the reader of the tutorial
     // filtering will be added in a later section
     /////////////////////////////
     // ==> SECTION: filter <==
     require_once 'Zend/Validate/Alnum.php';
     require_once 'Zend/Validate/Regex.php';
     // input filtering is enabled, so ..
     $validator_name = new Zend_Validate_Alnum();
     // alphabetic and numeric characters are permitted
     if (!$validator_name->isValid($username)) {
         $this->renderToSegment('body', 'invalidUsername');
         return;
     }
     // this application has "special" requirements, so we show how to use custom regex:
     $validator_password = new Zend_Validate_Regex('/^[a-z0-9_]{5,16}$/');
     if (!$validator_password->isValid($password)) {
         $this->renderToSegment('body', 'invalidPassword');
         return;
     }
     /////////////////////////////
     // ==> SECTION: auth <==
     $result = false;
     try {
         // try to authenticate using the md5 "digest" adapter
         $filename = $config->authenticate->filename;
         // file containing username:realm:password digests
         if ($filename[0] !== DIRECTORY_SEPARATOR) {
             $filename = Zend_Registry::get('dataDir') . $filename;
             // prepend path, if filename not absolute
         }
         $adapter = new Zend_Auth_Adapter_Digest($filename, $config->authenticate->realm, $username, $password);
         $result = $adapter->authenticate();
         // result of trying to authenticate credentials
         $this->view->resultCode = $result->getCode();
         // allow view to see result status (reason)
     } catch (Exception $exception) {
         $this->view->exception = ZFDemo::filterException($exception);
         // record exception description
         $this->view->resultCode = false;
     }
     if ($result && $result->isValid()) {
         // if successful authentication, save the authentication identity ( http://framework.zend.com/wiki/x/fUw )
         $id = $result->getIdentity();
         Zend_Registry::set('authenticationId', $id);
         // publish the identity (really need Observer pattern)
         $this->authSpace->authenticationId = $id;
         $this->authSpace->date = time();
         // save the timestamp when authenticated successfully
         $this->authSpace->attempts = 0;
         // success, so forget the number of previous login failures
         // @TODO: filter this ...
         $this->_redirect($_REQUEST['origPathInfo']);
         // now return to wherever user came from
     } else {
         $this->authSpace->attempts++;
         // record the authentication failure
         if ($this->authSpace->attempts > $config->authenticate->maxAttempts) {
             // Overly simplistic account "lockout" lasts for at least 10 seconds,
             // but increases with repeated failures.
             $this->view->lockout = 5 * $this->authSpace->attempts;
             // Lockout time will be "forgotten" later, and expired from session, allowing logins.
             $this->authSpace->setExpirationSeconds($this->view->lockout);
             $this->blockHacker();
             // show a view indicating account lockout
             return;
         }
     }
     // STAGE 5: Choose view template and submit presentation model to view template for rendering.
//.........这里部分代码省略.........
开发者ID:jorgenils,项目名称:zend-framework,代码行数:101,代码来源:LogonController.php

示例15: takenAction

 public function takenAction()
 {
     $username = $this->_getParam('username');
     $email = $this->_getParam('email');
     // Sent both or neither username/email
     if ((bool) $username == (bool) $email) {
         $this->view->status = false;
         $this->view->error = Zend_Registry::get('Zend_Translate')->_('Invalid param count');
         return;
     }
     // Username must be alnum
     if ($username) {
         $validator = new Zend_Validate_Alnum();
         if (!$validator->isValid($username)) {
             $this->view->status = false;
             $this->view->error = Zend_Registry::get('Zend_Translate')->_('Invalid param value');
             //$this->view->errors = $validator->getErrors();
             return;
         }
         $table = Engine_Api::_()->getItemTable('user');
         $row = $table->fetchRow($table->select()->where('username = ?', $username)->limit(1));
         $this->view->status = true;
         $this->view->taken = $row !== null;
         return;
     }
     if ($email) {
         $validator = new Zend_Validate_EmailAddress();
         if (!$validator->isValid($email)) {
             $this->view->status = false;
             $this->view->error = Zend_Registry::get('Zend_Translate')->_('Invalid param value');
             //$this->view->errors = $validator->getErrors();
             return;
         }
         $table = Engine_Api::_()->getItemTable('user');
         $row = $table->fetchRow($table->select()->where('email = ?', $email)->limit(1));
         $this->view->status = true;
         $this->view->taken = $row !== null;
         return;
     }
 }
开发者ID:robeendey,项目名称:ce,代码行数:40,代码来源:SignupController.php


注:本文中的Zend_Validate_Alnum::isValid方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。