Skip to content

Commit

Permalink
add dashboard
Browse files Browse the repository at this point in the history
  • Loading branch information
johnroper100 committed Mar 28, 2021
1 parent 8a1f160 commit 0992023
Show file tree
Hide file tree
Showing 9 changed files with 113 additions and 92 deletions.
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ Dropplets v2.2

## Manage Your Blog:

- Add a new post at `https://(your url)/write`

- Change settings at `https://(your url)/setup`
Go to `https://(your url)/dashboard` and all of the site options will be available.

## Project Goals:

Expand Down
39 changes: 27 additions & 12 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
$pageTitle = "Home";
require __DIR__ . '/templates/' . $siteConfig['template'] . '/home.php';
} else {
header("Location: " . $router->generate('setup'));
header("Location: " . $router->generate('settings'));
}
}, 'home');

Expand All @@ -82,7 +82,7 @@
$pageTitle = "Posts";
require __DIR__ . '/templates/' . $siteConfig['template'] . '/home.php';
} else {
header("Location: " . $router->generate('setup'));
header("Location: " . $router->generate('settings'));
}
}, 'posts');

Expand All @@ -101,11 +101,11 @@
require __DIR__ . '/templates/' . $siteConfig['template'] . '/post.php';
}
} else {
header("Location: " . $router->generate('setup'));
header("Location: " . $router->generate('settings'));
}
}, 'post');

$router->map('GET|POST', '/setup', function () {
$router->map('GET|POST', '/settings', function () {
global $siteConfig;
global $router;
if (isset($_SESSION['isAuthenticated']) || !file_exists("config.php")) {
Expand All @@ -126,16 +126,16 @@
header("Location: " . $router->generate('home'));
}
} else {
header("Location: " . $router->generate('setup'));
header("Location: " . $router->generate('settings'));
}
} else {
$pageTitle = "Setup";
require __DIR__ . '/internal/setup.php';
$pageTitle = "Settings";
require __DIR__ . '/internal/settings.php';
}
} else {
header("Location: " . $router->generate('login'));
}
}, 'setup');
}, 'settings');

$router->map('GET|POST', '/write', function () {
global $siteConfig;
Expand Down Expand Up @@ -171,7 +171,7 @@
session_destroy();
header("Location: " . $router->generate('home'));
} else {
header("Location: " . $router->generate('setup'));
header("Location: " . $router->generate('settings'));
}
}, 'logout');

Expand All @@ -180,13 +180,13 @@
global $siteConfig;
if (file_exists("config.php")) {
if (isset($_SESSION['isAuthenticated'])) {
//header("Location: " . $router->generate('dashboard'));
header("Location: " . $router->generate('dashboard'));
} else {
if ($_SERVER["REQUEST_METHOD"] == "POST") {
if (isset($_POST["blogPassword"])) {
if (password_verify($_POST["blogPassword"], $siteConfig['password'])) {
$_SESSION['isAuthenticated'] = true;
//header("Location: " . $router->generate('dashboard'));
header("Location: " . $router->generate('dashboard'));
}
}
header("Location: " . $router->generate('login'));
Expand All @@ -196,10 +196,25 @@
}
}
} else {
header("Location: " . $router->generate('setup'));
header("Location: " . $router->generate('settings'));
}
}, 'login');

$router->map('GET', '/dashboard', function () {
global $router;
global $siteConfig;
if (file_exists("config.php")) {
if (isset($_SESSION['isAuthenticated'])) {
$pageTitle = "Dashboard";
require __DIR__ . '/internal/dashboard.php';
} else {
header("Location: " . $router->generate('login'));
}
} else {
header("Location: " . $router->generate('settings'));
}
}, 'dashboard');

$match = $router->match();

session_start();
Expand Down
12 changes: 12 additions & 0 deletions internal/dashboard.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php
require "header.php";
?>
<h1 class="setupH1 setup">Your Blog Dashboard</h1>
<div style="text-align: center;">
<a href="<?php echo $router->generate('write'); ?>" class="btn">Write A Blog Post</a>
<a href="<?php echo $router->generate('settings'); ?>" class="btn">Edit The Site Settings</a>
<a href="<?php echo $router->generate('logout'); ?>" class="btn">Log Out</a>
</div>
<?php
require "footer.php";
?>
1 change: 1 addition & 0 deletions internal/footer.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
</div>
</body>

</html>
6 changes: 5 additions & 1 deletion internal/header.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,8 @@
<script src="https://cdn.jsdelivr.net/simplemde/latest/simplemde.min.js"></script>
</head>

