summaryrefslogtreecommitdiff
path: root/register.php
diff options
context:
space:
mode:
authorKyle McFarland <tfkyle@gmail.com>2018-01-31 00:51:07 -0600
committerKyle McFarland <tfkyle@gmail.com>2018-01-31 00:51:07 -0600
commit61d1aa04d8d44b17bfe6dace90088669fc6c3df8 (patch)
tree7ede15c880e4c41a18cded46fe6d03fb2dc4543b /register.php
downloadmcoop-61d1aa04d8d44b17bfe6dace90088669fc6c3df8.zip
mcoop-61d1aa04d8d44b17bfe6dace90088669fc6c3df8.tar.gz
mcoop-61d1aa04d8d44b17bfe6dace90088669fc6c3df8.tar.bz2
Initial importHEADmaster
* Registration system's almost done * Just part way through implementing tasks So not much done yet, but it's a start.
Diffstat (limited to 'register.php')
-rw-r--r--register.php57
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
+));
+
+?>