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\SettingsService;
|
||||||
use App\Services\AuthService;
|
use App\Services\AuthService;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
|
||||||
class DashController extends Controller
|
class DashController extends Controller
|
||||||
{
|
{
|
||||||
|
@ -20,10 +21,10 @@ class DashController extends Controller
|
||||||
$this->auth = $authService;
|
$this->auth = $authService;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function start()
|
public function start(Request $request)
|
||||||
{
|
{
|
||||||
return view('back.start', [
|
return view('back.start', [
|
||||||
"status" => false,
|
"status" => (session('handle') !== null ? true : false),
|
||||||
"title" => "Fipamo Dash"
|
"title" => "Fipamo Dash"
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,27 +7,31 @@ use function _\find;
|
||||||
class AuthService
|
class AuthService
|
||||||
{
|
{
|
||||||
protected $config;
|
protected $config;
|
||||||
|
protected $request;
|
||||||
|
|
||||||
public function __construct(SettingsService $config)
|
public function __construct(SettingsService $config)
|
||||||
{
|
{
|
||||||
$this->config = $config;
|
$this->config = $config;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function check($handle, $pass)
|
public function check($request)
|
||||||
{
|
{
|
||||||
$folks = $this->config->getFolks();
|
$folks = $this->config->getFolks();
|
||||||
$found = find($folks, ['handle' => $handle]);
|
$found = find($folks, ['handle' => $request->handle]);
|
||||||
if ($found) {
|
if ($found) {
|
||||||
if (password_verify($pass, $found['password'])) {
|
if (password_verify($request->password, $found['password'])) {
|
||||||
return "WELCOME";
|
$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
|
//DO SESSION STUFF
|
||||||
} else {
|
} else {
|
||||||
return "NOPE";
|
return ['status' => false, 'message' => 'CHECK THAT PASSWORD'];
|
||||||
//RETURN ERROR
|
//RETURN ERROR
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return "WHO ARE YOU?";
|
return ['status' => false, 'message' => 'CHECK THAT HANDLE'];
|
||||||
//RETURN ERROR
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,12 +2,17 @@
|
||||||
<div>
|
<div>
|
||||||
<img id="the-logo" src="/assets/images/global/fipamo-logo.svg"/>
|
<img id="the-logo" src="/assets/images/global/fipamo-logo.svg"/>
|
||||||
</div>
|
</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="text" name="handle" class="form-control" placeholder="Handle" required/>
|
||||||
<input type="password" name="password" class="form-control" placeholder="Password" required/>
|
<input type="password" name="password" class="form-control" placeholder="Password" required/>
|
||||||
<button id="login-btn" class='login-btn'>
|
@if($errors->any())
|
||||||
ID, PLEASE
|
<input type="submit" value="{{$errors->first()}}" name="submit_button">
|
||||||
</button>
|
@else
|
||||||
|
<input type="submit" value="Knock Knock" name="submit_button">
|
||||||
|
@endif
|
||||||
|
|
||||||
<a href="/dashboard/reset-password">?</a>
|
<a href="/dashboard/reset-password">?</a>
|
||||||
|
|
||||||
</form>
|
</form>
|
||||||
</section>
|
</section>
|
||||||
|
|
|
@ -30,12 +30,6 @@
|
||||||
</div>
|
</div>
|
||||||
@endif
|
@endif
|
||||||
</header>
|
</header>
|
||||||
|
|
||||||
@if($errors->any())
|
|
||||||
<div class="system-notice-error" role="status">
|
|
||||||
{{$errors->first()}}
|
|
||||||
</div>
|
|
||||||
@endif
|
|
||||||
@if(session('message'))
|
@if(session('message'))
|
||||||
<div class="system-notice-message" role="status">
|
<div class="system-notice-message" role="status">
|
||||||
{!! session('message') !!}
|
{!! session('message') !!}
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
use Illuminate\Support\Facades\Route;
|
use Illuminate\Support\Facades\Route;
|
||||||
use App\Http\Controllers\DashController;
|
use App\Http\Controllers\DashController;
|
||||||
|
use App\Http\Controllers\AuthController;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|--------------------------------------------------------------------------
|
|--------------------------------------------------------------------------
|
||||||
|
@ -20,7 +21,11 @@ Route::get('/', function () {
|
||||||
|
|
||||||
//DASHBOARD
|
//DASHBOARD
|
||||||
|
|
||||||
|
//login stuff
|
||||||
|
Route::post("/login", [AuthController::class, 'enter']);
|
||||||
|
|
||||||
//back
|
//back
|
||||||
Route::group(['prefix' => 'dashboard'], function () {
|
Route::group(['prefix' => 'dashboard'], function () {
|
||||||
Route::get("/", [DashController::class, 'start']);
|
Route::get("/", [DashController::class, 'start']);
|
||||||
|
Route::get("/logout", [AuthController::class, 'exit']);
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue