forked from are0h/TheBadSpace
Implemented Custom Auth Framework
Rebuilt member authorization and session handling within Laravel's envirnoment. Sticking with bcrypt encryption for passwords to make the transistion simple.about-updates
parent
ba79c9924c
commit
14af284103
@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
class AuthController extends Controller
|
||||
{
|
||||
public function showLogin(Request $request)
|
||||
{
|
||||
//$token = $request->session()->token();
|
||||
|
||||
//$token = csrf_token();
|
||||
return view('front.login');
|
||||
}
|
||||
|
||||
public function memberAuth(Request $request): Response
|
||||
{
|
||||
$token = csrf_token();
|
||||
|
||||
$credentials = $request->validate([
|
||||
'handle' => ['required'],
|
||||
'password' => ['required'],
|
||||
]);
|
||||
|
||||
if (Auth::attempt($credentials)) {
|
||||
$request->session()->regenerate();
|
||||
return redirect()->intended('den');
|
||||
}
|
||||
|
||||
return back()->withErrors([
|
||||
'error' => 'Nope. Check your crendtials, champ',
|
||||
]);
|
||||
}
|
||||
|
||||
public function leave(Request $request): Response
|
||||
{
|
||||
Auth::logout();
|
||||
|
||||
$request->session()->invalidate();
|
||||
|
||||
$request->session()->regenerateToken();
|
||||
|
||||
return redirect()->intended('login');
|
||||
}
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
class DenController extends Controller
|
||||
{
|
||||
//
|
||||
public function start(Request $request)
|
||||
{
|
||||
$member = Auth::user();
|
||||
return view('back.start', ['handle' => $member->handle]);
|
||||
}
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Closure;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
class MemberCheck
|
||||
{
|
||||
/**
|
||||
* Handle an incoming request.
|
||||
*
|
||||
* @param \Closure(\Illuminate\Http\Request): (\Symfony\Component\HttpFoundation\Response) $next
|
||||
*/
|
||||
public function handle(Request $request, Closure $next)
|
||||
{
|
||||
if (Auth::check()) {
|
||||
return $next($request);
|
||||
} else {
|
||||
return redirect('login');
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use App\Models\User as Authenticatable;
|
||||
|
||||
class Member extends Authenticatable
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $table = "member";
|
||||
protected $fillable = ["uuid", "handle", "email", "password", "active", "role", "avatar", "pronoun", "gender"];
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
@extends('frame')
|
||||
|
||||
@section('title', 'Den|Start')
|
||||
|
||||
@section('main-content')
|
||||
|
||||
<div>
|
||||
<h1>The Den</h1>
|
||||
Hey {{$handle}}
|
||||
</div>
|
||||
@endsection
|
@ -0,0 +1,21 @@
|
||||
@extends('frame')
|
||||
|
||||
@section('title', 'Login')
|
||||
|
||||
@section('main-content')
|
||||
@parent
|
||||
@if($errors->any())
|
||||
<h4>{{$errors->first()}}</h4>
|
||||
@endif
|
||||
<div>
|
||||
<form action="/login" method="post" enctype="multipart/form-data">
|
||||
@csrf
|
||||
<label>Handle</label><br />
|
||||
<input type="text" name="handle" value="" />
|
||||
<br />
|
||||
<label>Password</label><br />
|
||||
<input type="password" name="password" value="" />
|
||||
<input type="submit" value="Knock Knock" name="submit_button">
|
||||
</form>
|
||||
</div>
|
||||
@endsection
|
Loading…
Reference in New Issue