fix registration form post request callback, refactor api/register route

This commit is contained in:
German Correa 2018-10-17 15:11:29 -03:00
parent cae6e7572e
commit 0f2c6bb3cc
5 changed files with 81 additions and 82 deletions

2
.gitignore vendored
View File

@ -2,5 +2,5 @@
/logs/* /logs/*
!/logs/README.md !/logs/README.md
/templates/.cache /templates/.cache
/db/ggdworkshop.db /db/surfaces2018.db
/db/.schema.lock /db/.schema.lock

View File

@ -10,8 +10,8 @@ $().ready(function(){
$("#txtbda,#txteda").datepicker({ $("#txtbda,#txteda").datepicker({
dateFormat: "dd/mm/yy", dateFormat: "dd/mm/yy",
minDate:new Date(2018,6,16), minDate:new Date(2018,11,17),
maxDate:new Date(2018,7,3) maxDate:new Date(2018,11,19)
}); });
$("#pais").select2({ $("#pais").select2({
@ -66,8 +66,8 @@ function select2Focus() {
required: function() { required: function() {
if(grecaptcha.getResponse() == "") return true; if(grecaptcha.getResponse() == "") return true;
else return false; else return false;
} }
}, }
}, },
@ -94,27 +94,39 @@ function select2Focus() {
formdata.find(item => item.name === "pais").value = $("#pais").select2("data")[0].text; formdata.find(item => item.name === "pais").value = $("#pais").select2("data")[0].text;
formdata.find(item => item.name === "roomtype").value = $("#roomtype").select2("data")[0].text; formdata.find(item => item.name === "roomtype").value = $("#roomtype").select2("data")[0].text;
var parameters = $.param(formdata); var parameters = $.param(formdata);
$.post('api/register', parameters) /*$.ajax({
.done(function(data){ url: 'api/register',
alert("post done"); type: "POST",
data: parameters,
success:function(result){
console.log(result);
},
error: function(jqxhr, status, exception){
console.log(exception);
console.log(jqxhr);
}
});*/
var req = $.post('api/register', parameters)
req.done(function(data){
if(data.success){
if(data.success){ validator.resetForm();
alert("peter"); reset($("#registerform"));
validator.resetForm(); showMsg(false,data.msg);
reset($("#registerform")); }
showMsg(false,data.msg); else{
}
else{ var errMsg = data.msg+"<ul>";
$.each(data.errors, function(k,v){
var errMsg = data.msg+"<ul>"; errMsg+="<li>"+v+"</li>";
$.each(data.errors, function(k,v){ });
errMsg+="<li>"+v+"</li>"; errMsg+="</ul>";
}); console.log(errMsg);
errMsg+="</ul>"; showMsg(true,errMsg);
console.log(errMsg); }
showMsg(true,errMsg); });
}
});
}, },
errorElement: "em", errorElement: "em",

View File

