$assoc) { $groups = $assoc['groups'] ?? []; foreach (['corpus_builder', 'sase_participant', 'civic_professional'] as $group_key) { $gid = intval($groups[$group_key] ?? 0); if ($gid) { $r = q("SELECT xchan FROM pggrp_member WHERE gid = %d AND xchan = '%s' LIMIT 1", intval($gid), dbesc($observer) ); if ($r) return 'participant'; } } } return 'public'; } // ----------------------------------------------------------------------------- // CONTENT ROUTER // ----------------------------------------------------------------------------- function g1wallet_content() { if (function_exists('head_add_css')) { head_add_css('/addon/g1wallet/view/css/g1wallet.css'); } $access = g1wallet_access_state(); $sub_route = strtolower(argv(1) ?? ''); if ($access === 'public') { return g1wallet_render_access_wall(); } // POST: store g1 address if ($_SERVER['REQUEST_METHOD'] === 'POST' && $sub_route === 'address') { if (!g1wallet_verify_csrf()) { return g1wallet_render_error('Invalid form token. Please reload and try again.'); } return g1wallet_handle_address_post($access); } // Default: wallet landing page return g1wallet_render_landing($access); } // ----------------------------------------------------------------------------- // CSRF // ----------------------------------------------------------------------------- function g1wallet_csrf_token() { if (empty($_SESSION['g1wallet_csrf'])) { $_SESSION['g1wallet_csrf'] = bin2hex(random_bytes(16)); } return ''; } function g1wallet_verify_csrf() { return isset($_POST['g1wallet_csrf'], $_SESSION['g1wallet_csrf']) && hash_equals($_SESSION['g1wallet_csrf'], $_POST['g1wallet_csrf']); }