2024-08-04 21:38:41 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
|
2024-08-04 22:53:04 +00:00
|
|
|
use App\Models\Article;
|
2024-08-04 21:38:41 +00:00
|
|
|
use Illuminate\Http\Request;
|
|
|
|
|
use Illuminate\Contracts\View\View;
|
|
|
|
|
use Illuminate\Support\Facades\Auth;
|
|
|
|
|
use Illuminate\Http\RedirectResponse;
|
|
|
|
|
|
|
|
|
|
class WriterController extends Controller
|
|
|
|
|
{
|
|
|
|
|
public function authenticate(Request $request): RedirectResponse
|
|
|
|
|
{
|
|
|
|
|
$credentials = $request->validate([
|
|
|
|
|
'email' => ['required', 'email'],
|
|
|
|
|
'password' => ['required'],
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
if (Auth::attempt($credentials)) {
|
|
|
|
|
$request->session()->regenerate();
|
|
|
|
|
|
|
|
|
|
return redirect()->intended('writer');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return back()->withErrors([
|
|
|
|
|
'email' => 'The provided credentials do not match our records.',
|
|
|
|
|
])->onlyInput('email');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function logout(Request $request): RedirectResponse
|
|
|
|
|
{
|
|
|
|
|
Auth::logout();
|
|
|
|
|
|
|
|
|
|
$request->session()->invalidate();
|
|
|
|
|
|
|
|
|
|
$request->session()->regenerateToken();
|
|
|
|
|
|
|
|
|
|
return redirect(route('login'));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function dashboard(Request $request): View
|
|
|
|
|
{
|
|
|
|
|
return view('writer.dashboard');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function newArticle(Request $request): View
|
|
|
|
|
{
|
|
|
|
|
return view('writer.new-article');
|
|
|
|
|
}
|
2024-08-04 22:53:04 +00:00
|
|
|
|
|
|
|
|
public function livePreview(Request $request): View
|
|
|
|
|
{
|
|
|
|
|
// Upload the file
|
|
|
|
|
$header_image_path = $request->headerImage->storeAs('header-image-previews');
|
|
|
|
|
$article_empty = new Article();
|
|
|
|
|
$article_empty->markdown_body = $request->markdownBody;
|
|
|
|
|
$article_empty->generateMarkupFromMarkdown();
|
|
|
|
|
|
|
|
|
|
$article = [
|
|
|
|
|
'title' => $request->title ?? null,
|
|
|
|
|
'header_image_url' => $header_image_path ?? null,
|
|
|
|
|
'subtitle' => $request->subtitle ?? null,
|
|
|
|
|
'author' => [
|
|
|
|
|
'display_name' => auth()->user()->author->displayName,
|
|
|
|
|
],
|
|
|
|
|
'published_at' => $request->publicationDate ?? null,
|
|
|
|
|
'primary_link' => $request->primary_link ?? null,
|
|
|
|
|
'secondary_link' => $request->secondary_link ?? null,
|
|
|
|
|
'mastodon_handle' => $request->mastodon_handle ?? null,
|
|
|
|
|
'body' => $article_empty->body,
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
return view('guest.article', ['article' => $article]);
|
|
|
|
|
}
|
2024-08-04 21:38:41 +00:00
|
|
|
}
|