From 4089ba01e0881c89a72332e13bc3a80b6bddec2a Mon Sep 17 00:00:00 2001
From: Jake Vanderwerf <get@jakevanderwerf.ca>
Date: Mon, 29 Jun 2026 22:15:55 +0000
Subject: [PATCH] =DashboardManager overhaul. A bit easier to modify the output of pages. Still have to get the account pages to work as expected, as well as verify the integrations and others are working - but registrar/content pages work as expected. Also fixed up the table generation in CRUD.js and CRUDSkeleton.php
---
inc/rest/routes/LoginRoutes.php | 44 ++++++++++++++++++++++++++++----------------
1 files changed, 28 insertions(+), 16 deletions(-)
diff --git a/inc/rest/routes/LoginRoutes.php b/inc/rest/routes/LoginRoutes.php
index 6f78184..5d8218b 100644
--- a/inc/rest/routes/LoginRoutes.php
+++ b/inc/rest/routes/LoginRoutes.php
@@ -1,6 +1,7 @@
<?php
namespace JVBase\rest\routes;
+use JVBase\managers\Cache;
use JVBase\registrar\Registrar;
use JVBase\rest\Rest;
use JVBase\rest\Route;
@@ -30,8 +31,8 @@
$this->cacheTtl = WEEK_IN_SECONDS;
parent::__construct();
+ $this->hasMagicLink = Site::has('magic_link');
- $this->hasMagicLink = Site::has('magicLink');
}
public function registerRoutes(): void
@@ -94,7 +95,8 @@
->register();
// Magic link endpoint
- if ($this->hasMagicLink) {
+
+ if (Site::has('magic_link')) {
Route::for('auth/magic')
->post([$this, 'handleMagicLink'])
->args([
@@ -135,18 +137,23 @@
*/
public function handleLogin(WP_REST_Request $request): WP_REST_Response
{
+ error_log('Handling login...');
$email = sanitize_email($request->get_param('user_email'));
$password = $request->get_param('user_password');
$remember = (bool) $request->get_param('remember_me');
$redirect_to = $request->get_param('redirect_to');
// Verify Turnstile
+
if (!$this->verifyTurnstile($request->get_param('cf-turnstile-response') ?? '')) {
+ error_log('[handleLogin]Turnstile failed');
return $this->error(
'Security verification failed. Please try again.',
'turnstile_failed',
403
);
+ } else {
+ error_log('[handleLogin]Turnstile succeeded');
}
// Attempt authentication
@@ -415,7 +422,8 @@
*/
public function handleMagicLink(WP_REST_Request $request): WP_REST_Response
{
- if (!$this->hasMagicLink) {
+
+ if (!Site::has('magic_link')) {
return $this->error(
'Magic link authentication is not enabled.',
'feature_disabled',
@@ -631,17 +639,17 @@
}
// Check if role is valid and can register
- $role_config = JVB_USER[$user_select] ?? null;
+ $registrar = Registrar::getInstance($user_select);
- if (!$role_config) {
+ if (!$registrar) {
return new WP_Error('invalid_role', 'Invalid role selected.');
}
- if (!($role_config['can_register'] ?? false)) {
+ if (!($registrar->hasFeature('can_register') ?? false)) {
return new WP_Error('role_not_allowed', 'This role cannot be selected during registration.');
}
- return BASE . $user_select;
+ return $registrar->getBased();
}
/**
@@ -711,23 +719,27 @@
}
}
+ public static function auth():array
+ {
+ return (new self)->buildAuth();
+ }
+
protected function buildAuth(?int $user = null): array
{
- if (is_user_logged_in()) {
- $user = ($user) ?: get_current_user_id();
+ $userId = $user ?? (is_user_logged_in() ? get_current_user_id() : 0);
+
+ if ($userId) {
return [
'authenticated' => true,
- 'user' => $user,
- 'nonces' => $this->getUserNonces($user)
+ 'user' => $userId,
+ 'nonces' => $this->getUserNonces($userId),
];
}
return [
'authenticated' => false,
- 'user' => false,
- 'nonces' => [
- 'wp_rest' => wp_create_nonce('wp_rest')
- ]
+ 'user' => false,
+ 'nonces' => ['wp_rest' => wp_create_nonce('wp_rest')],
];
}
protected function getUserNonces(int $userID):array {
@@ -740,7 +752,7 @@
if (Site::has('favourites')) {
$nonces['favourites'] = wp_create_nonce('favourites-'.$userID);
}
- if (!empty(Registrar::getFeatured('karma'))) {
+ if (!empty(Registrar::withFeature('karma'))) {
$nonces['votes'] = wp_create_nonce('votes-'.$userID);
}
if (Site::has('notifications')) {
--
Gitblit v1.10.0