Initial push
This commit is contained in:
@@ -37,18 +37,18 @@ function cry01_load_pdl(&$b) {
|
||||
}
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// ----------------------------------------------------------------------------
|
||||
// HELPERS
|
||||
// ---------------------------------------------------------------------------
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
function cry01_h($value) {
|
||||
// HTML-escapes a value for safe output.
|
||||
return htmlspecialchars((string) $value, ENT_QUOTES, 'UTF-8');
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// ----------------------------------------------------------------------------
|
||||
// ACCESS
|
||||
// ---------------------------------------------------------------------------
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
function cry01_access_state($association_slug = '') {
|
||||
// Returns operator, participant, or public. Does not call local_channel() for group checks.
|
||||
@@ -109,9 +109,9 @@ function cry01_access_wall($association_slug = '') {
|
||||
';
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// ----------------------------------------------------------------------------
|
||||
// CONTENT ROUTER
|
||||
// ---------------------------------------------------------------------------
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
function cry01_content() {
|
||||
if (function_exists('head_add_css')) {
|
||||
@@ -122,7 +122,7 @@ function cry01_content() {
|
||||
}
|
||||
|
||||
$association_slug = argv(1) ?? '';
|
||||
$sub_route = strtolower(argv(2) ?? '');
|
||||
$sub_route = strtolower(argv(2) ?? '');
|
||||
|
||||
if (!$association_slug) {
|
||||
return cry01_render_index();
|
||||
@@ -160,14 +160,63 @@ function cry01_content() {
|
||||
}
|
||||
return cry01_render_manage($association_slug);
|
||||
|
||||
case 'lookup':
|
||||
// Public Ğ1 balance lookup. No SASE gate, no wallet session, no
|
||||
// storage of any kind. Address in, balance out.
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
if (!cry01_verify_csrf()) {
|
||||
return cry01_render_error('Invalid form token. Please reload and try again.');
|
||||
}
|
||||
return cry01_handle_lookup_post($association_slug, $access);
|
||||
}
|
||||
return cry01_render_landing($association_slug, $access);
|
||||
|
||||
default:
|
||||
return cry01_render_landing($association_slug, $access);
|
||||
}
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// ----------------------------------------------------------------------------
|
||||
// LOOKUP HANDLER
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
function cry01_handle_lookup_post($association_slug, $access) {
|
||||
// Public balance lookup: decode the pasted Ğ1 address, query the chain,
|
||||
// re-render the landing page with the result (or an error) inline.
|
||||
// No data is stored anywhere — this is a pure read.
|
||||
$address = trim($_POST['g1_lookup_address'] ?? '');
|
||||
|
||||
if (!$address) {
|
||||
return cry01_render_landing($association_slug, $access, [
|
||||
'lookup_error' => 'Please enter a Ğ1 address.',
|
||||
]);
|
||||
}
|
||||
|
||||
$account_id = cry01_ss58_decode($address);
|
||||
if ($account_id === null) {
|
||||
return cry01_render_landing($association_slug, $access, [
|
||||
'lookup_error' => 'That doesn\'t look like a valid Ğ1 address. Check for typos and try again.',
|
||||
'lookup_address' => $address,
|
||||
]);
|
||||
}
|
||||
|
||||
$balance = cry01_get_balance($account_id);
|
||||
if ($balance === null) {
|
||||
return cry01_render_landing($association_slug, $access, [
|
||||
'lookup_error' => 'Could not reach the Ğ1 network right now. Please try again shortly.',
|
||||
'lookup_address' => $address,
|
||||
]);
|
||||
}
|
||||
|
||||
return cry01_render_landing($association_slug, $access, [
|
||||
'lookup_address' => $address,
|
||||
'lookup_balance' => $balance,
|
||||
]);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// RENDER — INDEX
|
||||
// ---------------------------------------------------------------------------
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
function cry01_render_index() {
|
||||
// Lists all registered associations with links to their value layer pages.
|
||||
@@ -191,9 +240,9 @@ function cry01_render_index() {
|
||||
return $out;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// ----------------------------------------------------------------------------
|
||||
// RENDER — NOT FOUND / ERROR
|
||||
// ---------------------------------------------------------------------------
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
function cry01_render_not_found() {
|
||||
return '<div class="cry01-content"><div class="alert alert-warning">Association not found.</div></div>';
|
||||
@@ -204,9 +253,9 @@ function cry01_render_error($message) {
|
||||
return '<div class="cry01-content"><div class="alert alert-danger">' . cry01_h($message) . '</div></div>';
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// ----------------------------------------------------------------------------
|
||||
// CSRF
|
||||
// ---------------------------------------------------------------------------
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
function cry01_csrf_token() {
|
||||
// Generates and stores a CSRF token for the current session.
|
||||
|
||||
Reference in New Issue
Block a user