[eluser]september28[/eluser]
Yep, well the way I solved this was to copy the valid_email method contents into my valid_hash callback, however your suggestion is better code, since it avoids code replication. So now the callback rule is called callback__decode_email_hash_rule and it first decrypts and then runs the email validation.
Code:
/**
* decode_email_hash_rule
* @param string $str
* @param string $params
* @return bool
* This function wraps decode_hash_rule and _decode_hash to check for a valid Encrypted hash and then valid email if the encrypted hash decrypts correctly
*/
function _decode_email_hash_rule($str='',$params='')
{
$r = $this->_decode_hash_rule($str, $params);
if($r)
{
log_message('debug','decode_email_hash_rule returns: '.$r);
return $this->form_validation->valid_email($r);
}
return FALSE;
}
/*
* _decode_hash_rule
* This is the form validation rule version of the _decode_hash method
*/
function _decode_hash_rule($str='',$params='')
{
list($email_hash, $key) = explode(',', $params);
if( ! $ret = $this->_decode_hash($email_hash, $key))
{
$this->form_validation->set_message('_decode_hash', lang('api_proper_encryption'));
return FALSE;
}
return $ret;
}
/*
* _decode_hash(str, params)
* This is a form validation function that decodes the hashed email.
* If the hashed string is correctly decoded, it is passed back as an unhashed
* string, ready for any other validation rules (such as valid_email)#
* if it fails, an error message is set, and the nothing is returned (string
* will remained unchanged).
*/
function _decode_hash($str='', $key='')
{
$decoded = $this->encrypt->decode($str, $key);
if($decoded)
{
return $decoded;
}
else
{
return FALSE;
}
}
Since the codeigniter user guide says that each validation rule will pass the newly processed data to the next rule, I consider this a bug in the CI code.
Dan