本文整理汇总了PHP中Sanitizer::validateEmail方法的典型用法代码示例。如果您正苦于以下问题:PHP Sanitizer::validateEmail方法的具体用法?PHP Sanitizer::validateEmail怎么用?PHP Sanitizer::validateEmail使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Sanitizer
的用法示例。
在下文中一共展示了Sanitizer::validateEmail方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: checkEmail
private function checkEmail($addr, $expected = true, $msg = '')
{
if ($msg == '') {
$msg = "Testing {$addr}";
}
$this->assertEquals($expected, Sanitizer::validateEmail($addr), $msg);
}
示例2: receiverIsValid
public static function receiverIsValid($receiver)
{
// Returns true if the parameter is a valid e-mail address, false if not
$receiverIsValid = true;
// There may be multiple e-mail addresses, divided by commas - which is valid
// for us, but not for the validation functions we use below. So get the single
// address into an array first, validate them one by one, and only if all are ok,
// return true.
$receiverArray = explode(',', str_replace(', ', ',', $receiver));
// To make sure some joker doesn't copy in a large number of e-mail addresses
// and spams them all, lets set a (admittedly arbitrary) limit of 10.
if (count($receiverArray) > 10) {
return false;
}
if (method_exists('Sanitizer', 'validateEmail')) {
// User::isValidEmailAddr() has been moved to Sanitizer::validateEmail as of
// MediaWiki version 1.18 (I think).
foreach ($receiverArray as $singleEmailAddress) {
if (!Sanitizer::validateEmail($singleEmailAddress)) {
$receiverIsValid = false;
}
}
} else {
foreach ($receiverArray as $singleEmailAddress) {
if (!User::isValidEmailAddr($singleEmailAddress)) {
$receiverIsValid = false;
}
}
}
return $receiverIsValid;
}
示例3: execute
/**
* Show the special page
*
* @param $subpage Mixed: parameter passed to the page or null
*/
public function execute($subpage)
{
global $wgRequest, $wgUser, $wgOut;
$this->setHeaders();
$hash_key = $wgRequest->getText('key', null);
$email = $token = $timestamp = null;
if (!empty($hash_key)) {
#$hask_key = urldecode ( $hash_key );
$data = Wikia::verifyUserSecretKey($hash_key, 'sha256');
error_log("data = " . print_r($data, true));
if (!empty($data)) {
$username = isset($data['user']) ? $data['user'] : null;
$token = isset($data['token']) ? $data['token'] : null;
$timestamp = isset($data['signature1']) ? $data['signature1'] : null;
$oUser = User::newFromName($username);
$email = $oUser->getEmail();
}
} else {
$email = $wgRequest->getText('email', null);
$token = $wgRequest->getText('token', null);
$timestamp = $wgRequest->getText('timestamp', null);
}
if ($email == null || $token == null || $timestamp == null) {
#give up now, abandon all hope.
$wgOut->addWikiMsg('unsubscribe-badaccess');
return;
}
#validate timestamp isnt spoiled (you only have 7 days)
$timeCutoff = strtotime("7 days ago");
if ($timestamp <= $timeCutoff) {
$wgOut->addWikiMsg('unsubscribe-badtime');
// $wgOut->addHTML("timestamp={$timestamp}\n"); #DEVL (remove before release)
// $wgOut->addHTML("timeCutoff={$timeCutoff}\n"); #DEVL (remove before release)
return;
}
#generate what the token SHOULD be
$shouldToken = wfGenerateUnsubToken($email, $timestamp);
if ($token != $shouldToken) {
$wgOut->addWikiMsg('unsubscribe-badtoken');
// $wgOut->addHTML("shouldtoken={$shouldToken}\n"); #DEVL (remove before release)
return;
}
#does the non-blank email they gave us look like an email?
if (Sanitizer::validateEmail($email) == false) {
#email wasnt blank, but didnt look like any email
$wgOut->addWikiMsg('unsubscribe-bademail');
// $wgOut->addHTML("email={$email}\n"); #DEVL (remove before release)
return;
}
#at this point, the 3 params check out.
#is this their 2nd pass at this?
$confirmed = $wgRequest->getBool('confirm', null);
if ($wgRequest->wasPosted() && $confirmed) {
#this is the 2nd round, they pushed the button, so do it
$this->procUnsub($email);
} else {
#this is 1st pass, give them a button to push
$this->showInfo($email, $token, $timestamp);
}
}
示例4: execute
/**
* Main execution point
*
* @param null|string $code Confirmation code passed to the page
*/
function execute( $code ) {
$this->setHeaders();
$this->checkReadOnly();
$this->checkPermissions();
// This could also let someone check the current email address, so
// require both permissions.
if ( !$this->getUser()->isAllowed( 'viewmyprivateinfo' ) ) {
throw new PermissionsError( 'viewmyprivateinfo' );
}
if ( $code === null || $code === '' ) {
if ( $this->getUser()->isLoggedIn() ) {
if ( Sanitizer::validateEmail( $this->getUser()->getEmail() ) ) {
$this->showRequestForm();
} else {
$this->getOutput()->addWikiMsg( 'confirmemail_noemail' );
}
} else {
$llink = Linker::linkKnown(
SpecialPage::getTitleFor( 'Userlogin' ),
$this->msg( 'loginreqlink' )->escaped(),
array(),
array( 'returnto' => $this->getTitle()->getPrefixedText() )
);
$this->getOutput()->addHTML(
$this->msg( 'confirmemail_needlogin' )->rawParams( $llink )->parse()
);
}
} else {
$this->attemptConfirm( $code );
}
}
示例5: execute
function execute()
{
global $wgLang, $wgRequest;
global $wgOut, $wgExtensionsPath;
global $wgUser, $wgCaptchaClass, $wgJsMimeType;
$wgOut->addStyle(AssetsManager::getInstance()->getSassCommonURL('extensions/wikia/SpecialContact/SpecialContact.scss'));
$this->mName = null;
$this->mRealName = null;
$this->mWhichWiki = null;
$this->mProblem = $wgRequest->getText('wpContactSubject');
//subject
$this->mProblemDesc = null;
$this->mPosted = $wgRequest->wasPosted();
$this->mAction = $wgRequest->getVal('action');
$this->mEmail = $wgRequest->getText('wpEmail');
$this->mBrowser = $wgRequest->getText('wpBrowser');
$this->mAbTestInfo = $wgRequest->getText('wpAbTesting');
$this->mCCme = $wgRequest->getCheck('wgCC');
if ($this->mPosted && 'submit' == $this->mAction) {
if (!$wgUser->isLoggedIn() && class_exists($wgCaptchaClass)) {
$captchaObj = new $wgCaptchaClass();
$captchaObj->retrieveCaptcha();
$info = $captchaObj->retrieveCaptcha();
}
#ubrfzy note: these were moved inside to (lazy) prevent some stupid bots
$this->mName = $wgRequest->getText('wpName');
$this->mRealName = $wgRequest->getText('wpContactRealName');
$this->mWhichWiki = $wgRequest->getText('wpContactWikiName');
#sibject still handled outside of post check, because of existing hardcoded prefill links
$this->mProblemDesc = $wgRequest->getText('wpContactDesc');
//body
#malformed email?
if (!Sanitizer::validateEmail($this->mEmail)) {
$this->err[] .= wfMsg('invalidemailaddress');
$this->errInputs['wpEmail'] = true;
}
#empty message text?
if (empty($this->mProblemDesc)) {
$this->err[] .= wfMsg('specialcontact-nomessage');
$this->errInputs['wpContactDesc'] = true;
}
#captcha
if (!$wgUser->isLoggedIn() && class_exists($wgCaptchaClass)) {
// logged in users don't need the captcha (RT#139647)
if (!(!empty($info) && $captchaObj->keyMatch($wgRequest->getVal('wpCaptchaWord'), $info))) {
$this->err[] .= wfMsg('specialcontact-captchafail');
$this->errInputs['wpCaptchaWord'] = true;
}
}
#no errors?
if (empty($this->err)) {
#send email
$this->processCreation();
#stop here
return;
}
#if there were any ->err s, they will be displayed in ContactForm
}
$this->mainContactForm();
}
示例6: execute
public function execute()
{
$this->commit = $this->hasOption('commit');
$dbr = $this->getDB(DB_SLAVE);
$dbw = $this->getDB(DB_MASTER);
$lastId = 0;
do {
$rows = $dbr->select('user', array('user_id', 'user_email'), array('user_id > ' . $dbr->addQuotes($lastId), 'user_email != ""', 'user_email_authenticated IS NULL'), __METHOD__, array('LIMIT' => $this->mBatchSize));
$count = $rows->numRows();
$badIds = array();
foreach ($rows as $row) {
if (!Sanitizer::validateEmail(trim($row->user_email))) {
$this->output("Found bad email: {$row->user_email} for user #{$row->user_id}\n");
$badIds[] = $row->user_id;
}
if ($row->user_id > $lastId) {
$lastId = $row->user_id;
}
}
if ($badIds) {
$badCount = count($badIds);
if ($this->commit) {
$this->output("Removing {$badCount} emails from the database.\n");
$dbw->update('user', array('user_email' => ''), array('user_id' => $badIds), __METHOD__);
foreach ($badIds as $badId) {
User::newFromId($badId)->invalidateCache();
}
wfWaitForSlaves();
} else {
$this->output("Would have removed {$badCount} emails from the database.\n");
}
}
} while ($count !== 0);
$this->output("Done.\n");
}
示例7: onGroupNotify
/**
* Handles group notification.
*
* @since 0.1
*
* @param SWLGroup $group
* @param array $userIDs
* @param SMWChangeSet $changes
*
* @return true
*/
public static function onGroupNotify( SWLGroup $group, array $userIDs, SWLChangeSet $changes ) {
global $egSWLMailPerChange, $egSWLMaxMails;
foreach ( $userIDs as $userID ) {
$user = User::newFromId( $userID );
if ( $user->getOption( 'swl_email', false ) ) {
if ( !method_exists( 'Sanitizer', 'validateEmail' ) || Sanitizer::validateEmail( $user->getEmail() ) ) {
$lastNotify = $user->getOption( 'swl_last_notify' );
$lastWatch = $user->getOption( 'swl_last_watch' );
if ( is_null( $lastNotify ) || is_null( $lastWatch ) || $lastNotify < $lastWatch ) {
$mailCount = $user->getOption( 'swl_mail_count', 0 );
if ( $egSWLMailPerChange || $mailCount < $egSWLMaxMails ) {
SWLEmailer::notifyUser( $group, $user, $changes, $egSWLMailPerChange );
$user->setOption( 'swl_last_notify', wfTimestampNow() );
$user->setOption( 'swl_mail_count', $mailCount + 1 );
$user->saveSettings();
}
}
}
}
}
return true;
}
示例8: execute
/**
* Main execution point
*
* @param null|string $code Confirmation code passed to the page
* @throws PermissionsError
* @throws ReadOnlyError
* @throws UserNotLoggedIn
*/
function execute($code)
{
// Ignore things like master queries/connections on GET requests.
// It's very convenient to just allow formless link usage.
$trxProfiler = Profiler::instance()->getTransactionProfiler();
$this->setHeaders();
$this->checkReadOnly();
$this->checkPermissions();
// This could also let someone check the current email address, so
// require both permissions.
if (!$this->getUser()->isAllowed('viewmyprivateinfo')) {
throw new PermissionsError('viewmyprivateinfo');
}
if ($code === null || $code === '') {
$this->requireLogin('confirmemail_needlogin');
if (Sanitizer::validateEmail($this->getUser()->getEmail())) {
$this->showRequestForm();
} else {
$this->getOutput()->addWikiMsg('confirmemail_noemail');
}
} else {
$old = $trxProfiler->setSilenced(true);
$this->attemptConfirm($code);
$trxProfiler->setSilenced($old);
}
}
示例9: checkContactLink
protected function checkContactLink($name, $url, &$countOk)
{
global $wgVersion;
$ok = false;
if (Sanitizer::validateEmail($url)) {
$ok = true;
// assume OK
} else {
$bits = wfParseUrl($url);
if ($bits && isset($bits['scheme'])) {
if ($bits['scheme'] == 'mailto') {
$ok = true;
// assume OK
} elseif (in_array($bits['scheme'], array('http', 'https'))) {
$req = MWHttpRequest::factory($url, array('method' => 'GET', 'timeout' => 8, 'sslVerifyHost' => false, 'sslVerifyCert' => false));
$req->setUserAgent("MediaWiki {$wgVersion}, CheckCongressLinks Checker");
$ok = $req->execute()->isOK();
}
}
}
if ($ok) {
++$countOk;
} else {
$this->output("Broken: [{$name}] [{$url}]\n");
}
}
示例10: doCreate
protected function doCreate()
{
$params = $this->extractRequestParams();
// Do validations
foreach (explode('|', 'username|password|email') as $field) {
if (!isset($params[$field])) {
$this->dieUsage("Missing parameter {$field}", 'missingparam');
}
}
$username = $params['username'];
if (User::getCanonicalName($username, 'creatable') === false) {
$this->dieUsage("User name is not acceptable", 'invalidusername');
}
$user = User::newFromName($username);
if ($user->getID() !== 0) {
$this->dieUsage("User name is in use", 'nonfreeusername');
}
$password = $params['password'];
if (!$user->isValidPassword($password)) {
$this->dieUsage("Password is not acceptable", 'invalidpassword');
}
$email = $params['email'];
if (!Sanitizer::validateEmail($email)) {
$this->dieUsage("Email is not acceptable", 'invalidemail');
}
$user = TranslateSandbox::addUser($username, $email, $password);
$output = array('user' => array('name' => $user->getName(), 'id' => $user->getId()));
$user->setOption('language', $this->getContext()->getLanguage()->getCode());
$user->saveSettings();
$this->getResult()->addValue(null, $this->getModuleName(), $output);
}
示例11: onConfirmEmailShowRequestForm
public static function onConfirmEmailShowRequestForm(EmailConfirmation &$pageObj, &$show)
{
$show = false;
if (Sanitizer::validateEmail($pageObj->getUser()->getEmail())) {
$userLoginHelper = new UserLoginHelper();
$userLoginHelper->showRequestFormConfirmEmail($pageObj);
} else {
$pageObj->getOutput()->addWikiMsg('usersignup-user-pref-confirmemail_noemail');
}
return true;
}
示例12: execute
public function execute($par)
{
$this->checkPermissions();
$request = $this->getRequest();
$user = $this->getUser();
$out = $this->getOutput();
$this->setHeaders();
$store = $this->getStore();
$token = $request->getVal('token');
if ($request->wasPosted() && $user->matchEditToken($token, 'is')) {
if ($request->getVal('do') === 'delete') {
$store->deleteInvite($request->getVal('hash'));
}
if ($request->getVal('do') === 'add') {
$email = $request->getVal('email');
$okay = Sanitizer::validateEmail($email);
if (trim($email) === '') {
// Silence
} elseif (!$okay) {
$out->wrapWikiMsg(Html::rawElement('div', array('class' => 'error'), "\$1"), array('is-invalidemail', $email));
} else {
$groups = array();
foreach ($this->groups as $group) {
if ($request->getCheck("group-{$group}")) {
$groups[] = $group;
}
}
$hash = $store->addInvite($user, $email, $groups);
self::sendInviteEmail($user, $email, $hash);
}
}
}
$invites = $store->getInvites();
$lang = $this->getLanguage();
$out->addHtml(Html::openElement('table', array('class' => 'wikitable')) . Html::openElement('thead') . Html::openElement('tr') . Html::element('th', null, $this->msg('is-tableth-date')->text()) . Html::element('th', null, $this->msg('is-tableth-email')->text()) . Html::element('th', null, $this->msg('is-tableth-inviter')->text()) . Html::element('th', null, $this->msg('is-tableth-signup')->text()) . Html::element('th', null, $this->msg('is-tableth-groups')->text()) . Html::element('th', null, '') . $this->getAddRow() . Html::closeElement('thead'));
foreach ($invites as $hash => $invite) {
$whenSort = array('data-sort-value' => $invite['when']);
$when = $lang->userTimeAndDate($invite['when'], $user);
$email = $invite['email'];
$groups = $invite['groups'];
if (isset($invite['userid'])) {
$inviteeUser = User::newFromId($invite['userid']);
$name = $inviteeUser->getName();
$email = "{$name} <{$email}>";
}
foreach ($groups as $i => $g) {
$groups[$i] = User::getGroupMember($g);
}
$groups = $lang->commaList($groups);
$out->addHtml(Html::openElement('tr') . Html::element('td', $whenSort, $when) . Html::element('td', null, $email) . Html::element('td', null, User::newFromId($invite['inviter'])->getName()) . Html::element('td', array('data-sort-value' => $invite['used']), $invite['used'] ? $lang->userTimeAndDate($invite['used'], $user) : '') . Html::element('td', null, $groups) . Html::rawElement('td', null, $invite['used'] ? '' : $this->getDeleteButton($invite['hash'])) . Html::closeElement('tr'));
}
$out->addhtml('</table>');
}
示例13: wikia_fbconnect_validateChooseNameForm
/**
* Validate that the CUSTOM input of the ChooseName form is acceptable
* and display an error page if it is not.
*/
function wikia_fbconnect_validateChooseNameForm(&$specialConnect)
{
wfProfileIn(__METHOD__);
$allowDefault = true;
global $wgRequest;
$email = $wgRequest->getVal('wpEmail');
if ($email == "" || !Sanitizer::validateEmail($email)) {
$specialConnect->sendPage('chooseNameForm', 'fbconnect-invalid-email');
$allowDefault = false;
}
wfProfileOut(__METHOD__);
return $allowDefault;
}
示例14: populateUser
/**
* Add data to the User object
* @param User $user User being created (not added to the database yet).
* This may become a "UserValue" in the future, or User may be refactored
* into such.
* @return StatusValue
*/
public function populateUser($user)
{
if ($this->email !== null && $this->email !== '') {
if (!\Sanitizer::validateEmail($this->email)) {
return StatusValue::newFatal('invalidemailaddress');
}
$user->setEmail($this->email);
}
if ($this->realname !== null && $this->realname !== '') {
$user->setRealName($this->realname);
}
return StatusValue::newGood();
}
示例15: execute
public function execute()
{
global $wgUser, $wgAuth, $wgEnableEmail, $wgEmailAuthentication;
if ($wgUser->isAnon()) {
$this->dieUsage("You don't have permission to do that", 'permission-denied');
}
$params = $this->extractRequestParams();
$error = false;
switch ($params['mbaction']) {
case 'setemail':
if (!$wgAuth->allowPropChange('emailaddress')) {
$error = wfMsgExt('cannotchangeemail', 'parseinline');
} else {
//only set email if user does not have email on profile yet
if (!$wgUser->getEmail()) {
if (!isset($params['email']) || !Sanitizer::validateEmail($params['email'])) {
$error = wfMsgExt('invalidemailaddress', 'parseinline');
} else {
list($status, $info) = self::trySetUserEmail($wgUser, $params['email']);
// Status Object
if ($status !== true) {
$error = $status->getWikiText($info);
} else {
$wgUser->saveSettings();
}
}
}
}
break;
case 'resendverification':
//only sends the email if the email has not been verified
if ($wgEnableEmail && $wgEmailAuthentication && $wgUser->getEmail() && !$wgUser->isEmailConfirmed()) {
$status = $wgUser->sendConfirmationMail('set');
if (!$status->isGood()) {
$error = $status->getWikiText('mailerror');
}
}
break;
default:
throw new MWApiMoodBarSetUserEmailInvalidActionException("Action {$params['mbaction']} not implemented");
}
if ($error === false) {
$result = array('result' => 'success');
} else {
$result = array('result' => 'error', 'error' => $error);
}
$this->getResult()->addValue(null, $this->getModuleName(), $result);
}