WIP: Semi-complete authentication including several writer view stubs
This commit is contained in:
parent
e7c08e989a
commit
d2d75d2efb
|
|
@ -0,0 +1,50 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
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');
|
||||
}
|
||||
}
|
||||
|
|
@ -6,6 +6,7 @@ use App\Models\User;
|
|||
use App\Models\Author;
|
||||
use App\Models\Article;
|
||||
use Illuminate\Database\Seeder;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
|
||||
class DatabaseSeeder extends Seeder
|
||||
{
|
||||
|
|
@ -17,6 +18,7 @@ class DatabaseSeeder extends Seeder
|
|||
$test_user = User::factory()->create([
|
||||
'name' => 'Test User',
|
||||
'email' => 'test@example.com',
|
||||
'password' => Hash::make('password'),
|
||||
]);
|
||||
|
||||
$test_author = Author::factory()->user($test_user)->create();
|
||||
|
|
|
|||
|
|
@ -0,0 +1,3 @@
|
|||
.is-invalid {
|
||||
border: red 4px solid;
|
||||
}
|
||||
|
|
@ -22,10 +22,11 @@ a {
|
|||
justify-content: center;
|
||||
}
|
||||
|
||||
|
||||
.bubble-panel {
|
||||
border-radius: 50px;
|
||||
background: #813d9c;
|
||||
box-shadow: -33px 33px 65px #66307b,
|
||||
33px -33px 65px #9c4abd;
|
||||
padding: 2em;
|
||||
}
|
||||
}
|
||||
|
|
@ -4,26 +4,22 @@
|
|||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
|
||||
<!-- Include our local version of HTMX -->
|
||||
<link href="/word-salad.css" rel="stylesheet" />
|
||||
<link href="/word-salad-writer.css" rel="stylesheet" />
|
||||
|
||||
{{-- Include HTMX on the writer-side to enchance our interactivity --}}
|
||||
<script src="/htmx.1.9.12.js"></script>
|
||||
|
||||
<link href="/word-salad.css" rel="stylesheet" />
|
||||
|
||||
<title>{{ config('blog.publishing_name') }} | Home</title>
|
||||
<title>{{ config('blog.publishing_name') }} | @yield('title')</title>
|
||||
</head>
|
||||
<body>
|
||||
<main>
|
||||
<h2>Hey guys, check back soon for some word-based #content</h2>
|
||||
|
||||
<div id="button-container">
|
||||
<button hx-get="{{ route('surprise') }}"
|
||||
hx-trigger="click"
|
||||
hx-target="#button-container"
|
||||
hx-swap="outerHTML"
|
||||
>
|
||||
Click Me!
|
||||
</button>
|
||||
</div>
|
||||
</main>
|
||||
<section id="error-bag">
|
||||
@foreach($errors->all() as $error)
|
||||
{{ $error }}
|
||||
@endforeach
|
||||
</section>
|
||||
<main>
|
||||
@yield('content', 'Nothing to see here.')
|
||||
</main>
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
|||
|
|
@ -0,0 +1,14 @@
|
|||
@extends('layouts.writer')
|
||||
|
||||
@section('title', 'Writer Dashboard')
|
||||
|
||||
@section('content')
|
||||
<div>
|
||||
<h1>Writer's Dashboard</h1>
|
||||
<form method="POST" action="{{ route('logout') }}">
|
||||
@csrf
|
||||
<button type="submit">Logout</button>
|
||||
</form>
|
||||
<a href="{{ route('new_article') }}"><button>New Article</button></a>
|
||||
</div>
|
||||
@endsection
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
@extends('layouts.writer')
|
||||
|
||||
@section('title', 'Writer Login')
|
||||
|
||||
@section('content')
|
||||
<section class="bubble-panel">
|
||||
<h2>Writer Login</h2>
|
||||
<form action="{{ route('authenticate') }}" method="POST">
|
||||
|
||||
@csrf
|
||||
|
||||
<label for="email">Email</label>
|
||||
<input class="@error('email') is-invalid @enderror" type="text" name="email" />
|
||||
|
||||
<label for="password">Password</label>
|
||||
<input class="@error('password') is-invalid @enderror" type="password" name="password" />
|
||||
|
||||
<button type="submit">Login</button>
|
||||
</form>
|
||||
</section>
|
||||
@endsection
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
@extends('layouts.writer')
|
||||
|
||||
@section('title', 'Write New Article')
|
||||
|
||||
@section('content')
|
||||
<div>
|
||||
New Article
|
||||
</div>
|
||||
@endsection
|
||||
|
|
@ -1,5 +1,6 @@
|
|||
<?php
|
||||
|
||||
use App\Http\Controllers\WriterController;
|
||||
use App\Models\Article;
|
||||
use Illuminate\Support\Facades\Route;
|
||||
|
||||
|
|
@ -38,3 +39,15 @@ Route::get('/post/{article_slug}', function ($article_slug) {
|
|||
}
|
||||
return view('guest.article', ['article' => $active_article]);
|
||||
})->name('article');
|
||||
|
||||
Route::get('/writer/login', function () {
|
||||
return view('writer.login');
|
||||
})->name('login');
|
||||
|
||||
Route::post('/writer/authenticate', [WriterController::class, 'authenticate'])->name('authenticate');
|
||||
|
||||
Route::middleware('auth')->group(function () {
|
||||
Route::get('/writer', [WriterController::class, 'dashboard'])->name('dashboard');
|
||||
Route::post('/logout', [WriterController::class, 'logout'])->name('logout');
|
||||
Route::get('writer/new-article', [WriterController::class, 'newArticle'])->name('new_article');
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in New Issue