Skip to content

Commit

Permalink
add banemail
Browse files Browse the repository at this point in the history
  • Loading branch information
skywalker512 committed Jun 30, 2018
1 parent 92e94b3 commit 649ca3b
Show file tree
Hide file tree
Showing 3 changed files with 125 additions and 0 deletions.
Empty file.
89 changes: 89 additions & 0 deletions addons/plugins/BanEmail/plugin.php
@@ -0,0 +1,89 @@
<?php

if (!defined("IN_ESOTALK")) exit;

ET::$pluginInfo["BanEmail"] = array(
"name" => "禁止电子邮件地址",
"description" => "禁止用户使用某些电子邮件服务",
"version" => "1.0.1",
"author" => "saturngod",
"authorEmail" => "saturngod@gmail.com",
"authorURL" => "http://github.com/saturngod",
"license" => "MIT"
);

class ETPlugin_BanEmail extends ETPlugin {
public function handler_userController_initJoin($controller, $form)
{

$form->addField("BanEmail", "BanEmail", function($form) {},function($form, $key, &$data)
{

$email = $form->getValue("email");

$found = false;
$error = "";

$lists = trim(C("plugin.BanEmail.emails"));

if($lists == "") {
return;
}

$ban_emails = explode(",",$lists);

foreach ($ban_emails as $search_mail) {

$address = "@".trim($search_mail);

$pos = strpos($email,$address);
if ($pos !== false) {
$found = true;
$error = $search_mail . " is not allow to register.";
break;
}
}
if($found) {
$form->error("email",$error);
}


});
}

/**
* Construct and process the settings form for this skin, and return the path to the view that should be
* rendered.
*
* @param ETController $sender The page controller.
* @return string The path to the settings view to render.
*/
public function settings($sender)
{
// Set up the settings form.
$form = ETFactory::make("form");
$form->action = URL("admin/plugins/settings/BanEmail");
$form->setValue("emails", C("plugin.BanEmail.emails"));

// If the form was submitted...
if ($form->validPostBack("BanEmailSave")) {

// Construct an array of config options to write.
$config = array();
$config["plugin.BanEmail.emails"] = $form->getValue("emails");

if (!$form->errorCount()) {

// Write the config file.
ET::writeConfig($config);

$sender->message(T("message.changesSaved"), "success autoDismiss");
$sender->redirect(URL("admin/plugins"));

}
}

$sender->data("BanemailSettingsForm", $form);
return $this->view("settings");
}
}
36 changes: 36 additions & 0 deletions addons/plugins/BanEmail/views/settings.php
@@ -0,0 +1,36 @@
<?php
// Copyright 2011 Toby Zerner, Simon Zerner
// This file is part of esoTalk. Please see the included license file for usage information.

if (!defined("IN_ESOTALK")) exit;

/**
* Displays the settings form for the Proto skin.
*
* @package esoTalk
*/

$form = $data["BanemailSettingsForm"];
?>
<?php echo $form->open(); ?>

<div class='section'>

<ul class='form'>

<li>
<label><?php echo T("Email Address"); ?></label>
<?php echo $form->input("emails", "text"); ?><br/>
使用 <b>英文逗号 (,)</b>来分隔电子邮件地址<br/>
如 : 163.com,qq.com,189.cn
</li>

</ul>

</div>

<div class='buttons'>
<?php echo $form->saveButton("BanEmailSave"); ?>
</div>

<?php echo $form->close(); ?>

0 comments on commit 649ca3b

Please sign in to comment.