mirror of
https://github.com/myronblair/tomtomgames
synced 2026-06-30 17:51:08 -05:00
Fix bogus $sent check on 20 non-email actions in admin.php
Every case that wasn't actually sending email had copy-pasted the email-send result check, causing all those actions (delete_pending, payment_settings_update, etc.) to always return 'Failed to send reset email' even on success. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
+20
-20
@@ -31,7 +31,7 @@ switch ($action) {
|
||||
$data = json_decode(file_get_contents('php://input'), true);
|
||||
$id = (int)($data['id'] ?? 0);
|
||||
db()->prepare("DELETE FROM pending_registrations WHERE id=?")->execute([$id]);
|
||||
echo json_encode($sent ? ['success'=>true] : ['success'=>false,'error'=>'Failed to send reset email. Please try again.']);
|
||||
echo json_encode(['success'=>true]);
|
||||
break;
|
||||
|
||||
case 'approve_pending':
|
||||
@@ -208,7 +208,7 @@ switch ($action) {
|
||||
if ($req) db()->prepare("UPDATE users SET tokens=tokens+? WHERE id=?")->execute([$req['tokens'],$req['user_id']]);
|
||||
}
|
||||
db()->prepare("UPDATE cashout_requests SET status=?,admin_note=?,resolved_at=NOW() WHERE id=?")->execute([$status,$note,$id]);
|
||||
echo json_encode($sent ? ['success'=>true] : ['success'=>false,'error'=>'Failed to send reset email. Please try again.']);
|
||||
echo json_encode(['success'=>true]);
|
||||
break;
|
||||
|
||||
// ─── USERS LIST ───────────────────────────────────────────
|
||||
@@ -318,7 +318,7 @@ switch ($action) {
|
||||
} else {
|
||||
db()->prepare("UPDATE users SET username=?,alias=?,email=? WHERE id=?")->execute([$username,$alias,$email,$uid]);
|
||||
}
|
||||
echo json_encode($sent ? ['success'=>true] : ['success'=>false,'error'=>'Failed to send reset email. Please try again.']);
|
||||
echo json_encode(['success'=>true]);
|
||||
break;
|
||||
|
||||
// ─── TOGGLE ADMIN ROLE ───────────────────────────────────
|
||||
@@ -362,7 +362,7 @@ switch ($action) {
|
||||
if ($uid === MASTER_ADMIN_ID) { echo json_encode(['success'=>false,'error'=>'Cannot suspend the master admin.']); exit; }
|
||||
logAdminAction('USER_STATUS_CHANGE', $adminId, 'user', isset($userId)?(int)$userId:0, 'Changed user status to: '.($data['status']??'unknown'), '', ($data['status']??''), 'warning');
|
||||
db()->prepare("UPDATE users SET status=IF(status='active','suspended','active') WHERE id=?")->execute([$uid]);
|
||||
echo json_encode($sent ? ['success'=>true] : ['success'=>false,'error'=>'Failed to send reset email. Please try again.']);
|
||||
echo json_encode(['success'=>true]);
|
||||
break;
|
||||
|
||||
// ─── DELETE USER ──────────────────────────────────────────
|
||||
@@ -381,7 +381,7 @@ switch ($action) {
|
||||
db()->prepare("DELETE FROM token_purchases WHERE user_id=?")->execute([$uid]);
|
||||
db()->prepare("DELETE FROM users WHERE id=?")->execute([$uid]);
|
||||
db()->commit();
|
||||
echo json_encode($sent ? ['success'=>true] : ['success'=>false,'error'=>'Failed to send reset email. Please try again.']);
|
||||
echo json_encode(['success'=>true]);
|
||||
} catch (Exception $e) {
|
||||
db()->rollBack();
|
||||
echo json_encode(['success'=>false,'error'=>'Delete failed']);
|
||||
@@ -441,7 +441,7 @@ switch ($action) {
|
||||
db()->prepare("INSERT INTO game_aliases (user_id,platform_slug,alias) VALUES (?,?,?) ON DUPLICATE KEY UPDATE alias=VALUES(alias)")
|
||||
->execute([$row['user_id'],$row['platform_slug'],$uname]);
|
||||
}
|
||||
echo json_encode($sent ? ['success'=>true] : ['success'=>false,'error'=>'Failed to send reset email. Please try again.']);
|
||||
echo json_encode(['success'=>true]);
|
||||
break;
|
||||
|
||||
case 'platform_account_update':
|
||||
@@ -459,7 +459,7 @@ switch ($action) {
|
||||
db()->prepare("INSERT INTO game_aliases (user_id,platform_slug,alias) VALUES (?,?,?) ON DUPLICATE KEY UPDATE alias=VALUES(alias)")
|
||||
->execute([$row['user_id'],$row['platform_slug'],$uname]);
|
||||
}
|
||||
echo json_encode($sent ? ['success'=>true] : ['success'=>false,'error'=>'Failed to send reset email. Please try again.']);
|
||||
echo json_encode(['success'=>true]);
|
||||
break;
|
||||
$rows = db()->query("
|
||||
SELECT b.*, u.username AS sender_name,
|
||||
@@ -516,7 +516,7 @@ switch ($action) {
|
||||
$d = json_decode(file_get_contents('php://input'), true);
|
||||
$id = (int)($d['id']??0);
|
||||
db()->prepare("DELETE FROM broadcasts WHERE id=?")->execute([$id]);
|
||||
echo json_encode($sent ? ['success'=>true] : ['success'=>false,'error'=>'Failed to send reset email. Please try again.']);
|
||||
echo json_encode(['success'=>true]);
|
||||
break;
|
||||
|
||||
case 'broadcast_edit':
|
||||
@@ -529,7 +529,7 @@ switch ($action) {
|
||||
if (!$id || !$subject || !$message) { echo json_encode(['success'=>false,'error'=>'Missing fields']); exit; }
|
||||
db()->prepare("UPDATE broadcasts SET subject=?, message=?, target=? WHERE id=?")->execute([$subject, $message, $target, $id]);
|
||||
logAdminAction('BROADCAST_EDITED', $adminId, 'broadcast', $id, 'Edited broadcast #'.$id, '', '', 'info');
|
||||
echo json_encode($sent ? ['success'=>true] : ['success'=>false,'error'=>'Failed to send reset email. Please try again.']);
|
||||
echo json_encode(['success'=>true]);
|
||||
break;
|
||||
|
||||
case 'broadcast_resend':
|
||||
@@ -612,7 +612,7 @@ switch ($action) {
|
||||
if (!$id||!$label){echo json_encode(['success'=>false,'error'=>'ID and label required']);exit;}
|
||||
db()->prepare("UPDATE cashout_method_types SET label=?,icon=?,description=?,is_active=?,sort_order=? WHERE id=?")
|
||||
->execute([$label,$icon,$desc,$active,$sort,$id]);
|
||||
echo json_encode($sent ? ['success'=>true] : ['success'=>false,'error'=>'Failed to send reset email. Please try again.']);
|
||||
echo json_encode(['success'=>true]);
|
||||
break;
|
||||
|
||||
case 'cashout_methods_delete':
|
||||
@@ -621,7 +621,7 @@ switch ($action) {
|
||||
$id=(int)($d['id']??0);
|
||||
if (!$id){echo json_encode(['success'=>false,'error'=>'ID required']);exit;}
|
||||
db()->prepare("DELETE FROM cashout_method_types WHERE id=?")->execute([$id]);
|
||||
echo json_encode($sent ? ['success'=>true] : ['success'=>false,'error'=>'Failed to send reset email. Please try again.']);
|
||||
echo json_encode(['success'=>true]);
|
||||
break;
|
||||
|
||||
// ──
|
||||
@@ -630,7 +630,7 @@ switch ($action) {
|
||||
$d=json_decode(file_get_contents('php://input'),true);
|
||||
$id=(int)($d['id']??0);$nt=substr(trim($d['admin_note']??''),0,500);
|
||||
db()->prepare("UPDATE platform_accounts SET status='denied',admin_note=?,admin_id=? WHERE id=?")->execute([$nt,$_SESSION['user_id'],$id]);
|
||||
echo json_encode($sent ? ['success'=>true] : ['success'=>false,'error'=>'Failed to send reset email. Please try again.']);
|
||||
echo json_encode(['success'=>true]);
|
||||
break;
|
||||
|
||||
case 'platform_account_delete':
|
||||
@@ -638,7 +638,7 @@ switch ($action) {
|
||||
$d=json_decode(file_get_contents('php://input'),true);
|
||||
$id=(int)($d['id']??0);
|
||||
db()->prepare("DELETE FROM platform_accounts WHERE id=?")->execute([$id]);
|
||||
echo json_encode($sent ? ['success'=>true] : ['success'=>false,'error'=>'Failed to send reset email. Please try again.']);
|
||||
echo json_encode(['success'=>true]);
|
||||
break;
|
||||
|
||||
case 'platform_accounts_user':
|
||||
@@ -763,7 +763,7 @@ switch ($action) {
|
||||
if (!$id) { echo json_encode(['success'=>false,'error'=>'ID required']); exit; }
|
||||
db()->prepare("UPDATE payment_settings SET label=?,handle=?,instructions=?,is_enabled=?,sort_order=? WHERE id=?")
|
||||
->execute([$label,$handle,$inst,$enabled,$sort,$id]);
|
||||
echo json_encode($sent ? ['success'=>true] : ['success'=>false,'error'=>'Failed to send reset email. Please try again.']);
|
||||
echo json_encode(['success'=>true]);
|
||||
break;
|
||||
|
||||
|
||||
@@ -805,7 +805,7 @@ switch ($action) {
|
||||
if ($alias === '') $del->execute([$uid, $slug]);
|
||||
else $stmt->execute([$uid, $slug, $alias]);
|
||||
}
|
||||
echo json_encode($sent ? ['success'=>true] : ['success'=>false,'error'=>'Failed to send reset email. Please try again.']);
|
||||
echo json_encode(['success'=>true]);
|
||||
break;
|
||||
|
||||
// ─── PLATFORMS: admin list (active + inactive, no archived) ──
|
||||
@@ -960,7 +960,7 @@ switch ($action) {
|
||||
strtoupper(substr(trim($data['state']??''),0,2)),
|
||||
substr(trim($data['zip'] ??''),0,10),
|
||||
]);
|
||||
echo json_encode($sent ? ['success'=>true] : ['success'=>false,'error'=>'Failed to send reset email. Please try again.']);
|
||||
echo json_encode(['success'=>true]);
|
||||
break;
|
||||
|
||||
// ─── BILLING: clear card ─────────────────────────────────
|
||||
@@ -969,7 +969,7 @@ switch ($action) {
|
||||
$data = json_decode(file_get_contents('php://input'), true);
|
||||
$uid = (int)($data['user_id'] ?? 0);
|
||||
db()->prepare("UPDATE saved_billing SET card_brand=NULL,card_last4=NULL,card_exp_month=NULL,card_exp_year=NULL,sq_card_id=NULL WHERE user_id=?")->execute([$uid]);
|
||||
echo json_encode($sent ? ['success'=>true] : ['success'=>false,'error'=>'Failed to send reset email. Please try again.']);
|
||||
echo json_encode(['success'=>true]);
|
||||
break;
|
||||
|
||||
// ─── BILLING: clear all ──────────────────────────────────
|
||||
@@ -978,7 +978,7 @@ switch ($action) {
|
||||
$data = json_decode(file_get_contents('php://input'), true);
|
||||
$uid = (int)($data['user_id'] ?? 0);
|
||||
db()->prepare("DELETE FROM saved_billing WHERE user_id=?")->execute([$uid]);
|
||||
echo json_encode($sent ? ['success'=>true] : ['success'=>false,'error'=>'Failed to send reset email. Please try again.']);
|
||||
echo json_encode(['success'=>true]);
|
||||
break;
|
||||
|
||||
// ─── RESEND VERIFICATION (from admin) ─────────────────────
|
||||
@@ -1044,14 +1044,14 @@ switch ($action) {
|
||||
$tid = (int)($data['user_id'] ?? 0);
|
||||
if (!$tid) { echo json_encode(['success'=>false,'error'=>'user_id required']); exit; }
|
||||
db()->prepare("DELETE FROM chat_messages WHERE user_id=?")->execute([$tid]);
|
||||
echo json_encode($sent ? ['success'=>true] : ['success'=>false,'error'=>'Failed to send reset email. Please try again.']);
|
||||
echo json_encode(['success'=>true]);
|
||||
break;
|
||||
|
||||
// ─── CHAT: clear ALL chats ────────────────────────────
|
||||
case 'chat_clear_all':
|
||||
if ($_SERVER['REQUEST_METHOD'] !== 'POST') { echo json_encode(['success'=>false]); exit; }
|
||||
db()->exec("DELETE FROM chat_messages");
|
||||
echo json_encode($sent ? ['success'=>true] : ['success'=>false,'error'=>'Failed to send reset email. Please try again.']);
|
||||
echo json_encode(['success'=>true]);
|
||||
break;
|
||||
case 'chat_unread':
|
||||
$count = db()->query("SELECT COUNT(*) FROM chat_messages WHERE sender='user' AND is_read=0")->fetchColumn();
|
||||
|
||||
Reference in New Issue
Block a user