thynan Posted December 3, 2014 Report Posted December 3, 2014 Hi! After this discussion: http://www.blesta.com/forums/index.php?/topic/3767-eu-new-vat-rules/, I want to create a plugin that does the following: Before a client is registered, the IP of the user who wants to register is matched against the country he selected. If the IP is from another country (geoIP lookup) the user cannot register and gets a message feedback. I have a few questions: My plugin has to register to an event, to plug into the client creation, and do the validation right? But is there an event which I can use? The "Clients.create" event is too late, because the client is already created there, correct? I need to do the validation before the client is created. Any tipps how to achieve this would be very appreciated. Thanks! Quote
Blesta Addons Posted December 3, 2014 Report Posted December 3, 2014 Hi thynan . another request to event system , please add your vote to this thread http://www.blesta.com/forums/index.php?/topic/2979-more-events/ this other thread is about before/after the event , but no reply from staff http://www.blesta.com/forums/index.php?/topic/3640-events-beforeafter-event-set-errors/ i believe the events is the most wanted feature for developpers . now for your request , you can create a plugin for that , i will assist you for this . first your plugin shoud be registred to Appcontroller.preAction event . then you should check the post in your fucntion , something like if (isset($_POST['action']) && $_POST['action'] === "signup" ) { //be sure it's a new signup request $args = array( 'ip' => $_SERVER['REMOTE_ADDR'] , 'country' => $_POST['country'] ); // here you can put your matching fucntion } you can inspire from my admin tools plugin, i have a function that block spambot from registring . Quote
thynan Posted December 3, 2014 Author Report Posted December 3, 2014 Hi, Thanks again! Your suggestion looks great. I will also have a look at your admin tools module, and try to learn from that. I will report back as soon as I got someting working. Quote
thynan Posted December 3, 2014 Author Report Posted December 3, 2014 Hi again! I have tried to get the plugin working, however, the error-message popup doesn't seem to work. When I click "create account" the website only flashes, and stays on the same page without a message. Here is the code from my plugin. It's not much, I basically just took the code from your admin tools plugin, and put in some test-strings - just to test the error message: <?php class CheckClientOriginPlugin extends Plugin { public function __construct() { // Load modules for this plugun Loader::loadModels($this, array("ModuleManager")); $this->loadConfig(dirname(__FILE__) . DS . "config.json"); } public function getEvents() { return array( array( 'event' => "Appcontroller.preAction", 'callback' => array("this", "checkClientOrigin") ) ); } public function checkClientOrigin($event) { if (isset($_POST['action']) && $_POST['action'] === "signup" ) { echo ' <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>test title</title> <!-- Latest compiled and minified CSS --> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css" /> <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries --> <!-- WARNING: Respond.js doesnt work if you view the page via file:// --> <!--[if lt IE 9]> <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script> <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script> <![endif]--> </head> <body> <!-- Modal --> <div class="modal center-block"> <div class="modal-dialog"> <div class="modal-content"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">×</span><span class="sr-only">'. Language::_("AdminToolsPlugin.security.buttons.close", true ) .'</span></button> <h4 class="modal-title" id="myModalLabel">some label</h4> </div> <div class="modal-body"> <div class="alert alert-danger" role="alert">test message</div> </div> <div class="modal-footer"> </div> </div> </div> </div> <!-- jQuery (necessary for Bootstrap JavaScript plugins) --> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> <!-- Latest compiled and minified JavaScript --> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script> </body> </html> '; exit(); } } } ?> Quote
Blesta Addons Posted December 3, 2014 Report Posted December 3, 2014 Hello i think your plugin is good, the only isue i se is the html output . your output contain a modal , so no mesage will be shown until you add a button to show the modal change this <!-- Modal --> <div class="modal center-block"> <div class="modal-dialog"> <div class="modal-content"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">×</span><span class="sr-only">'. Language::_("AdminToolsPlugin.security.buttons.close", true ) .'</span></button> <h4 class="modal-title" id="myModalLabel">some label</h4> </div> <div class="modal-body"> <div class="alert alert-danger" role="alert">test message</div> </div> <div class="modal-footer"> </div> </div> </div> </div> with the fallowing <div class="alert alert-danger" role="alert">test message</div> Quote
thynan Posted December 4, 2014 Author Report Posted December 4, 2014 Hi, I found out that the problem was not the modal button, but the selected order template. The popup only shows up when I select the "standard" order template. If i select any of the "AJAX" or "wizard" templates, the popup doesnt show up. Quote
Blesta Addons Posted December 4, 2014 Report Posted December 4, 2014 Hi, I found out that the problem was not the modal button, but the selected order template. The popup only shows up when I select the "standard" order template. If i select any of the "AJAX" or "wizard" templates, the popup doesnt show up. ohh yes, i missed to signal this . all the template that use ajax in thier request are not supported by this method . Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.