- Added maximum discount settings configurable by the administrator. - Implemented discount calculations in the quote confirmation process. - Introduced transport options with associated costs, including handling for exceeding maximum piece limits. - Updated frontend to display discounts and transport information in the quote summary. - Created new database migrations for storing discount and transport settings. - Developed a new Filament page for managing global discount settings. - Enhanced email templates to include discount and transport details. - Added tests to ensure proper functionality of discounts and transport calculations.
75 lines
2.5 KiB
PHP
75 lines
2.5 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Api;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Models\Cliente;
|
|
use Illuminate\Http\JsonResponse;
|
|
use Illuminate\Http\Request;
|
|
|
|
class AuthController extends Controller
|
|
{
|
|
/**
|
|
* POST /api/auth/login
|
|
* Login del cliente per l'accesso al configuratore (username + password).
|
|
*/
|
|
public function login(Request $request): JsonResponse
|
|
{
|
|
$data = $request->validate([
|
|
'username' => ['required', 'string'],
|
|
'password' => ['required', 'string'],
|
|
]);
|
|
|
|
$cliente = Cliente::where('username', $data['username'])->first();
|
|
|
|
if (! $cliente || ! $cliente->password || ! password_verify($data['password'], $cliente->password)) {
|
|
return response()->json([
|
|
'message' => 'Nome utente o password non validi.',
|
|
], 401);
|
|
}
|
|
|
|
$giorni = (int) config('preventivi.configurator_session_days', 30);
|
|
$token = $cliente->createToken('configuratore', ['*'], now()->addDays($giorni));
|
|
|
|
return response()->json([
|
|
'token' => $token->plainTextToken,
|
|
'expires_at' => $token->accessToken->expires_at,
|
|
'cliente' => [
|
|
'id' => $cliente->id,
|
|
'username' => $cliente->username,
|
|
'nominativo' => $cliente->nominativo,
|
|
],
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* GET /api/auth/me
|
|
* Verifica che il token del configuratore sia ancora valido e restituisce i dati
|
|
* anagrafici del cliente, usati per precompilare il form di richiesta preventivo.
|
|
*/
|
|
public function me(Request $request): JsonResponse
|
|
{
|
|
$cliente = $request->user();
|
|
|
|
return response()->json([
|
|
'cliente' => [
|
|
'id' => $cliente->id,
|
|
'username' => $cliente->username,
|
|
'nominativo' => $cliente->nominativo,
|
|
'nome' => $cliente->nome,
|
|
'cognome' => $cliente->cognome,
|
|
'ragione_sociale' => $cliente->ragione_sociale,
|
|
'email' => $cliente->email,
|
|
'telefono' => $cliente->telefono,
|
|
'indirizzo' => $cliente->indirizzo,
|
|
'cap' => $cliente->cap,
|
|
'citta' => $cliente->citta,
|
|
'provincia' => $cliente->provincia,
|
|
'note' => $cliente->note,
|
|
],
|
|
// Sconti massimi (%) applicabili al preventivo prima dell'invio (0 = non consentito).
|
|
'sconti' => $cliente->scontiMassimi(),
|
|
]);
|
|
}
|
|
}
|