Agregadas rutas con middleware y pantalla de login vacia

This commit is contained in:
Alejandro Tasistro 2024-09-10 21:11:22 -03:00
parent 53691f6a30
commit bf3f697299
4 changed files with 49 additions and 7 deletions

View File

@ -11,4 +11,9 @@ class ComprasController
$file = resource_path('csv/exports/total-pedidos.csv');
return response()->download($file);
}
public function showLoginForm()
{
return view('auth/compras_login');
}
}

View File

@ -3,21 +3,24 @@
namespace App\Http\Middleware;
use Closure;
use Auth;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
class Compras
{
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @param Request $request
* @param Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
public function handle(Request $request, Closure $next)
{
$user = Auth::user();
if ($user->is_compras) {
if (!Auth::check())
return redirect()->route('compras.login');
if (Auth::user()->is_compras) {
return $next($request);
} else {
return response('Necesitás ser de comisión compras para hacer esto', 403);

View File

@ -0,0 +1,32 @@
<!DOCTYPE html>
<html class="has-background-warning" lang="{{ str_replace('_', '-', app()->getLocale()) }}">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>{{ config('app.name', 'Pedidos del MPS') }}</title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bulma@0.9.3/css/bulma.min.css">
<link rel="stylesheet" href="{{ mix('css/app.css') }}">
<script src="https://kit.fontawesome.com/9235d1c676.js" crossorigin="anonymous"></script>
</head>
<body>
<section class="section">
<div id="root" class="container">
<h1 class="title">
Pedidos MPS
</h1>
<p class="subtitle">
Bienvenidx a la sección de compras de la aplicación del <strong>Mercado Popular de Subsistencia</strong>
</p>
@error('name')
<div class="notification is-danger">
Contraseña incorrecta, intentalo nuevamente.
</div>
@enderror
<form method="post" action="login">
@csrf
</form>
</div>
</section>
<script src="{{ mix('js/app.js') }}" defer></script>
</body>
</html>

View File

@ -76,6 +76,8 @@ Route::middleware('auth')->group( function() {
});
});
Route::middleware(['auth', 'compras'])->group( function() {
Route::get('/compras/login', 'ComprasController@showLoginForm')->name('compras.login');
Route::middleware(['compras'])->group( function() {
Route::get('/compras/pedidos', 'ComprasController@pedidos')->name('compras.pedidos');
});