@ -87,7 +87,7 @@ $mw = function ($request, $response, $next) {
// API ROUTES // API ROUTES
$app->group('/api', function($app){ $app->group('/api', function($app){
$app->get("/test", function(Request $request, Response $response, array $args) { $app->get("/test", function(Request $request, Response $response, array $args) {
$this->logger->info("GDDWorkshop '/api/test' route"); $this->logger->info("GDDWorkshop '/api/test' route");
return var_dump($request); return var_dump($request);
@ -97,24 +97,21 @@ $app->group('/api', function($app){
$app->post('/register', function (Request $request, Response $response, array $args) { $app->post('/register', function (Request $request, Response $response, array $args) {
$messages = $this->flash; $messages = $this->flash;
$data = $request->getParsedBody(); $data = $request->getParsedBody();
$db = $this->db;
if($this->settings['close_registration']){ if($this->settings['close_registration']){
$messages->addMessageNow("submit-register-err", "Registration has benn closed"); $messages->addMessageNow("submit-register-err", "Registration has benn closed");
} }
else{ else{
$db = $this->db;
if(!isset($data['nombre'])||empty($data['nombre'])) if(!isset($data['nombre'])||empty($data['nombre']))
$messages->addMessageNow("submit-register-err", "First name could not be empty"); $messages->addMessageNow("submit-register-err", "First name could not be empty");
if(!isset($data['apellido'])||empty($data['apellido'])) if(!isset($data['apellido'])||empty($data['apellido']))
$messages->addMessageNow("submit-register-err", "Last name could not be empty"); $messages->addMessageNow("submit-register-err", "Last name could not be empty");
if(!isset($data['email'])||empty($data['email'])) if(!isset($data['email'])||empty($data['email']))
$messages->addMessageNow("submit-register-err", "E-mail could not be empty"); $messages->addMessageNow("submit-register-err", "E-mail could not be empty");
/*if(!isset($data['financiacion'])||!is_numeric($data['financiacion']))
$messages->addMessageNow("submit-register-err", "Question about financial support must have a selected answer");*/
/*if(!isset($data['invited'])||!is_numeric($data['invited']))
$messages->addMessageNow("submit-register-err", "Question about 'invited to participate in this conference' must have a selected answer");*/
if(!isset($data['letterinvited'])||!is_numeric($data['letterinvited'])) if(!isset($data['letterinvited'])||!is_numeric($data['letterinvited']))
$messages->addMessageNow("submit-register-err", "Question about needing a letter of invitation must have a selected answer"); $messages->addMessageNow("submit-register-err", "Question about needing a letter of invitation must have a selected answer");
//ReCaptcha Validation //ReCaptcha Validation
if(!isset($data['g-recaptcha-response'])||empty($data['g-recaptcha-response'])){ if(!isset($data['g-recaptcha-response'])||empty($data['g-recaptcha-response'])){
$messages->addMessageNow("submit-register-err", "Please validate captcha!"); $messages->addMessageNow("submit-register-err", "Please validate captcha!");
@ -124,7 +121,7 @@ $app->group('/api', function($app){
if($this->settings['testing']){ if($this->settings['testing']){
$recapsecret = $this->settings['recaptcha']['secrettest']; $recapsecret = $this->settings['recaptcha']['secrettest'];
} }
var_dump($recapsecret);
$recaptcha = new ReCaptcha\ReCaptcha($recapsecret); $recaptcha = new ReCaptcha\ReCaptcha($recapsecret);
//get remote ip from request header TODO //get remote ip from request header TODO
$resp = $recaptcha->verify($data['g-recaptcha-response'], $_SERVER['REMOTE_ADDR']); $resp = $recaptcha->verify($data['g-recaptcha-response'], $_SERVER['REMOTE_ADDR']);
@ -140,39 +137,41 @@ $app->group('/api', function($app){
if($db->findByMail($data['email'])) if($db->findByMail($data['email']))
$messages->addMessageNow("submit-register-err", $data['email']." is already registered<br/>" $messages->addMessageNow("submit-register-err", $data['email']." is already registered<br/>"
."Please contact: <b>surfacedynamics2018@cmat.edu.uy</b>"); ."Please contact: <b>surfacedynamics2018@cmat.edu.uy</b>");
else }catch (Exception $e){
$db->insert($data);
}
catch (Exception $e){
$this->logger->debug("Submit register DB error: ".$e->getMessage()); $this->logger->debug("Submit register DB error: ".$e->getMessage());
$messages->addMessageNow("submit-register-err", "DB error: ".$e->getMessage()); $messages->addMessageNow("submit-register-err", "DB error: ".$e->getMessage());
} }
} }
if($messages->hasMessage("submit-register-err")){
if($messages->hasMessage("submit-register-err")){
$arrayresponse = array("success" => false, $arrayresponse = array("success" => false,
"msg"=>"You registration could not be completed:\n", "msg"=>"You registration could not be completed:\n",
"errors"=>$messages->getMessage("submit-register-err"), "data"=>$data); "errors"=>$messages->getMessage("submit-register-err"), "data"=>$data);
}
else {
try{
$db->insert($data);
}catch (Exception $e){
$this->logger->debug("Submit register DB error: ".$e->getMessage());
$messages->addMessageNow("submit-register-err", "DB error: ".$e->getMessage());
} }
$arrayresponse = array("success" => true,
else { "msg"=>"You have been successfully registered to the GGDWorkshop",
$arrayresponse = array("success" => true, "data"=>$data);
"msg"=>"You have been successfully registered to the GGDWorkshop", $mailbody = "Hello ".$data["nombre"]." ".$data["apellido"].",\n\n".
"data"=>$data); "You have been successfully registered to the Workshop on Surface Dynamics 2018!\n\n".
$msg = "Hello ".$data["nombre"]." ".$data["apellido"].",\n\n". "If you need to change the information you have provided on the registration and for any".
"You have been successfully registered to the Surface Dynamics 2018 Workshop!\n\n". "questions please contact surfacedynamics2018@cmat.edu.uy\n\n".
"For any questions please contact surfacedynamics2018@cmat.edu.uy\n\n". "Best!\n\n";
"Best!\n\n"; $headers = 'From: ' . "surfacedynamics2018@cmat.edu.uy" . "\r\n" .
$headers = 'From: ' . "surfacedynamics2018@cmat.edu.uy" . "\r\n" . 'Reply-To: ' . "surfacedynamics2018@edu.uy" . "\r\n" .
'Reply-To: ' . "surfacedynamics2018@edu.uy" . "\r\n" . 'Content-Type: ' . "text/plain; charset=UTF-8". "\r\n" .
'Content-Type: ' . "text/plain; charset=UTF-8". "\r\n" . 'X-Mailer: PHP/' . phpversion();
'X-Mailer: PHP/' . phpversion(); mail($data['email'], 'Successfully registered to the Surface Dynamics 2018 Workshop', $mailbody, $headers);
mail($data['email'], 'Successfully registered to the Surface Dynamics 2018 Workshop', $msg, $headers); }
$newres = $response->withJson($arrayresponse);
return $newres;
}
$newres = $response->withJson($arrayresponse);
return $newres;
}); });
}); });

View File

@ -2,19 +2,16 @@
{% block content %} {% block content %}
<h1 id="welcome"><strong>Welcome!</strong></h1> <h1 id="welcome"><strong>Welcome!</strong></h1>
<p> <p>
The Dynamical Systems Group at the Universidad de la República has The Dynamical Systems Group at the Universidad de la República is very honored to host a workshop
been organizing several international Conferences and on the occasion of Patrice Le Calvez's 60th anniversary.
Workshops in the last 20 years, focusing on different aspects of
dynamics and related topics.
</p> </p>
<p> <p>
As our group expanded, both in number of participants and areas The aim is to bring together top scientists working on surface topological dynamics to share their
of research, we are holding a Workshop on Groups, Geometry and Dynamics knowledge and ideas.
on 2018 at Montevideo as a satellite conference of ICM 2018 (Rio de </p>
Janeiro). The goal of the Workshop is to bring together top scientists <p>
working on these areas to discuss new trends on these topics. The The event will take place on december 17th20th, 2018.
idea is to have few talks and lots of discussion time.
</p> </p>
<hr class="separador"> <hr class="separador">
<!--<p> <!--<p>

View File

@ -197,19 +197,10 @@
</div> </div>
<!--<fieldset disabled="disabled">--> <!--<fieldset disabled="disabled">-->
</form> </form>
<div id="statusmsg" class="alert alert-error">
</div>
<!--{% if flash("submit-register-err") %}
<div id="statusmsg" class="alert alert-error">
<strong>Error!</strong>
{% for msg in flash("submit-register-err") %}
<kbd>{{ msg }}.</kdb>
{% endfor %}
</div>
{% endif %}-->
<div id="msgModal" class="modal fade" role="dialog"> <div id="msgModal" class="modal fade" role="dialog">
<div class="modal-dialog"> <div class="modal-dialog">