public function __construct() { parent::__construct('ccbill-config-form'); $language = OW::getLanguage(); $billingService = BOL_BillingService::getInstance(); $gwKey = BILLINGCCBILL_CLASS_CcbillAdapter::GATEWAY_KEY; $clientAccnum = new TextField('clientAccnum'); $clientAccnum->setValue($billingService->getGatewayConfigValue($gwKey, 'clientAccnum')); $this->addElement($clientAccnum); $clientSubacc = new TextField('clientSubacc'); $clientSubacc->setValue($billingService->getGatewayConfigValue($gwKey, 'clientSubacc')); $this->addElement($clientSubacc); $adapter = new BILLINGCCBILL_CLASS_CcbillAdapter(); $subAccounts = $adapter->getAdditionalSubaccounts(); if ($subAccounts) { foreach ($subAccounts as $key => $sub) { $field = new TextField($key); $field->setLabel($sub['label']); $field->setValue($sub['value']); $this->addElement($field); } } $ccFormName = new TextField('ccFormName'); $ccFormName->setValue($billingService->getGatewayConfigValue($gwKey, 'ccFormName')); $this->addElement($ccFormName); $ckFormName = new TextField('ckFormName'); $ckFormName->setValue($billingService->getGatewayConfigValue($gwKey, 'ckFormName')); $this->addElement($ckFormName); $dpFormName = new TextField('dpFormName'); $dpFormName->setValue($billingService->getGatewayConfigValue($gwKey, 'dpFormName')); $this->addElement($dpFormName); $edFormName = new TextField('edFormName'); $edFormName->setValue($billingService->getGatewayConfigValue($gwKey, 'edFormName')); $this->addElement($edFormName); $dynamicPricingSalt = new TextField('dynamicPricingSalt'); $dynamicPricingSalt->setValue($billingService->getGatewayConfigValue($gwKey, 'dynamicPricingSalt')); $this->addElement($dynamicPricingSalt); $datalinkUsername = new TextField('datalinkUsername'); $datalinkUsername->setValue($billingService->getGatewayConfigValue($gwKey, 'datalinkUsername')); $this->addElement($datalinkUsername); $datalinkPassword = new PasswordField('datalinkPassword'); $datalinkPassword->setValue($billingService->getGatewayConfigValue($gwKey, 'datalinkPassword')); $this->addElement($datalinkPassword); // submit $submit = new Submit('save'); $submit->setValue($language->text('billingccbill', 'btn_save')); $this->addElement($submit); }
/** * Validate this field * * @param Validator $validator * @return bool */ public function validate($validator) { $name = $this->name; // if field isn't visible, don't validate if (!$this->isSaveable()) { return true; } $this->passwordField->setValue($this->value); $this->confirmPasswordfield->setValue($this->confirmValue); $value = $this->passwordField->Value(); // both password-fields should be the same if ($value != $this->confirmPasswordfield->Value()) { $validator->validationError($name, _t('Form.VALIDATIONPASSWORDSDONTMATCH', "Passwords don't match"), "validation"); return false; } if (!$this->canBeEmpty) { // both password-fields shouldn't be empty if (!$value || !$this->confirmPasswordfield->Value()) { $validator->validationError($name, _t('Form.VALIDATIONPASSWORDSNOTEMPTY', "Passwords can't be empty"), "validation"); return false; } } // lengths if ($this->minLength || $this->maxLength) { $errorMsg = null; $limit = null; if ($this->minLength && $this->maxLength) { $limit = "{{$this->minLength},{$this->maxLength}}"; $errorMsg = _t('ConfirmedPasswordField.BETWEEN', 'Passwords must be {min} to {max} characters long.', array('min' => $this->minLength, 'max' => $this->maxLength)); } elseif ($this->minLength) { $limit = "{{$this->minLength}}.*"; $errorMsg = _t('ConfirmedPasswordField.ATLEAST', 'Passwords must be at least {min} characters long.', array('min' => $this->minLength)); } elseif ($this->maxLength) { $limit = "{0,{$this->maxLength}}"; $errorMsg = _t('ConfirmedPasswordField.MAXIMUM', 'Passwords must be at most {max} characters long.', array('max' => $this->maxLength)); } $limitRegex = '/^.' . $limit . '$/'; if (!empty($value) && !preg_match($limitRegex, $value)) { $validator->validationError($name, $errorMsg, "validation"); } } if ($this->requireStrongPassword) { if (!preg_match('/^(([a-zA-Z]+\\d+)|(\\d+[a-zA-Z]+))[a-zA-Z0-9]*$/', $value)) { $validator->validationError($name, _t('Form.VALIDATIONSTRONGPASSWORD', "Passwords must have at least one digit and one alphanumeric character"), "validation"); return false; } } // Check if current password is valid if (!empty($value) && $this->getRequireExistingPassword()) { if (!$this->currentPasswordValue) { $validator->validationError($name, _t('ConfirmedPasswordField.CURRENT_PASSWORD_MISSING', "You must enter your current password."), "validation"); return false; } // Check this password is valid for the current user $member = Member::currentUser(); if (!$member) { $validator->validationError($name, _t('ConfirmedPasswordField.LOGGED_IN_ERROR', "You must be logged in to change your password."), "validation"); return false; } // With a valid user and password, check the password is correct $checkResult = $member->checkPassword($this->currentPasswordValue); if (!$checkResult->valid()) { $validator->validationError($name, _t('ConfirmedPasswordField.CURRENT_PASSWORD_ERROR', "The current password you have entered is not correct."), "validation"); return false; } } return true; }