diff options
Diffstat (limited to 'register.php')
-rw-r--r-- | register.php | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/register.php b/register.php new file mode 100644 index 0000000..99cb2d1 --- /dev/null +++ b/register.php @@ -0,0 +1,57 @@ +<?php +namespace mcoop; +require_once("recaptcha/autoload.php"); +require_once("vendor/autoload.php"); +require_once("common/config.php"); + +// TODO: this should probably check if the user's already logged in and prompt to logout first + +//var_dump($_POST); + +$danger_alerts = array(); +$success_alerts = array(); + +$reg_attempted = false; +if (isset($_POST["username"], $_POST["email"], $_POST["passwd"], $_POST["g-recaptcha-response"])) { + $reg_attempted = true; + $recaptcha = new \ReCaptcha\ReCaptcha($config->recaptcha_secret); + $username = $_POST["username"]; + $email = $_POST["email"]; + $password = $_POST["passwd"]; + if (isset($_POST["fullname"])) { + $full_name = $_POST["fullname"]; + } else { + $full_name = null; + } + // TODO: we should really filter/validate g-recaptcha-response (still need to do) + $recaptcha_resp = $_POST["g-recaptcha-response"]; + // XXX: one downside of this is it checks the captcha before validating all the other fields, might want to move captcha validation to register() + $resp = $recaptcha->verify($recaptcha_resp); + $captcha_valid = $resp->isSuccess(); + $reg_successful = false; + if ($captcha_valid) { + try { + // TODO: validate_email (5th arg) + $db->register($username, $email, $password, $full_name, true, $twig); + $reg_successful = true; + $success_alerts[] = 'Registration successful, <a href="/">Click here to return to the webapp</a>'; + } catch (RegistrationError $re) { + $reg_successful = false; + $error_text = $re->reason; + $danger_alerts[] = $error_text; + if ($db->conn->inTransaction()) + $db->conn->rollBack(); + } + } else { + $danger_alerts[] = "Captcha Invalid, please try again."; + } +} + +// TODO: move into a util file +echo $twig->render("register.tmpl", array( + "danger_alerts" => $danger_alerts, + "success_alerts" => $success_alerts, + "sess_info" => $sess_info +)); + +?> |