<body>
<body>
<div class="setup">
<div class="setupHeader">
<a href="https://github.com/johnroper100/dropplets"><span class="headerLogo"></span><span class="droppletsName">Dropplets</span></a>
</div>
21 changes: 8 additions & 13 deletions internal/login.php
Original file line number Diff line number Diff line change
@@ -1,19 +1,14 @@
<?php
require "header.php";
?>
<div class="setup">
<div class="setupHeader">
<a href="https://github.com/johnroper100/dropplets"><span class="headerLogo"></span><span class="droppletsName">Dropplets</span></a>
</div>
<h1 class="setupH1 setup">Log Into Your Blog</h1>
<form method="post" action="<?php echo $router->generate('login'); ?>">
<fieldset>
<legend>Type your password to update your blog:</legend>
<input type="password" name="blogPassword" placeholder="Management password" required />
</fieldset>
<input class="btn" type="submit" value="Log In" />
</form>
</div>
<h1 class="setupH1 setup">Log Into Your Blog</h1>
<form method="post" action="<?php echo $router->generate('login'); ?>">
<fieldset>
<legend>Type your password to update your blog:</legend>
<input type="password" name="blogPassword" placeholder="Management password" required />
</fieldset>
<input class="btn" type="submit" value="Log In" />
</form>
<?php
require "footer.php";
?>
47 changes: 47 additions & 0 deletions internal/settings.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php
require "header.php";
?>
<?php if ($siteConfig['name'] == "") { ?>
<h1 class="setupH1 setup">Let's create your blog</h1>
<?php } else { ?>
<h1 class="setupH1 setup">Edit your blog's settings</h1>
<?php } ?>
<form method="post" action="<?php echo $router->generate('settings'); ?>">
<fieldset>
<legend>First, some details:</legend>
<label>Blog Name:</label>
<input type="text" name="blogName" placeholder="Enter your blog's name" required value="<?php echo $siteConfig['name']; ?>" />
<label>Blog Info:</label>
<input type="text" name="blogInfo" placeholder="Enter an optional info message" value="<?php echo $siteConfig['info']; ?>" />
<label>Footer Message:</label>
<input type="text" name="blogFooter" placeholder="Enter an optional footer message" value="<?php echo $siteConfig['footer']; ?>" />
<label>Site Template Name:</label>
<input type="text" name="blogTemplate" placeholder="Enter the name of a template" required value="<?php echo $siteConfig['template']; ?>" />
<label>Post Timezone:</label>
<input type="text" name="blogTimezone" placeholder="Enter a timezone" required value="<?php echo $siteConfig['timezone']; ?>" />
<label>Site Base Path:</label>
<input type="text" name="blogBase" placeholder="Enter the base path" value="<?php echo $siteConfig['basePath']; ?>" />
</fieldset>
<?php if (!isset($_SESSION['isAuthenticated'])) { ?>
<fieldset>
<?php if ($siteConfig['name'] == "") { ?>
<legend>Last but not least, the password:</legend>
<input type="password" name="blogPassword" placeholder="Choose a good password" required />
<?php } else { ?>
<legend>Type your password to update your blog:</legend>
<input type="password" name="blogPassword" placeholder="Management password" required />
<?php } ?>
</fieldset>
<?php }
if ($siteConfig['name'] == "") { ?>
<input class="btn" type="submit" value="Create Your Blog" />
<?php } else { ?>
<input class="btn" type="submit" value="Update Your Blog" />
<?php } ?>
</form>
<div style="text-align: center; padding-top: 25px;">
<a href="<?php echo $router->generate('dashboard'); ?>" class="btn btn-sm">Return To Dashboard</a>
</div>
<?php
require "footer.php";
?>
49 changes: 0 additions & 49 deletions internal/setup.php

This file was deleted.

26 changes: 12 additions & 14 deletions internal/write.php
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
<?php
require "header.php";
?>
<div class="setup">
<div class="setupHeader">
<a href="https://github.com/johnroper100/dropplets"><span class="headerLogo"></span><span class="droppletsName">Dropplets</span></a>
</div>
<h1 class="setupH1 setup">Time to write your prose</h1>
<form method="post" action="<?php echo $router->generate('write'); ?>">
<fieldset>
<input type="text" name="blogPostTitle" class="blogPostTitle" placeholder="The post title" required />
<input type="text" name="blogPostAuthor" class="blogPostAuthor" placeholder="The post author" required />
<input type="url" name="blogPostImage" class="blogPostImage" placeholder="A featured image for this post" />
<textarea name="blogPostContent" id="blogPostContent" placeholder="Write your post here, you can use Markdown"></textarea>
</fieldset>
<input class="btn" type="submit" value="Publish New Post" />
</form>
<h1 class="setupH1 setup">Time to write your prose</h1>
<form method="post" action="<?php echo $router->generate('write'); ?>">
<fieldset>
<input type="text" name="blogPostTitle" class="blogPostTitle" placeholder="The post title" required />
<input type="text" name="blogPostAuthor" class="blogPostAuthor" placeholder="The post author" required />
<input type="url" name="blogPostImage" class="blogPostImage" placeholder="A featured image for this post" />
<textarea name="blogPostContent" id="blogPostContent" placeholder="Write your post here, you can use Markdown"></textarea>
</fieldset>
<input class="btn" type="submit" value="Publish New Post" />
</form>
<div style="text-align: center; padding-top: 25px;">
<a href="<?php echo $router->generate('dashboard'); ?>" class="btn btn-sm">Return To Dashboard</a>
</div>
<script>
var simplemde = new SimpleMDE({
Expand Down

0 comments on commit 0992023

Please sign in to comment.