register
This commit is contained in:
parent
86d41488fa
commit
a71110c333
|
@ -0,0 +1,31 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Validation\Rules\Password;
|
||||
|
||||
class RegisteredUserController extends Controller
|
||||
{
|
||||
public function create()
|
||||
{
|
||||
return view('auth.register');
|
||||
}
|
||||
|
||||
public function store()
|
||||
{
|
||||
$validatedAttributes = request()->validate([
|
||||
'fullname' => ['required'],
|
||||
'email' => ['required', 'email', 'confirmed'],
|
||||
'password' => ['required', Password::min(5), 'confirmed'],
|
||||
]);
|
||||
|
||||
$user = User::create($validatedAttributes);
|
||||
|
||||
Auth::login( $user );
|
||||
|
||||
return redirect('/admin');
|
||||
}
|
||||
}
|
|
@ -8,7 +8,7 @@ class SessionController extends Controller
|
|||
{
|
||||
public function create()
|
||||
{
|
||||
return view('admin.login');
|
||||
return view('auth.login');
|
||||
}
|
||||
|
||||
public function store()
|
||||
|
|
|
@ -17,6 +17,7 @@ class User extends Authenticatable
|
|||
* @var array<int, string>
|
||||
*/
|
||||
protected $fillable = [
|
||||
'fullname',
|
||||
'email',
|
||||
'password',
|
||||
];
|
||||
|
|
|
@ -0,0 +1,26 @@
|
|||
<?php
|
||||
|
||||
namespace App\View\Components;
|
||||
|
||||
use Closure;
|
||||
use Illuminate\Contracts\View\View;
|
||||
use Illuminate\View\Component;
|
||||
|
||||
class input extends Component
|
||||
{
|
||||
/**
|
||||
* Create a new component instance.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the view / contents that represent the component.
|
||||
*/
|
||||
public function render(): View|Closure|string
|
||||
{
|
||||
return view('components.input');
|
||||
}
|
||||
}
|
|
@ -13,6 +13,7 @@ return new class extends Migration
|
|||
{
|
||||
Schema::create('users', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('fullname');
|
||||
$table->string('email')->unique();
|
||||
$table->timestamp('email_verified_at')->nullable();
|
||||
$table->string('password');
|
||||
|
|
|
@ -427,6 +427,7 @@ button
|
|||
{ margin-left : -3rem
|
||||
; background : #ddd
|
||||
; border : 0.125rem solid #ddd
|
||||
; box-shadow : inset 0 0 0 0.125rem #ddd
|
||||
}
|
||||
|
||||
.buttons input[type="search"]:hover
|
||||
|
@ -443,13 +444,21 @@ button
|
|||
.buttons input[type="search"] + button:hover
|
||||
, .buttons input[type="search"] + button:focus
|
||||
, .buttons input[type="search"] + button:active
|
||||
{ border : 0.125rem solid #ddd
|
||||
; box-shadow : inset 0 0 0 0.125rem transparent
|
||||
, 0 0 0 0.125rem #fff
|
||||
, 0 0 0 0.3rem #ddd
|
||||
}
|
||||
.buttons input[type="search"]:focus + button:hover
|
||||
, .buttons input[type="search"]:active + button:hover
|
||||
{ border : 0.125rem solid #bbb
|
||||
; box-shadow : inset 0 0 0 0.125rem transparent
|
||||
, 0 0 0 0.125rem #fff
|
||||
, 0 0 0 0.25rem #bbb
|
||||
, 0 0 0 0.3rem #bbb
|
||||
}
|
||||
|
||||
|
||||
|
||||
.red { --b : var( --red ) }
|
||||
.yellow { --b : var( --yellow ) }
|
||||
.green { --b : var( --green ) }
|
||||
|
@ -684,4 +693,30 @@ dfn[title]
|
|||
{ border-bottom: 1pt dotted var(--text) }
|
||||
|
||||
.w-30
|
||||
{ width : 30rem }
|
||||
{ width : 30rem }
|
||||
|
||||
.error
|
||||
{ color : var(--red) }
|
||||
|
||||
.x-input
|
||||
{ display : grid
|
||||
; justify-content : center
|
||||
; gap : 0.5rem 1rem
|
||||
; grid-template :
|
||||
' label input '
|
||||
' error error '
|
||||
auto / 10rem 14rem ;
|
||||
}
|
||||
.x-input label
|
||||
{ grid-area : label
|
||||
; justify-self : flex-end
|
||||
; align-self : center
|
||||
; text-align : right
|
||||
}
|
||||
.x-input input
|
||||
{ grid-area : input
|
||||
; justify-self : flex-start
|
||||
; align-self : flex-start
|
||||
}
|
||||
.x-input .error
|
||||
{ grid-area : error }
|
|
@ -0,0 +1,27 @@
|
|||
<x-layout>
|
||||
|
||||
<form class="col c" method="post" name="register_form" id="register_form" action="/register">
|
||||
@csrf
|
||||
|
||||
<x-input :value="old('fullname')"
|
||||
title="Full Name"
|
||||
required>fullname</x-input>
|
||||
|
||||
<x-input type="email" :value="old('email')"
|
||||
title="E-Mail"
|
||||
required>email</x-input>
|
||||
<x-input type="email" :value="old('email_confirmation')"
|
||||
title="Confirm E-Mail"
|
||||
required>email_confirmation</x-input>
|
||||
|
||||
<x-input type="password"
|
||||
title="Password"
|
||||
required>password</x-input>
|
||||
<x-input type="password"
|
||||
title="Confirm Password"
|
||||
required>password_confirmation</x-input>
|
||||
|
||||
<button type="submit">Register</button>
|
||||
</form>
|
||||
|
||||
</x-layout>
|
|
@ -0,0 +1,17 @@
|
|||
<div class="x-input"
|
||||
title="{{ $attributes['title'] ?? $slot }}"
|
||||
>
|
||||
<label
|
||||
for="{{ $slot }}"
|
||||
>{{ $attributes['title'] ?? $slot }}</label>
|
||||
<input
|
||||
name="{{ $slot }}"
|
||||
id="{{ $slot }}"
|
||||
placeholder="{{ $attributes['title'] ?? $slot }}"
|
||||
{{ $attributes->merge()->filter(fn ($value, $key) => !in_array($key, ['title'])) }}
|
||||
>
|
||||
|
||||
@error( "$slot" )
|
||||
<p class="error">{{ $message }}</p>
|
||||
@enderror
|
||||
</div>
|
|
@ -20,18 +20,29 @@
|
|||
|
||||
|
||||
@guest
|
||||
|
||||
<a href="/register">Register</a>
|
||||
|
||||
<form class="col c" method="post" name="login_form" id="login_form" action="/login">
|
||||
@csrf
|
||||
<input type="email" name="email" placeholder="email"
|
||||
:value="old('email')"
|
||||
required>
|
||||
<input type="password" name="password" placeholder="password" required>
|
||||
<button onclick="login_form.submit()">Login</button>
|
||||
<x-input type="email" :value="old('email')"
|
||||
title="E-Mail"
|
||||
required>email</x-input>
|
||||
<x-input type="password"
|
||||
title="Password"
|
||||
required>password</x-input>
|
||||
<button type="submit">Login</button>
|
||||
</form>
|
||||
@endguest
|
||||
|
||||
@auth
|
||||
{{ $slot }}
|
||||
|
||||
|
||||
<form class="col c" method="post" name="logout_form" id="logout_form" action="/logout">
|
||||
@csrf
|
||||
<button type="submit">Logout</button>
|
||||
</form>
|
||||
@endauth
|
||||
|
||||
<footer class="c">
|
||||
|
@ -41,7 +52,7 @@
|
|||
class="gray" title="search"
|
||||
><span class="hidden">search</span>
|
||||
</button>
|
||||
<a href="/rss" class="orange" title="rss"><span class="hidden">rss</span>
|
||||
<x-nav-link class="orange">rss</x-nav-link>
|
||||
</a>
|
||||
</form>
|
||||
</footer>
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
<?php
|
||||
|
||||
use App\Http\Controllers\RegisteredUserController;
|
||||
use App\Http\Controllers\SessionController;
|
||||
use Illuminate\Support\Facades\Route;
|
||||
|
||||
|
@ -29,6 +30,10 @@ Route::name('admin.index')->get('/admin', function ($name = null) {
|
|||
return view('admin.index');
|
||||
});
|
||||
|
||||
|
||||
Route::get('/register', [RegisteredUserController::class, 'create']);
|
||||
Route::post('/register', [RegisteredUserController::class, 'store']);
|
||||
|
||||
Route::get('/login', [SessionController::class, 'create']);
|
||||
Route::post('/login', [SessionController::class, 'store']);
|
||||
Route::post('/logout', [SessionController::class, 'destroy']);
|
||||
|
|
Loading…
Reference in New Issue