diff --git a/app/classes/forms.php b/app/classes/forms.php index 28201a2..bb9a927 100644 --- a/app/classes/forms.php +++ b/app/classes/forms.php @@ -350,6 +350,10 @@ class Forms extends Check { self::addUserError( 'Invalid username.' ); return false; } + if ( $user->usernameExists( Input::post( 'username' ) ) ) { + self::addUserError( 'A user with that username is already registered.' ); + return false; + } if ( !self::password( Input::post( 'password' ) ) ) { self::addUserError( 'Invalid password.' ); return false; diff --git a/app/controllers/register.php b/app/controllers/register.php index c04e6ca..94ac9ec 100644 --- a/app/controllers/register.php +++ b/app/controllers/register.php @@ -47,7 +47,8 @@ class Register extends Controller { public function index() { self::$title = '{SITENAME} Sign Up'; self::$pageDescription = 'Many features of {SITENAME} are disabled or hidden from unregistered users. On this page you can sign up for an account to access all the app has to offer.'; - + Components::append( 'TEMPLATE_JS_INCLUDES', '' ); + Components::set( 'TURNSTILE_API_KEY', '0x4AAAAAAA1yKVCfYqpnMbvA' ); if ( ! Config::getValue( 'main/registrationEnabled' ) ) { return Issues::add( 'notice', 'The site administrator has disable the ability to register a new account.' ); } @@ -59,10 +60,41 @@ class Register extends Controller { if ( !Input::exists() ) { return Views::view( 'auth.register' ); } + if ( Input::exists( 'userEmail' ) ) { + // for the really bad AI / headless bots + Session::flash( 'success', 'Thank you for registering! Please check your email to confirm your account.' ); + Redirect::to( 'home/index' ); + } if ( !Forms::check( 'register' ) ) { Issues::add( 'error', [ 'There was an error with your registration.' => Check::userErrors() ] ); return Views::view( 'auth.register' ); } + if ( ! Input::exists('cf-turnstile-response') ) { + Issues::add( 'notice', 'Turnstile verification failed. Please try again.' ); + return Views::view( 'auth.register' ); + } + // Verify Turnstile response with Cloudflare API + $secret_key = "0x4AAAAAAA1yKZdXiv9_JrXXhF9Iw2tvQTE"; + $verify_url = "https://challenges.cloudflare.com/turnstile/v0/siteverify"; + $data = [ + "secret" => $secret_key, + "response" => Input::post('cf-turnstile-response'), + "remoteip" => $_SERVER["REMOTE_ADDR"] // Optional, helps detect abuse + ]; + $options = [ + "http" => [ + "header" => "Content-Type: application/x-www-form-urlencoded", + "method" => "POST", + "content" => http_build_query($data) + ] + ]; + $context = stream_context_create($options); + $response = file_get_contents($verify_url, false, $context); + $result = json_decode($response, true); + if ( ! $result["success"]) { + Issues::add( 'notice', 'Turnstile verification failed. Please try again. If the issue persists, please contact the site administrator.' ); + return Views::view( 'auth.register' ); + } self::$user->create( [ 'username' => Input::post( 'username' ), 'password' => Hash::make( Input::post( 'password' ) ), diff --git a/app/js/main.js b/app/js/main.js index 160b06e..3c12819 100644 --- a/app/js/main.js +++ b/app/js/main.js @@ -272,8 +272,6 @@ document.querySelectorAll('[data-bs-toggle="collapse"]').forEach(button => { document.addEventListener("DOMContentLoaded", function () { var popoverTriggerList = [].slice.call(document.querySelectorAll('[data-bs-toggle="popover"]')); var popoverList = popoverTriggerList.map(function (popoverTriggerEl) { - return new bootstrap.Popover(popoverTriggerEl, { - customClass: 'context-popover', - }); + return new bootstrap.Popover(popoverTriggerEl); }); }); \ No newline at end of file diff --git a/app/views/auth/register.html b/app/views/auth/register.html index fc5dc93..a8ee014 100644 --- a/app/views/auth/register.html +++ b/app/views/auth/register.html @@ -15,6 +15,7 @@
+
@@ -42,6 +43,11 @@ + +
+
+
+
diff --git a/app/views/footer/right.html b/app/views/footer/right.html index b17317d..5b575f7 100644 --- a/app/views/footer/right.html +++ b/app/views/footer/right.html @@ -1,6 +1,6 @@
{SHARE_IMAGE} -
Dark Mode
+
Dark Mode
diff --git a/app/views/footer/share.html b/app/views/footer/share.html index 53cb6a6..b6570ca 100644 --- a/app/views/footer/share.html +++ b/app/views/footer/share.html @@ -1,9 +1,9 @@
-
Share
+
Share
-