Skip to content

Commit

Permalink
v0.4.1 - bug fixes (closes #26)
Browse files Browse the repository at this point in the history
  • Loading branch information
Justintime50 committed Feb 12, 2021
1 parent 3fec583 commit 7d0462b
Show file tree
Hide file tree
Showing 8 changed files with 82 additions and 37 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# CHANGELOG

## v0.4.1 (2021-02-12)

* Various bug fixes (closes #26)
* Admins can now access their draft posts without an error being thrown
* There is now a unique check in place for post slug names that now ignores the post being updated and only checks against other posts
* Fixed a development bug where data wasn't seeded correctly for categories and rollbacks wouldn't remove that data
* The dark mode theme had text the same color as the background on the admin page which has been fixed
* Reading time and categories now have visual fallbacks if they are not set properly

## v0.4.0 (2021-02-09)

* Fixed slugify integration and dependencies
Expand Down
45 changes: 30 additions & 15 deletions src/app/Http/Controllers/PostController.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,22 @@ public function readPosts(Request $request)

public function create(Request $request)
{
$post = new Post();

request()->validate([
'title' => 'required|string',
'slug' => Rule::unique('posts')->where(function ($query) {
return $query->where('user_id', Auth::user()->id);
}),
'slug' => [
'required',
Rule::unique('posts')->ignore($post->id)->where(function ($query) {
return $query->where('user_id', Auth::user()->id);
})
],
'reading_time' => 'nullable|numeric',
'keywords' => 'nullable|string',
'category' => 'string',
'post' => 'required|string',
]);

$post = new Post();
$post->title = request()->get('title');
$post->slug = request()->get('slug');
$post->published = request()->get('published');
Expand All @@ -54,9 +58,14 @@ public function create(Request $request)

public function read($user, $slug)
{
$post = Post::where('slug', '=', $slug)
// ->where('published', '=', 1) // TODO: Fix this for admins so they can still access their posts even when on "draft"
->firstOrFail();
if (Auth::user()->role = 1) {
$post = Post::where('slug', '=', $slug)
->firstOrFail();
} else {
$post = Post::where('slug', '=', $slug)
->where('published', '=', 1)
->firstOrFail();
}
$comments = Comment::where('post_id', '=', $post->id)
->orderBy('created_at', 'asc')
->paginate(15);
Expand All @@ -82,21 +91,23 @@ public function readEdit($user, $slug)

public function update(Request $request)
{
$id = request()->get('id');
$post = Post::where('id', '=', $id)->first();

request()->validate([
'title' => 'required|string',
/* TODO: fix validation to allow the same slug as the current one when updating
'slug' => Rule::unique('posts')->where(function ($query) {
return $query->where('user_id', Auth::user()->id);
}),
*/
'slug' => [
'required',
Rule::unique('posts')->ignore($post->id)->where(function ($query) {
return $query->where('user_id', Auth::user()->id);
})
],
'reading_time' => 'nullable|numeric',
'keywords' => 'nullable|string',
'category' => 'string',
'post' => 'required|string',
]);

$id = request()->get('id');
$post = Post::where('id', '=', $id)->first();
$post->published = request()->get('published');
$post->banner_image_url = request()->get('banner_image_url');
$post->title = request()->get('title');
Expand Down Expand Up @@ -141,7 +152,11 @@ public function uploadPostImage(Request $request)
$request->validate([
'upload_image' => 'required|image|mimes:jpeg,jpg,png|max:2048',
]);
$id = mt_rand(100000000000, 999999999999); # TODO: This is hacky, fix down the road

// ~1 billion possible id's, overlap potential should be small
$id_min = 1000000000;
$id_max = 9999999999;
$id = mt_rand($id_min, $id_max);

if (!is_dir(storage_path("app/public/post-images"))) {
mkdir(storage_path("app/public/post-images"), 0775, true);
Expand Down
41 changes: 27 additions & 14 deletions src/database/migrations/2020_01_27_213243_insert_admin_account.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
use App\Models\User;
use App\Models\Setting;
use App\Models\Category;

class InsertAdminAccount extends Migration
{
Expand All @@ -14,21 +17,29 @@ class InsertAdminAccount extends Migration
public function up()
{
// Seed User's table with initial account
DB::table('users')->insert([
'name' => "admin",
'email' => "[email protected]",
'email_verified_at' => now(),
'password' => '$2y$10$P/XLoBoBIkfD6QBxhV5GB.2jXL5OZkc9E2pWAVkm9IKoAUQ0zct52', // password = "password"
'remember_token' => Str::random(10),
'role' => 1,
]);
$user = new User();
$user->id = 1;
$user->name = "admin";
$user->email = "[email protected]";
$user->email_verified_at = now();
$user->password = '$2y$10$P/XLoBoBIkfD6QBxhV5GB.2jXL5OZkc9E2pWAVkm9IKoAUQ0zct52'; // secret
$user->remember_token = Str::random(10);
$user->role = 1;
$user->save();

// Seed settings table with initial settings
DB::table('settings')->insert([
'title' => "Blog",
'theme' => 1,
'comments' => 1,
]);
$setting = new Setting();
$setting-> id = 1;
$setting->title = "Blog";
$setting->theme = 1;
$setting->comments = 1;
$setting->save();

// Seed an initial category
$category = new Category();
$category->user_id = 1;
$category->category = 'Uncategorized';
$category->save();
}

/**
Expand All @@ -38,6 +49,8 @@ public function up()
*/
public function down()
{
// TODO: Add in a way to delete this
User::truncate();
Setting::truncate();
Category::truncate();
}
}
6 changes: 5 additions & 1 deletion src/public/css/dark-mode.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions src/public/css/dark-mode.scss
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,7 @@ hr {
background-color: #b20000;
border-color: #b20000;
}

.table {
color: #bbe1fa;
}
6 changes: 3 additions & 3 deletions src/resources/views/admin.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,12 @@
<th>Actions</th>
@foreach($users as $user)
<?php
// TODO: Cleanup, there's a better way.
if ($user->role == 1) {
$role = "Admin";
}
if ($user->role == 2) {
} elseif ($user->role == 2) {
$role = "User";
} else {
$role = "Undefined";
}
?>
<tr>
Expand Down
4 changes: 2 additions & 2 deletions src/resources/views/post.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@
<i class="fas fa-user"></i>
{{ $post->user->name }}
<i class="fas fa-clock"></i>
{{ $post->reading_time }} minutes
@if (isset($post->reading_time)) {{ $post->reading_time }} @else {{ '0' }} @endif minutes
<i class="fas fa-tag"></i>
{{ $post->category->category }}
@if (isset($post->category->category)) {{ $post->category->category }} @else {{ 'Uncategorized' }} @endif
</p>
<div class="banner-image-container">
@if (file_exists("storage/post-images/$post->banner_image_url") && $post->banner_image_url != null)
Expand Down
4 changes: 2 additions & 2 deletions src/resources/views/posts.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@
<i class="fas fa-user"></i>
{{ $post->user->name }}
<i class="fas fa-clock"></i>
{{ $post->reading_time }} minutes
@if (isset($post->reading_time)) {{ $post->reading_time }} @else {{ '0' }} @endif minutes
<i class="fas fa-tag"></i>
{{ $post->category->category }}
@if (isset($post->category->category)) {{ $post->category->category }} @else {{ 'Uncategorized' }} @endif
</p>
<p>
<?php $strippedPost = preg_replace("/[^0-9a-zA-Z_.!?' \r\n+]/", "", $post->post); ?>
Expand Down

0 comments on commit 7d0462b

Please sign in to comment.