本文整理汇总了PHP中SugarEmailAddress::isValidEmail方法的典型用法代码示例。如果您正苦于以下问题:PHP SugarEmailAddress::isValidEmail方法的具体用法?PHP SugarEmailAddress::isValidEmail怎么用?PHP SugarEmailAddress::isValidEmail使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SugarEmailAddress
的用法示例。
在下文中一共展示了SugarEmailAddress::isValidEmail方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: evaluate
/**
* Returns itself when evaluating.
*/
function evaluate()
{
$emailStr = $this->getParameters()->evaluate();
if ($emailStr == "") {
return AbstractExpression::$TRUE;
}
$lastChar = $emailStr[strlen($emailStr) - 1];
if (!preg_match('/[^\\.]/i', $lastChar)) {
return AbstractExpression::$FALSE;
}
// validate it
$emailArr = preg_split('/[,;]/', $emailStr);
for ($i = 0; $i < sizeof($emailArr); $i++) {
$emailAddress = trim($emailArr[$i]);
if ($emailAddress != '' && !SugarEmailAddress::isValidEmail($emailAddress)) {
return AbstractExpression::$FALSE;
}
}
return AbstractExpression::$TRUE;
}
示例2: apiSave
/**
* This should be called when the bean is saved from the API.
* Most fields can just use default, which calls the field's
* individual ->save() function instead.
*
* @param SugarBean $bean the bean performing the save
* @param array $params an array of parameters relevant to the save, which will be an array passed up to the API
* @param string $field The name of the field to save (the vardef name, not the form element name)
* @param array $properties Any properties for this field
*/
public function apiSave(SugarBean $bean, array $params, $field, $properties)
{
if (!is_array($params[$field])) {
// Not an array, don't do anything.
return;
}
if (!isset($bean->emailAddress)) {
$bean->emailAddress = BeanFactory::getBean('EmailAddresses');
}
if (empty($bean->emailAddress->addresses) && !isset($bean->emailAddress->hasFetched)) {
$oldAddresses = $bean->emailAddress->getAddressesByGUID($bean->id, $bean->module_name);
} else {
$oldAddresses = $bean->emailAddress->addresses;
}
array_walk($params[$field], array($this, 'formatEmails'));
$bean->emailAddress->addresses = array();
foreach ($params[$field] as $email) {
if (empty($email['email_address'])) {
// Can't save an empty email address
continue;
}
// Search each one for a matching set, otherwise use the defaults
$mergeAddr = array('primary_address' => false, 'invalid_email' => false, 'opt_out' => false);
foreach ($oldAddresses as $address) {
if (strtolower($address['email_address']) == strtolower($email['email_address'])) {
$mergeAddr = $address;
break;
}
}
$email = array_merge($mergeAddr, $email);
if (!SugarEmailAddress::isValidEmail($email['email_address'])) {
require_once 'include/api/SugarApiException.php';
throw new SugarApiExceptionInvalidParameter("{$email['email_address']} is an invalid email address");
}
$bean->emailAddress->addAddress($email['email_address'], $email['primary_address'], false, $email['invalid_email'], $email['opt_out']);
}
$bean->emailAddress->save($bean->id, $bean->module_dir, $params[$field]);
// Here is a hack for SugarEmailAddress.php so it doesn't attempt a legacy save
$bean->emailAddress->dontLegacySave = true;
$bean->emailAddress->populateLegacyFields($bean);
}
示例3: requestPassword
/**
* Resets password and sends email to user
* @param $api
* @param array $args
* @return bool
* @throws SugarApiExceptionRequestMethodFailure
* @throws SugarApiExceptionMissingParameter
*/
public function requestPassword($api, $args)
{
require_once 'modules/Users/language/en_us.lang.php';
$res = $GLOBALS['sugar_config']['passwordsetting'];
$requiredParams = array('email', 'username');
if (!$GLOBALS['sugar_config']['passwordsetting']['forgotpasswordON']) {
throw new SugarApiExceptionRequestMethodFailure(translate('LBL_FORGOTPASSORD_NOT_ENABLED', 'Users'), $args);
}
foreach ($requiredParams as $key => $param) {
if (!isset($args[$param])) {
throw new SugarApiExceptionMissingParameter('Error: Missing argument.', $args);
}
}
$usr = empty($this->usr) ? new User() : $this->usr;
$useremail = $args['email'];
$username = $args['username'];
if (!empty($username) && !empty($useremail)) {
$usr_id = $usr->retrieve_user_id($username);
$usr->retrieve($usr_id);
if (!$usr->isPrimaryEmail($useremail)) {
throw new SugarApiExceptionRequestMethodFailure(translate('LBL_PROVIDE_USERNAME_AND_EMAIL', 'Users'), $args);
}
if ($usr->portal_only || $usr->is_group) {
throw new SugarApiExceptionRequestMethodFailure(translate('LBL_PROVIDE_USERNAME_AND_EMAIL', 'Users'), $args);
}
// email invalid can not reset password
if (!SugarEmailAddress::isValidEmail($usr->emailAddress->getPrimaryAddress($usr))) {
throw new SugarApiExceptionRequestMethodFailure(translate('ERR_EMAIL_INCORRECT', 'Users'), $args);
}
$isLink = !$GLOBALS['sugar_config']['passwordsetting']['SystemGeneratedPasswordON'];
// if i need to generate a password (not a link)
$password = $isLink ? '' : User::generatePassword();
// Create URL
// if i need to generate a link
if ($isLink) {
$guid = create_guid();
$url = $GLOBALS['sugar_config']['site_url'] . "/index.php?entryPoint=Changenewpassword&guid={$guid}";
$time_now = TimeDate::getInstance()->nowDb();
$q = "INSERT INTO users_password_link (id, username, date_generated) VALUES('" . $guid . "','" . $username . "','" . $time_now . "') ";
$usr->db->query($q);
}
if ($isLink && isset($res['lostpasswordtmpl'])) {
$emailTemp_id = $res['lostpasswordtmpl'];
} else {
$emailTemp_id = $res['generatepasswordtmpl'];
}
$additionalData = array('link' => $isLink, 'password' => $password);
if (isset($url)) {
$additionalData['url'] = $url;
}
$result = $usr->sendEmailForPassword($emailTemp_id, $additionalData);
if ($result['status']) {
return true;
} elseif ($result['message'] != '') {
throw new SugarApiExceptionRequestMethodFailure($result['message'], $args);
} else {
throw new SugarApiExceptionRequestMethodFailure('LBL_EMAIL_NOT_SENT', $args);
}
} else {
throw new SugarApiExceptionMissingParameter('Error: Empty argument', $args);
}
}
示例4: splitEmailAddress
public function splitEmailAddress($addr)
{
$email = $this->_cleanAddress($addr);
if (!SugarEmailAddress::isValidEmail($email)) {
$email = '';
// remove bad email addr
}
$name = trim(str_replace(array($email, '<', '>', '"', "'"), '', $addr));
return array("name" => $name, "email" => strtolower($email));
}
示例5: validateEmailAddresses
/**
* Validates email addresses. The return value is an array of key-value pairs where the keys are the email
* addresses and the values are booleans indicating whether or not the email address is valid.
*
* @param $api
* @param $args
* @return array
* @throws SugarApiException
*/
public function validateEmailAddresses($api, $args)
{
$validatedEmailAddresses = array();
unset($args["__sugar_url"]);
if (!is_array($args)) {
throw new SugarApiExceptionInvalidParameter('Invalid argument: cannot validate');
}
if (empty($args)) {
throw new SugarApiExceptionMissingParameter('Missing email address(es) to validate');
}
$emailAddresses = $args;
foreach ($emailAddresses as $emailAddress) {
$validatedEmailAddresses[$emailAddress] = SugarEmailAddress::isValidEmail($emailAddress);
}
return $validatedEmailAddresses;
}
示例6: email
/**
* Validate email fields
*
* @param $value string
* @param $vardef array
* @param $focus object bean of the module we're importing into
* @return string sanitized and validated value on success, bool false on failure
*/
public function email($value, $vardef)
{
if (!empty($value) && !SugarEmailAddress::isValidEmail($value)) {
return false;
}
return $value;
}