Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c358b51930 |
46
assets/css/custom.css
Normal file
46
assets/css/custom.css
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
|
||||||
|
body {
|
||||||
|
font-family: 'Roboto', sans-serif;
|
||||||
|
background-color: #F8F9FA;
|
||||||
|
}
|
||||||
|
|
||||||
|
.navbar {
|
||||||
|
background-color: #FFFFFF;
|
||||||
|
box-shadow: 0 2px 4px rgba(0,0,0,.1);
|
||||||
|
}
|
||||||
|
|
||||||
|
.hero {
|
||||||
|
background-image: url('https://picsum.photos/seed/calendar-hero/1600/400');
|
||||||
|
background-size: cover;
|
||||||
|
background-position: center;
|
||||||
|
color: white;
|
||||||
|
text-align: center;
|
||||||
|
padding: 100px 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.hero h1 {
|
||||||
|
font-size: 3.5rem;
|
||||||
|
font-weight: 700;
|
||||||
|
text-shadow: 2px 2px 4px rgba(0,0,0,0.5);
|
||||||
|
}
|
||||||
|
|
||||||
|
.btn-primary {
|
||||||
|
background-color: #4285F4;
|
||||||
|
border-color: #4285F4;
|
||||||
|
border-radius: 0.5rem;
|
||||||
|
padding: 10px 20px;
|
||||||
|
font-weight: 500;
|
||||||
|
}
|
||||||
|
|
||||||
|
.btn-primary:hover {
|
||||||
|
background-color: #3367D6;
|
||||||
|
border-color: #3367D6;
|
||||||
|
}
|
||||||
|
|
||||||
|
.calendar-placeholder {
|
||||||
|
background-color: #FFFFFF;
|
||||||
|
border-radius: 0.5rem;
|
||||||
|
padding: 2rem;
|
||||||
|
box-shadow: 0 2px 4px rgba(0,0,0,.1);
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
1
assets/js/main.js
Normal file
1
assets/js/main.js
Normal file
@ -0,0 +1 @@
|
|||||||
|
// Placeholder for future JS
|
||||||
100
callback.php
Normal file
100
callback.php
Normal file
@ -0,0 +1,100 @@
|
|||||||
|
<?php
|
||||||
|
session_start();
|
||||||
|
|
||||||
|
// If the authorization code is not present, redirect to the homepage.
|
||||||
|
if (!isset($_GET['code'])) {
|
||||||
|
header('Location: index.php');
|
||||||
|
exit();
|
||||||
|
}
|
||||||
|
|
||||||
|
require_once 'google_config.php';
|
||||||
|
|
||||||
|
// Prevent refreshing the page with the same code.
|
||||||
|
if (isset($_SESSION['last_auth_code']) && $_SESSION['last_auth_code'] === $_GET['code']) {
|
||||||
|
// This code has been processed already. Redirect to avoid re-using it.
|
||||||
|
header('Location: index.php?error=code_reused');
|
||||||
|
exit();
|
||||||
|
}
|
||||||
|
|
||||||
|
// The code from Google.
|
||||||
|
$code = $_GET['code'];
|
||||||
|
$_SESSION['last_auth_code'] = $code; // Store the code to detect reuse.
|
||||||
|
|
||||||
|
// Exchange authorization code for an access token.
|
||||||
|
$token_url = 'https://oauth2.googleapis.com/token';
|
||||||
|
$token_data = [
|
||||||
|
'code' => $code,
|
||||||
|
'client_id' => GOOGLE_CLIENT_ID,
|
||||||
|
'client_secret' => GOOGLE_CLIENT_SECRET,
|
||||||
|
'redirect_uri' => GOOGLE_REDIRECT_URI,
|
||||||
|
'grant_type' => 'authorization_code'
|
||||||
|
];
|
||||||
|
|
||||||
|
$ch = curl_init($token_url);
|
||||||
|
curl_setopt($ch, CURLOPT_POST, true);
|
||||||
|
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($token_data));
|
||||||
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||||
|
$response = curl_exec($ch);
|
||||||
|
curl_close($ch);
|
||||||
|
|
||||||
|
$token_info = json_decode($response, true);
|
||||||
|
|
||||||
|
if (isset($token_info['access_token'])) {
|
||||||
|
// Success! Store the token and redirect.
|
||||||
|
$_SESSION['access_token'] = $token_info['access_token'];
|
||||||
|
if (isset($token_info['refresh_token'])) {
|
||||||
|
$_SESSION['refresh_token'] = $token_info['refresh_token'];
|
||||||
|
}
|
||||||
|
unset($_SESSION['last_auth_code']); // Clean up the used code.
|
||||||
|
header('Location: index.php');
|
||||||
|
exit();
|
||||||
|
} else {
|
||||||
|
// Log the detailed error from Google for server-side debugging.
|
||||||
|
error_log("Google OAuth Error: " . $response);
|
||||||
|
|
||||||
|
// Display a clear, actionable error message to the user.
|
||||||
|
$error_title = "Authentication Failed!";
|
||||||
|
$error_message = "The application was unable to get an access token from Google.";
|
||||||
|
$google_response = "<pre>" . htmlspecialchars($response, ENT_QUOTES, 'UTF-8') . "</pre>";
|
||||||
|
$most_likely_cause = "This is most likely due to an incorrect <strong>Client ID</strong> or <strong>Client Secret</strong> in the <code>google_config.php</code> file.";
|
||||||
|
$instructions = "Please double-check that the credentials you copied from the Google Cloud Console are correct and have no typos or extra spaces.";
|
||||||
|
|
||||||
|
// Simple HTML for the error page
|
||||||
|
echo <<<HTML
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<title>{$error_title}</title>
|
||||||
|
<style>
|
||||||
|
body { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif; background-color: #f8f9fa; color: #212529; margin: 40px; }
|
||||||
|
.container { max-width: 700px; margin: 0 auto; background-color: #fff; border: 1px solid #dee2e6; border-radius: 8px; padding: 20px; }
|
||||||
|
h1 { color: #dc3545; }
|
||||||
|
code { background-color: #e9ecef; padding: 2px 4px; border-radius: 4px; }
|
||||||
|
.response { background-color: #f1f1f1; border: 1px solid #ddd; padding: 10px; margin-top: 15px; font-family: monospace; }
|
||||||
|
.footer { margin-top: 20px; }
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div class="container">
|
||||||
|
<h1>{$error_title}</h1>
|
||||||
|
<p>{$error_message}</p>
|
||||||
|
<p><strong>{$most_likely_cause}</strong></p>
|
||||||
|
<p>{$instructions}</p>
|
||||||
|
|
||||||
|
<div class="response">
|
||||||
|
<strong>Google's Raw Response:</strong>
|
||||||
|
{$google_response}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="footer">
|
||||||
|
<a href="index.php">Go back to homepage and try again</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
HTML;
|
||||||
|
exit();
|
||||||
|
}
|
||||||
|
?>
|
||||||
20
google_config.php
Normal file
20
google_config.php
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
<?php
|
||||||
|
// Google API configuration
|
||||||
|
// Instructions for getting your credentials:
|
||||||
|
// 1. Go to the Google API Console: https://console.developers.google.com/
|
||||||
|
// 2. Create a new project.
|
||||||
|
// 3. Go to "APIs & Services" -> "Credentials".
|
||||||
|
// 4. Click "Create Credentials" -> "OAuth client ID".
|
||||||
|
// 5. Select "Web application" for the application type.
|
||||||
|
// 6. Under "Authorized redirect URIs", add the EXACT redirect URI for your application.
|
||||||
|
// You can find the correct URI by temporarily adding the following line to your index.php:
|
||||||
|
// echo "Your Redirect URI is: " . GOOGLE_REDIRECT_URI;
|
||||||
|
// 7. Click "Create".
|
||||||
|
// 8. Copy the "Client ID" and "Client Secret" and paste them below.
|
||||||
|
|
||||||
|
define('GOOGLE_CLIENT_ID', '105420142772-pfmcst2vhtm9to0tmaeonua2varbb0qd.apps.googleusercontent.com');
|
||||||
|
define('GOOGLE_CLIENT_SECRET', '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');
|
||||||
|
|
||||||
|
// Set the redirect URI to use https, as required for production apps.
|
||||||
|
define('GOOGLE_REDIRECT_URI', 'https://' . $_SERVER['HTTP_HOST'] . '/callback.php');
|
||||||
|
?>
|
||||||
189
index.php
189
index.php
@ -1,131 +1,74 @@
|
|||||||
<?php
|
<?php
|
||||||
declare(strict_types=1);
|
session_start();
|
||||||
@ini_set('display_errors', '1');
|
require_once 'google_config.php';
|
||||||
@error_reporting(E_ALL);
|
|
||||||
@date_default_timezone_set('UTC');
|
|
||||||
|
|
||||||
$phpVersion = PHP_VERSION;
|
|
||||||
$now = date('Y-m-d H:i:s');
|
|
||||||
?>
|
?>
|
||||||
<!doctype html>
|
<!DOCTYPE html>
|
||||||
<html lang="en">
|
<html lang="en">
|
||||||
<head>
|
<head>
|
||||||
<meta charset="utf-8" />
|
<meta charset="UTF-8">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
<title>New Style</title>
|
<title>My Calendar</title>
|
||||||
<link rel="preconnect" href="https://fonts.googleapis.com">
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
|
||||||
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.10.5/font/bootstrap-icons.css">
|
||||||
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;700&display=swap" rel="stylesheet">
|
<link href="https://fonts.googleapis.com/css2?family=Roboto:wght@400;500;700&display=swap" rel="stylesheet">
|
||||||
<style>
|
<link rel="stylesheet" href="assets/css/custom.css?v=<?php echo time(); ?>">
|
||||||
:root {
|
|
||||||
--bg-color-start: #6a11cb;
|
|
||||||
--bg-color-end: #2575fc;
|
|
||||||
--text-color: #ffffff;
|
|
||||||
--card-bg-color: rgba(255, 255, 255, 0.01);
|
|
||||||
--card-border-color: rgba(255, 255, 255, 0.1);
|
|
||||||
}
|
|
||||||
body {
|
|
||||||
margin: 0;
|
|
||||||
font-family: 'Inter', sans-serif;
|
|
||||||
background: linear-gradient(45deg, var(--bg-color-start), var(--bg-color-end));
|
|
||||||
color: var(--text-color);
|
|
||||||
display: flex;
|
|
||||||
justify-content: center;
|
|
||||||
align-items: center;
|
|
||||||
min-height: 100vh;
|
|
||||||
text-align: center;
|
|
||||||
overflow: hidden;
|
|
||||||
position: relative;
|
|
||||||
}
|
|
||||||
body::before {
|
|
||||||
content: '';
|
|
||||||
position: absolute;
|
|
||||||
top: 0;
|
|
||||||
left: 0;
|
|
||||||
width: 100%;
|
|
||||||
height: 100%;
|
|
||||||
background-image: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="100" height="100" viewBox="0 0 100 100"><path d="M-10 10L110 10M10 -10L10 110" stroke-width="1" stroke="rgba(255,255,255,0.05)"/></svg>');
|
|
||||||
animation: bg-pan 20s linear infinite;
|
|
||||||
z-index: -1;
|
|
||||||
}
|
|
||||||
@keyframes bg-pan {
|
|
||||||
0% { background-position: 0% 0%; }
|
|
||||||
100% { background-position: 100% 100%; }
|
|
||||||
}
|
|
||||||
main {
|
|
||||||
padding: 2rem;
|
|
||||||
}
|
|
||||||
.card {
|
|
||||||
background: var(--card-bg-color);
|
|
||||||
border: 1px solid var(--card-border-color);
|
|
||||||
border-radius: 16px;
|
|
||||||
padding: 2rem;
|
|
||||||
backdrop-filter: blur(20px);
|
|
||||||
-webkit-backdrop-filter: blur(20px);
|
|
||||||
box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.1);
|
|
||||||
}
|
|
||||||
.loader {
|
|
||||||
margin: 1.25rem auto 1.25rem;
|
|
||||||
width: 48px;
|
|
||||||
height: 48px;
|
|
||||||
border: 3px solid rgba(255, 255, 255, 0.25);
|
|
||||||
border-top-color: #fff;
|
|
||||||
border-radius: 50%;
|
|
||||||
animation: spin 1s linear infinite;
|
|
||||||
}
|
|
||||||
@keyframes spin {
|
|
||||||
from { transform: rotate(0deg); }
|
|
||||||
to { transform: rotate(360deg); }
|
|
||||||
}
|
|
||||||
.hint {
|
|
||||||
opacity: 0.9;
|
|
||||||
}
|
|
||||||
.sr-only {
|
|
||||||
position: absolute;
|
|
||||||
width: 1px; height: 1px;
|
|
||||||
padding: 0; margin: -1px;
|
|
||||||
overflow: hidden;
|
|
||||||
clip: rect(0, 0, 0, 0);
|
|
||||||
white-space: nowrap; border: 0;
|
|
||||||
}
|
|
||||||
h1 {
|
|
||||||
font-size: 3rem;
|
|
||||||
font-weight: 700;
|
|
||||||
margin: 0 0 1rem;
|
|
||||||
letter-spacing: -1px;
|
|
||||||
}
|
|
||||||
p {
|
|
||||||
margin: 0.5rem 0;
|
|
||||||
font-size: 1.1rem;
|
|
||||||
}
|
|
||||||
code {
|
|
||||||
background: rgba(0,0,0,0.2);
|
|
||||||
padding: 2px 6px;
|
|
||||||
border-radius: 4px;
|
|
||||||
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
|
|
||||||
}
|
|
||||||
footer {
|
|
||||||
position: absolute;
|
|
||||||
bottom: 1rem;
|
|
||||||
font-size: 0.8rem;
|
|
||||||
opacity: 0.7;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<main>
|
|
||||||
<div class="card">
|
|
||||||
<h1>Analyzing your requirements and generating your website…</h1>
|
<nav class="navbar navbar-expand-lg navbar-light">
|
||||||
<div class="loader" role="status" aria-live="polite" aria-label="Applying initial changes">
|
<div class="container">
|
||||||
<span class="sr-only">Loading…</span>
|
<a class="navbar-brand" href="#">
|
||||||
</div>
|
<i class="bi bi-calendar-check"></i>
|
||||||
<p class="hint">Flatlogic AI is collecting your requirements and applying the first changes.</p>
|
My Calendar
|
||||||
<p class="hint">This page will update automatically as the plan is implemented.</p>
|
</a>
|
||||||
<p>Runtime: PHP <code><?= htmlspecialchars($phpVersion) ?></code> — UTC <code><?= htmlspecialchars($now) ?></code></p>
|
</div>
|
||||||
</div>
|
</nav>
|
||||||
</main>
|
|
||||||
<footer>
|
<header class="hero">
|
||||||
Page updated: <?= htmlspecialchars($now) ?> (UTC)
|
<div class="container">
|
||||||
</footer>
|
<h1 class="display-4">Your Personal Calendar</h1>
|
||||||
|
<p class="lead">All your events, in one place.</p>
|
||||||
|
<?php if (isset($_SESSION['access_token'])): ?>
|
||||||
|
<a href="logout.php" class="btn btn-danger btn-lg">
|
||||||
|
<i class="bi bi-google"></i> Disconnect Google Calendar
|
||||||
|
</a>
|
||||||
|
<?php else: ?>
|
||||||
|
<a href="oauth-redirect.php" class="btn btn-primary btn-lg">
|
||||||
|
<i class="bi bi-google"></i> Connect Google Calendar
|
||||||
|
</a>
|
||||||
|
<?php endif; ?>
|
||||||
|
</div>
|
||||||
|
</header>
|
||||||
|
|
||||||
|
<main class="container my-5">
|
||||||
|
<?php if (isset($_SESSION['access_token'])): ?>
|
||||||
|
<div class="calendar-view">
|
||||||
|
<h2>Your Upcoming Events</h2>
|
||||||
|
<p>Your calendar events will be displayed here shortly.</p>
|
||||||
|
<!-- JavaScript will populate this area -->
|
||||||
|
</div>
|
||||||
|
<?php else: ?>
|
||||||
|
<div class="calendar-placeholder">
|
||||||
|
<h2>Your calendar will appear here</h2>
|
||||||
|
<p class="text-muted">Connect your Google Calendar to get started.</p>
|
||||||
|
<div class="row mt-4">
|
||||||
|
<div class="col-md-6">
|
||||||
|
<img src="https://picsum.photos/seed/calendar-1/800/600" class="img-fluid rounded" alt="A person organizing their schedule">
|
||||||
|
</div>
|
||||||
|
<div class="col-md-6">
|
||||||
|
<img src="https://picsum.photos/seed/calendar-2/800/600" class="img-fluid rounded" alt="A close-up of a calendar">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<?php endif; ?>
|
||||||
|
</main>
|
||||||
|
|
||||||
|
<footer class="text-center py-4">
|
||||||
|
<p>© <?php echo date("Y"); ?> My Calendar. All rights reserved.</p>
|
||||||
|
</footer>
|
||||||
|
|
||||||
|
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
|
||||||
|
<script src="assets/js/main.js?v=<?php echo time(); ?>"></script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
23
logout.php
Normal file
23
logout.php
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
<?php
|
||||||
|
session_start();
|
||||||
|
|
||||||
|
// Unset all of the session variables.
|
||||||
|
$_SESSION = array();
|
||||||
|
|
||||||
|
// If it's desired to kill the session, also delete the session cookie.
|
||||||
|
// Note: This will destroy the session, and not just the session data!
|
||||||
|
if (ini_get("session.use_cookies")) {
|
||||||
|
$params = session_get_cookie_params();
|
||||||
|
setcookie(session_name(), '', time() - 42000,
|
||||||
|
$params["path"], $params["domain"],
|
||||||
|
$params["secure"], $params["httponly"]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Finally, destroy the session.
|
||||||
|
session_destroy();
|
||||||
|
|
||||||
|
// Redirect to homepage
|
||||||
|
header('Location: index.php');
|
||||||
|
exit();
|
||||||
|
?>
|
||||||
22
oauth-redirect.php
Normal file
22
oauth-redirect.php
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
<?php
|
||||||
|
session_start();
|
||||||
|
require_once 'google_config.php';
|
||||||
|
|
||||||
|
// If we have an access token, the user is already connected.
|
||||||
|
if (isset($_SESSION['access_token'])) {
|
||||||
|
header('Location: index.php');
|
||||||
|
exit();
|
||||||
|
}
|
||||||
|
|
||||||
|
$auth_url = 'https://accounts.google.com/o/oauth2/v2/auth?' . http_build_query([
|
||||||
|
'client_id' => GOOGLE_CLIENT_ID,
|
||||||
|
'redirect_uri' => GOOGLE_REDIRECT_URI,
|
||||||
|
'response_type' => 'code',
|
||||||
|
'scope' => 'https://www.googleapis.com/auth/calendar.readonly',
|
||||||
|
'access_type' => 'offline', // Required to get a refresh token
|
||||||
|
'prompt' => 'consent' // Forces the consent screen to be shown every time
|
||||||
|
]);
|
||||||
|
|
||||||
|
header('Location: ' . $auth_url);
|
||||||
|
exit();
|
||||||
|
?>
|
||||||
Loading…
x
Reference in New Issue
Block a user