From 0d481f8feb92776d06c0b443ca24af95d81ea8d6 Mon Sep 17 00:00:00 2001 From: Myron Blair Date: Fri, 29 May 2026 15:33:16 +0000 Subject: [PATCH] Simplify admin login to email/password only; remove Google OAuth --- admin/auth/google/callback.php | 109 --------------------------------- admin/auth/google/login.php | 30 --------- admin/login.php | 27 +------- 3 files changed, 1 insertion(+), 165 deletions(-) delete mode 100644 admin/auth/google/callback.php delete mode 100644 admin/auth/google/login.php diff --git a/admin/auth/google/callback.php b/admin/auth/google/callback.php deleted file mode 100644 index 1160ef9..0000000 --- a/admin/auth/google/callback.php +++ /dev/null @@ -1,109 +0,0 @@ - [ - 'method' => 'POST', - 'header' => 'Content-Type: application/x-www-form-urlencoded', - 'content' => http_build_query([ - 'code' => $_GET['code'], - 'client_id' => GOOGLE_CLIENT_ID, - 'client_secret' => GOOGLE_CLIENT_SECRET, - 'redirect_uri' => GOOGLE_REDIRECT_URI, - 'grant_type' => 'authorization_code', - ]), - 'timeout' => 15, - ], -])), true); - -if (empty($tokenResp['access_token'])) { - error_log('[Google OAuth] token exchange failed: ' . json_encode($tokenResp)); - googleOAuthError('Failed to complete Google sign-in. Please try again.'); -} - -// Fetch Google user info -$userInfo = json_decode(file_get_contents('https://www.googleapis.com/oauth2/v3/userinfo', false, stream_context_create([ - 'http' => [ - 'method' => 'GET', - 'header' => 'Authorization: Bearer ' . $tokenResp['access_token'], - 'timeout' => 10, - ], -])), true); - -if (empty($userInfo['email'])) { - googleOAuthError('Could not retrieve email from Google. Please try again.'); -} - -$googleEmail = strtolower($userInfo['email']); - -// Look up admin by email -$admin = db()->fetch( - "SELECT * FROM admin_users WHERE email = :email", - ['email' => $googleEmail] -); - -if (!$admin) { - error_log('[Google OAuth] login attempt by non-admin: ' . $googleEmail); - googleOAuthError('No admin account found for ' . htmlspecialchars($googleEmail) . '. Contact the site administrator.'); -} - -// Store google_id on first Google login -if (empty($admin['google_id'])) { - try { - db()->query( - "UPDATE admin_users SET google_id = :gid, last_login = NOW() WHERE user_id = :id", - ['gid' => $userInfo['sub'], 'id' => $admin['user_id']] - ); - } catch (Exception $e) { - // google_id column may not exist yet — update last_login only - db()->query( - "UPDATE admin_users SET last_login = NOW() WHERE user_id = :id", - ['id' => $admin['user_id']] - ); - } -} else { - db()->query( - "UPDATE admin_users SET last_login = NOW() WHERE user_id = :id", - ['id' => $admin['user_id']] - ); -} - -// Create session -$_SESSION['admin'] = [ - 'user_id' => $admin['user_id'], - 'email' => $admin['email'], - 'name' => $admin['name'], - 'is_master' => (bool)$admin['is_master'], - 'permissions' => json_decode($admin['permissions'] ?? '[]', true), - 'auth_method' => 'google', -]; -session_regenerate_id(true); - -$redirect = $_SESSION['admin_redirect'] ?? '/admin/'; -unset($_SESSION['admin_redirect']); -header('Location: ' . $redirect); -exit; diff --git a/admin/auth/google/login.php b/admin/auth/google/login.php deleted file mode 100644 index 5d0cf8e..0000000 --- a/admin/auth/google/login.php +++ /dev/null @@ -1,30 +0,0 @@ - GOOGLE_CLIENT_ID, - 'redirect_uri' => GOOGLE_REDIRECT_URI, - 'response_type' => 'code', - 'scope' => 'openid email profile', - 'state' => $state, - 'access_type' => 'online', - 'prompt' => 'select_account', -]); - -header('Location: https://accounts.google.com/o/oauth2/v2/auth?' . $params); -exit; diff --git a/admin/login.php b/admin/login.php index 0069042..4c1f4b7 100644 --- a/admin/login.php +++ b/admin/login.php @@ -9,11 +9,7 @@ if (AdminAuth::isLoggedIn()) { exit; } -$googleEnabled = defined('GOOGLE_CLIENT_ID') && GOOGLE_CLIENT_ID; - -$error = $_SESSION['admin_login_error'] ?? ''; -unset($_SESSION['admin_login_error']); - +$error = ''; if ($_SERVER['REQUEST_METHOD'] === 'POST') { $email = trim($_POST['email'] ?? ''); $password = trim($_POST['password'] ?? ''); @@ -45,12 +41,6 @@ input{width:100%;background:#111;border:1.5px solid #2a2a2a;border-radius:8px;pa input:focus{border-color:#FF5E1A} .btn{width:100%;padding:14px;border:none;border-radius:8px;background:#FF5E1A;color:#fff;font-family:Inter,sans-serif;font-weight:600;font-size:15px;cursor:pointer;transition:background .2s;margin-top:4px} .btn:hover{background:#e54d0f} -.btn-google{display:flex;align-items:center;justify-content:center;gap:10px;width:100%;padding:13px;border:1.5px solid #333;border-radius:8px;background:#111;color:#e0e0e0;font-family:Inter,sans-serif;font-weight:500;font-size:15px;cursor:pointer;text-decoration:none;transition:border-color .2s,background .2s} -.btn-google:hover{border-color:#555;background:#1a1a1a} -.btn-google svg{width:20px;height:20px;flex-shrink:0} -.divider{display:flex;align-items:center;gap:12px;margin:22px 0} -.divider::before,.divider::after{content:'';flex:1;height:1px;background:#2a2a2a} -.divider span{font-size:12px;color:#444} .error{background:rgba(220,38,38,.1);border:1px solid rgba(220,38,38,.3);color:#f87171;padding:12px 15px;border-radius:8px;font-size:14px;margin-bottom:20px;display:flex;align-items:center;gap:8px} .back{display:block;text-align:center;margin-top:20px;color:#555;font-size:13px;text-decoration:none;transition:color .2s} .back:hover{color:#FF5E1A} @@ -62,24 +52,9 @@ input:focus{border-color:#FF5E1A}

☕ Tom's Java Jive

Admin Panel

-
- - - - - - - - - - Sign in with Google - -
or sign in with email
- -