Login Auth Flow
Added controller to handle the login process and session management that stores information about the person that has logged in so that info is available through out the app when logged in
This commit is contained in:
parent
367f20d8fa
commit
c77eeafb2c
6 changed files with 76 additions and 19 deletions
48
app/Http/Controllers/AuthController.php
Normal file
48
app/Http/Controllers/AuthController.php
Normal file
|
@ -0,0 +1,48 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use App\Services\AuthService;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class AuthController extends Controller
|
||||
{
|
||||
public function __construct(
|
||||
AuthService $authService
|
||||
) {
|
||||
$this->auth = $authService;
|
||||
}
|
||||
|
||||
public function enter(Request $request): Response
|
||||
{
|
||||
$token = csrf_token();
|
||||
|
||||
$credentials = $request->validate([
|
||||
'handle' => ['required'],
|
||||
'password' => ['required'],
|
||||
]);
|
||||
|
||||
if ($credentials) {
|
||||
$result = $this->auth->check($request);
|
||||
if ($result['status']) {
|
||||
//$request->session()->regenerate();
|
||||
return redirect()->intended('dashboard');
|
||||
} else {
|
||||
return back()->withErrors([
|
||||
'error' => $result['message'],
|
||||
]);
|
||||
}
|
||||
} else {
|
||||
return back()->withErrors([
|
||||
'error' => 'Nope. Check your crendtials, champ',
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
public function exit(Request $request): Response
|
||||
{
|
||||
session()->flush();
|
||||
return redirect()->intended('dashboard');
|
||||
}
|
||||
}
|
|
@ -4,6 +4,7 @@ namespace App\Http\Controllers;
|
|||
|
||||
use App\Services\SettingsService;
|
||||
use App\Services\AuthService;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class DashController extends Controller
|
||||
{
|
||||
|
@ -20,10 +21,10 @@ class DashController extends Controller
|
|||
$this->auth = $authService;
|
||||
}
|
||||
|
||||
public function start()
|
||||
public function start(Request $request)
|
||||
{
|
||||
return view('back.start', [
|
||||
"status" => false,
|
||||
"status" => (session('handle') !== null ? true : false),
|
||||
"title" => "Fipamo Dash"
|
||||
]);
|
||||
}
|
||||
|
|
|
@ -7,27 +7,31 @@ use function _\find;
|
|||
class AuthService
|
||||
{
|
||||
protected $config;
|
||||
protected $request;
|
||||
|
||||
public function __construct(SettingsService $config)
|
||||
{
|
||||
$this->config = $config;
|
||||
}
|
||||
|
||||
public function check($handle, $pass)
|
||||
public function check($request)
|
||||
{
|
||||
$folks = $this->config->getFolks();
|
||||
$found = find($folks, ['handle' => $handle]);
|
||||
$found = find($folks, ['handle' => $request->handle]);
|
||||
if ($found) {
|
||||
if (password_verify($pass, $found['password'])) {
|
||||
return "WELCOME";
|
||||
if (password_verify($request->password, $found['password'])) {
|
||||
$request->session()->put('handle', $found['handle']);
|
||||
$request->session()->put('email', $found['email']);
|
||||
$request->session()->put('role', $found['role']);
|
||||
$request->session()->put('avi', $found['avi']);
|
||||
return ['status' => true, 'message' => 'HEY WELCOME BACK'];
|
||||
//DO SESSION STUFF
|
||||
} else {
|
||||
return "NOPE";
|
||||
return ['status' => false, 'message' => 'CHECK THAT PASSWORD'];
|
||||
//RETURN ERROR
|
||||
}
|
||||
} else {
|
||||
return "WHO ARE YOU?";
|
||||
//RETURN ERROR
|
||||
return ['status' => false, 'message' => 'CHECK THAT HANDLE'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,12 +2,17 @@
|
|||
<div>
|
||||
<img id="the-logo" src="/assets/images/global/fipamo-logo.svg"/>
|
||||
</div>
|
||||
<form id="login" class='login' name="login" method="POST" onsubmit="return false;">
|
||||
<form action="/login" method="post" enctype="multipart/form-data">
|
||||
@csrf
|
||||
<input type="text" name="handle" class="form-control" placeholder="Handle" required/>
|
||||
<input type="password" name="password" class="form-control" placeholder="Password" required/>
|
||||
<button id="login-btn" class='login-btn'>
|
||||
ID, PLEASE
|
||||
</button>
|
||||
@if($errors->any())
|
||||
<input type="submit" value="{{$errors->first()}}" name="submit_button">
|
||||
@else
|
||||
<input type="submit" value="Knock Knock" name="submit_button">
|
||||
@endif
|
||||
|
||||
<a href="/dashboard/reset-password">?</a>
|
||||
|
||||
</form>
|
||||
</section>
|
||||
|
|
|
@ -30,12 +30,6 @@
|
|||
</div>
|
||||
@endif
|
||||
</header>
|
||||
|
||||
@if($errors->any())
|
||||
<div class="system-notice-error" role="status">
|
||||
{{$errors->first()}}
|
||||
</div>
|
||||
@endif
|
||||
@if(session('message'))
|
||||
<div class="system-notice-message" role="status">
|
||||
{!! session('message') !!}
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
use Illuminate\Support\Facades\Route;
|
||||
use App\Http\Controllers\DashController;
|
||||
use App\Http\Controllers\AuthController;
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
|
@ -20,7 +21,11 @@ Route::get('/', function () {
|
|||
|
||||
//DASHBOARD
|
||||
|
||||
//login stuff
|
||||
Route::post("/login", [AuthController::class, 'enter']);
|
||||
|
||||
//back
|
||||
Route::group(['prefix' => 'dashboard'], function () {
|
||||
Route::get("/", [DashController::class, 'start']);
|
||||
Route::get("/logout", [AuthController::class, 'exit']);
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue