Majdnem kész

This commit is contained in:
Sándor Máté Magony
2025-04-24 15:38:31 +02:00
parent db245545eb
commit 2d71603962
121 changed files with 3870 additions and 2601 deletions

View File

@@ -0,0 +1,32 @@
<?php
namespace App\Console;
use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
class Kernel extends ConsoleKernel
{
/**
* Define the application's command schedule.
*
* @param \Illuminate\Console\Scheduling\Schedule $schedule
* @return void
*/
protected function schedule(Schedule $schedule)
{
// $schedule->command('inspire')->hourly();
}
/**
* Register the commands for the application.
*
* @return void
*/
protected function commands()
{
$this->load(__DIR__.'/Commands');
require base_path('routes/console.php');
}
}

View File

@@ -0,0 +1,41 @@
<?php
namespace App\Exceptions;
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
use Throwable;
class Handler extends ExceptionHandler
{
/**
* A list of the exception types that are not reported.
*
* @var array<int, class-string<Throwable>>
*/
protected $dontReport = [
//
];
/**
* A list of the inputs that are never flashed for validation exceptions.
*
* @var array<int, string>
*/
protected $dontFlash = [
'current_password',
'password',
'password_confirmation',
];
/**
* Register the exception handling callbacks for the application.
*
* @return void
*/
public function register()
{
$this->reportable(function (Throwable $e) {
//
});
}
}

View File

@@ -0,0 +1,103 @@
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use App\Models\User;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Validator;
use Tymon\JWTAuth\Facades\JWTAuth;
class AuthController extends Controller
{
public function __construct()
{
$this->middleware('auth:api', ['except' => ['login', 'register']]);
}
public function register(Request $request)
{
$validator = Validator::make($request->all(), [
'nev' => 'required|string',
'email' => 'required|email|unique:felhasznalok',
'felh_nev' => 'required|string|unique:felhasznalok',
'jelszo' => 'required|string|min:6',
'jelszo_confirmation' => 'required|same:jelszo',
'is_admin' => 'boolean'
]);
if ($validator->fails()) {
return response()->json($validator->errors(), 422);
}
$user = User::create([
'nev' => $request->nev,
'email' => $request->email,
'felh_nev' => $request->felh_nev,
'jelszo' => $request->jelszo, // This will be hashed via the mutator
'is_admin' => $request->is_admin ?? false
]);
return response()->json([
'message' => 'Sikeresen regisztrált felhasználó',
'user' => $user
], 201);
}
public function login(Request $request)
{
$validator = Validator::make($request->all(), [
'felh_nev' => 'required|string',
'jelszo' => 'required|string'
]);
if ($validator->fails()) {
return response()->json($validator->errors(), 422);
}
// Since your login fields are custom, you need to specify the fields
$credentials = [
'felh_nev' => $request->felh_nev,
'password' => $request->jelszo // Laravel expects 'password' internally
];
if (!$token = auth('api')->attempt($credentials)) {
return response()->json(['error' => 'Helytelen felhasználónév vagy jelszó'], 401);
}
return $this->respondWithToken($token);
}
public function me()
{
return response()->json(auth('api')->user());
}
public function logout()
{
auth('api')->logout();
return response()->json(['message' => 'Sikeres kijelentkezés']);
}
public function refresh()
{
try {
$token = JWTAuth::parseToken()->refresh();
return $this->respondWithToken($token);
} catch (\Exception $e) {
return response()->json(['error' => 'Could not refresh token'], 401);
}
}
protected function respondWithToken($token)
{
return response()->json([
'access_token' => $token,
'token_type' => 'bearer',
'expires_in' => config('jwt.ttl') * 60, // Getting TTL from config
'user' => auth('api')->user()
]);
}
}

View File

@@ -0,0 +1,13 @@
<?php
namespace App\Http\Controllers;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Routing\Controller as BaseController;
class Controller extends BaseController
{
use AuthorizesRequests, DispatchesJobs, ValidatesRequests;
}

View File

@@ -0,0 +1,100 @@
<?php
namespace App\Http\Controllers;
use App\Models\WcAdatok;
use Illuminate\Http\Request;
class HozzaadasController extends Controller
{
/**
* Display a listing of the resource.
*/
public function index()
{
//
}
/**
* Store a newly created resource in storage.
*/
public function store(Request $request)
{
$validatedData = $request -> validate([
'nev' => 'required|string',
'kerulet' => 'required|string',
'kozeli_megall' => 'required|string',
'akadalym' => 'nullable|boolean',
'ar' => 'nullable|numeric',
'nyitva' => 'nullable|string',
'utvonal' => 'required|string',
'koordinatak' => 'required|string'
]);
try {
$szelesseg = null;
$hosszusag = null;
if (!empty($validatedData['koordinatak'])) {
$koordinatak = explode(',', $validatedData['koordinatak']);
if (count($koordinatak) == 2) {
$hosszusag = trim($koordinatak[0]);
$szelesseg = trim($koordinatak[1]);
if (!is_numeric($szelesseg) || !is_numeric($hosszusag)) {
return response() -> json([
'message' => 'Érvénytelen a koordináták formátuma'
], 422);
}
}
}
$mosdo = WcAdatok::create([
'nev' => $validatedData['nev'],
'kerulet' => $validatedData['kerulet'],
'kozeli_megall' => $validatedData['kozeli_megall'],
'akadalym' => $validatedData['akadalym'],
'ar' => $validatedData['ar'],
'nyitva' => $validatedData['nyitva'],
'utvonal' => $validatedData['utvonal'],
'szel_koord' => $szelesseg,
'hossz_koord' => $hosszusag
]);
return response() -> json([
'message' => 'Sikeres rögzítés',
'data' => $mosdo
], 201);
} catch (\Exception $e) {
return response() -> json([
'message' => 'Hiba történt a mentés során',
'error' => $e -> getMessage()
], 500);
}
}
/**
* Display the specified resource.
*/
public function show(string $id)
{
//
}
/**
* Update the specified resource in storage.
*/
public function update(Request $request, string $id)
{
//
}
/**
* Remove the specified resource from storage.
*/
public function destroy(string $id)
{
//
}
}

View File

@@ -0,0 +1,76 @@
<?php
namespace App\Http\Controllers;
use App\Models\User;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Hash;
class UserController extends Controller
{
/**
* Display a listing of the resource.
*/
public function index()
{
//
}
/**
* Store a newly created resource in storage.
*/
public function store(Request $request)
{
$validatedData = $request->validate([
'nev' => 'required|string',
'email' => 'required|email|unique:felhasznalok',
'felh_nev' => 'required|string|unique:felhasznalok',
'jelszo' => 'required|string|min:6',
'is_admin' => 'boolean'
]);
try {
$felhasznalo = User::create([
'nev' => $validatedData['nev'],
'email' => $validatedData['email'],
'felh_nev' => $validatedData['felh_nev'],
'jelszo' => $validatedData['jelszo'], // Will be hashed by mutator
'is_admin' => $validatedData['is_admin'] ?? false
]);
return response()->json([
'message' => 'Sikeres rögzítés',
'data' => $felhasznalo
], 201);
} catch (\Exception $e) {
return response()->json([
'message' => 'Hiba történt a mentés során',
'error' => $e->getMessage()
], 500);
}
}
/**
* Display the specified resource.
*/
public function show(string $id)
{
//
}
/**
* Update the specified resource in storage.
*/
public function update(Request $request, string $id)
{
//
}
/**
* Remove the specified resource from storage.
*/
public function destroy(string $id)
{
//
}
}

View File

@@ -0,0 +1,97 @@
<?php
namespace App\Http\Controllers;
use App\Models\WcAdatok;
use Illuminate\Http\Request;
class WcController extends Controller
{
public function index()
{
$mosdok = WcAdatok::with('kerulet')->get();
return response()->json($mosdok);
}
public function store(Request $request)
{
$validatedData = $request->validate([
'nev' => 'required|string',
'kerulet_id' => 'required|integer|exists:keruletek,id',
'kozeli_megall' => 'required|string',
'akadalym' => 'nullable|boolean',
'ar' => 'nullable|numeric',
'nyitva' => 'nullable|string',
'utvonal' => 'required|string',
'koordinatak' => 'required|string',
'felhasznalo_id' => 'nullable|numeric'
]);
try {
$szelesseg = null;
$hosszusag = null;
if (!empty($validatedData['koordinatak'])) {
$koordinatak = explode(',', $validatedData['koordinatak']);
if (count($koordinatak) == 2) {
$hosszusag = trim($koordinatak[0]);
$szelesseg = trim($koordinatak[1]);
if (!is_numeric($szelesseg) || !is_numeric($hosszusag)) {
return response()->json([
'message' => 'Érvénytelen a koordináták formátuma'
], 422);
}
}
}
$mosdo = WcAdatok::create([
'nev' => $validatedData['nev'],
'kerulet_id' => $validatedData['kerulet_id'],
'kozeli_megall' => $validatedData['kozeli_megall'],
'akadalym' => $validatedData['akadalym'],
'ar' => $validatedData['ar'],
'nyitva' => $validatedData['nyitva'],
'utvonal' => $validatedData['utvonal'],
'szel_koord' => $szelesseg,
'hossz_koord' => $hosszusag,
'felhasznalo_id' => $validatedData['felhasznalo_id'] ?? null
]);
return response()->json([
'message' => 'Sikeres rögzítés',
'data' => $mosdo
], 201);
} catch (\Exception $e) {
return response()->json([
'message' => 'Hiba történt a mentés során',
'error' => $e->getMessage()
], 500);
}
}
public function show($id)
{
$wc = WcAdatok::find($id);
if (!$wc) {
return response()->json(['message' => 'Nem található'], 404);
}
return response()->json($wc);
}
public function destroy($id)
{
$mosdo = WcAdatok::find($id);
if($mosdo){
$mosdo -> delete();
return response() -> json(['message' => 'Sikeres törlés'], 200);
} else {
return response() -> json(['message' => 'Nem található'], 404);
}
}
}

View File

@@ -0,0 +1,67 @@
<?php
namespace App\Http;
use Illuminate\Foundation\Http\Kernel as HttpKernel;
class Kernel extends HttpKernel
{
/**
* The application's global HTTP middleware stack.
*
* These middleware are run during every request to your application.
*
* @var array<int, class-string|string>
*/
protected $middleware = [
// \App\Http\Middleware\TrustHosts::class,
\App\Http\Middleware\TrustProxies::class,
\Fruitcake\Cors\HandleCors::class,
\App\Http\Middleware\PreventRequestsDuringMaintenance::class,
\Illuminate\Foundation\Http\Middleware\ValidatePostSize::class,
\App\Http\Middleware\TrimStrings::class,
\Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull::class,
];
/**
* The application's route middleware groups.
*
* @var array<string, array<int, class-string|string>>
*/
protected $middlewareGroups = [
'web' => [
\App\Http\Middleware\EncryptCookies::class,
\Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
\Illuminate\Session\Middleware\StartSession::class,
// \Illuminate\Session\Middleware\AuthenticateSession::class,
\Illuminate\View\Middleware\ShareErrorsFromSession::class,
\App\Http\Middleware\VerifyCsrfToken::class,
\Illuminate\Routing\Middleware\SubstituteBindings::class,
],
'api' => [
// \Laravel\Sanctum\Http\Middleware\EnsureFrontendRequestsAreStateful::class,
'throttle:api',
\Illuminate\Routing\Middleware\SubstituteBindings::class,
],
];
/**
* The application's route middleware.
*
* These middleware may be assigned to groups or used individually.
*
* @var array<string, class-string|string>
*/
protected $routeMiddleware = [
'auth' => \App\Http\Middleware\Authenticate::class,
'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
'cache.headers' => \Illuminate\Http\Middleware\SetCacheHeaders::class,
'can' => \Illuminate\Auth\Middleware\Authorize::class,
'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class,
'password.confirm' => \Illuminate\Auth\Middleware\RequirePassword::class,
'signed' => \Illuminate\Routing\Middleware\ValidateSignature::class,
'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
'verified' => \Illuminate\Auth\Middleware\EnsureEmailIsVerified::class,
];
}

View File

@@ -0,0 +1,21 @@
<?php
namespace App\Http\Middleware;
use Illuminate\Auth\Middleware\Authenticate as Middleware;
class Authenticate extends Middleware
{
/**
* Get the path the user should be redirected to when they are not authenticated.
*
* @param \Illuminate\Http\Request $request
* @return string|null
*/
protected function redirectTo($request)
{
if (! $request->expectsJson()) {
return route('login');
}
}
}

View File

@@ -0,0 +1,20 @@
<?php
namespace App\Http\Middleware;
use Closure;
use Illuminate\Http\Request;
class Cors
{
public function handle(Request $request, Closure $next)
{
$response = $next($request);
$response->headers->set('Access-Control-Allow-Origin', '*');
$response->headers->set('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE, OPTIONS');
$response->headers->set('Access-Control-Allow-Headers', 'Content-Type, Authorization, X-Requested-With');
return $response;
}
}

View File

@@ -0,0 +1,17 @@
<?php
namespace App\Http\Middleware;
use Illuminate\Cookie\Middleware\EncryptCookies as Middleware;
class EncryptCookies extends Middleware
{
/**
* The names of the cookies that should not be encrypted.
*
* @var array<int, string>
*/
protected $except = [
//
];
}

View File

@@ -0,0 +1,17 @@
<?php
namespace App\Http\Middleware;
use Illuminate\Foundation\Http\Middleware\PreventRequestsDuringMaintenance as Middleware;
class PreventRequestsDuringMaintenance extends Middleware
{
/**
* The URIs that should be reachable while maintenance mode is enabled.
*
* @var array<int, string>
*/
protected $except = [
//
];
}

View File

@@ -0,0 +1,32 @@
<?php
namespace App\Http\Middleware;
use App\Providers\RouteServiceProvider;
use Closure;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
class RedirectIfAuthenticated
{
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure(\Illuminate\Http\Request): (\Illuminate\Http\Response|\Illuminate\Http\RedirectResponse) $next
* @param string|null ...$guards
* @return \Illuminate\Http\Response|\Illuminate\Http\RedirectResponse
*/
public function handle(Request $request, Closure $next, ...$guards)
{
$guards = empty($guards) ? [null] : $guards;
foreach ($guards as $guard) {
if (Auth::guard($guard)->check()) {
return redirect(RouteServiceProvider::HOME);
}
}
return $next($request);
}
}

View File

@@ -0,0 +1,19 @@
<?php
namespace App\Http\Middleware;
use Illuminate\Foundation\Http\Middleware\TrimStrings as Middleware;
class TrimStrings extends Middleware
{
/**
* The names of the attributes that should not be trimmed.
*
* @var array<int, string>
*/
protected $except = [
'current_password',
'password',
'password_confirmation',
];
}

View File

@@ -0,0 +1,20 @@
<?php
namespace App\Http\Middleware;
use Illuminate\Http\Middleware\TrustHosts as Middleware;
class TrustHosts extends Middleware
{
/**
* Get the host patterns that should be trusted.
*
* @return array<int, string|null>
*/
public function hosts()
{
return [
$this->allSubdomainsOfApplicationUrl(),
];
}
}

View File

@@ -0,0 +1,28 @@
<?php
namespace App\Http\Middleware;
use Illuminate\Http\Middleware\TrustProxies as Middleware;
use Illuminate\Http\Request;
class TrustProxies extends Middleware
{
/**
* The trusted proxies for this application.
*
* @var array<int, string>|string|null
*/
protected $proxies;
/**
* The headers that should be used to detect proxies.
*
* @var int
*/
protected $headers =
Request::HEADER_X_FORWARDED_FOR |
Request::HEADER_X_FORWARDED_HOST |
Request::HEADER_X_FORWARDED_PORT |
Request::HEADER_X_FORWARDED_PROTO |
Request::HEADER_X_FORWARDED_AWS_ELB;
}

View File

@@ -0,0 +1,17 @@
<?php
namespace App\Http\Middleware;
use Illuminate\Foundation\Http\Middleware\VerifyCsrfToken as Middleware;
class VerifyCsrfToken extends Middleware
{
/**
* The URIs that should be excluded from CSRF verification.
*
* @var array<int, string>
*/
protected $except = [
//
];
}

View File

@@ -0,0 +1,14 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class Keruletek extends Model
{
public function wcAdatok(){
return $this->hasMany(WcAdatok::class);
}
protected $table = 'keruletek';
}

View File

@@ -0,0 +1,57 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Laravel\Sanctum\HasApiTokens;
use Tymon\JWTAuth\Contracts\JWTSubject;
class User extends Authenticatable implements JWTSubject
{
use HasApiTokens, HasFactory, Notifiable;
public function getJWTIdentifier()
{
return $this->getKey();
}
public function getJWTCustomClaims()
{
return [];
}
// Change to match your migration
protected $table = 'felhasznalok';
protected $fillable = [
'nev',
'email',
'felh_nev',
'jelszo',
'is_admin',
];
protected $hidden = [
'jelszo',
'remember_token'
];
protected $casts = [
'is_admin' => 'boolean',
'email_verified_at' => 'datetime',
];
// This method tells Laravel to use jelszo field for passwords
public function getAuthPassword()
{
return $this->jelszo;
}
// Fix this to use 'jelszo' instead of 'password'
public function setJelszoAttribute($value)
{
$this->attributes['jelszo'] = \Illuminate\Support\Facades\Hash::make($value);
}
}

View File

@@ -0,0 +1,36 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class WcAdatok extends Model
{
use HasFactory;
public function kerulet(){
return $this->belongsTo(Keruletek::class);
}
public function felhasznalo(){
return $this->belongsTo(User::class);
}
protected $table = 'wc_adatok';
protected $fillable = [
'id',
'nev',
'kerulet_id',
'kozeli_megall',
'akadalym',
'ar',
'nyitva',
'hossz_koord',
'szel_koord',
'utvonal',
'felhasznalo_id'
];
}

View File

@@ -0,0 +1,28 @@
<?php
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
class AppServiceProvider extends ServiceProvider
{
/**
* Register any application services.
*
* @return void
*/
public function register()
{
//
}
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{
//
}
}

View File

@@ -0,0 +1,30 @@
<?php
namespace App\Providers;
use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider;
use Illuminate\Support\Facades\Gate;
class AuthServiceProvider extends ServiceProvider
{
/**
* The policy mappings for the application.
*
* @var array<class-string, class-string>
*/
protected $policies = [
// 'App\Models\Model' => 'App\Policies\ModelPolicy',
];
/**
* Register any authentication / authorization services.
*
* @return void
*/
public function boot()
{
$this->registerPolicies();
//
}
}

View File

@@ -0,0 +1,21 @@
<?php
namespace App\Providers;
use Illuminate\Support\Facades\Broadcast;
use Illuminate\Support\ServiceProvider;
class BroadcastServiceProvider extends ServiceProvider
{
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{
Broadcast::routes();
require base_path('routes/channels.php');
}
}

View File

@@ -0,0 +1,32 @@
<?php
namespace App\Providers;
use Illuminate\Auth\Events\Registered;
use Illuminate\Auth\Listeners\SendEmailVerificationNotification;
use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;
use Illuminate\Support\Facades\Event;
class EventServiceProvider extends ServiceProvider
{
/**
* The event listener mappings for the application.
*
* @var array<class-string, array<int, class-string>>
*/
protected $listen = [
Registered::class => [
SendEmailVerificationNotification::class,
],
];
/**
* Register any events for your application.
*
* @return void
*/
public function boot()
{
//
}
}

View File

@@ -0,0 +1,63 @@
<?php
namespace App\Providers;
use Illuminate\Cache\RateLimiting\Limit;
use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\RateLimiter;
use Illuminate\Support\Facades\Route;
class RouteServiceProvider extends ServiceProvider
{
/**
* The path to the "home" route for your application.
*
* This is used by Laravel authentication to redirect users after login.
*
* @var string
*/
public const HOME = '/home';
/**
* The controller namespace for the application.
*
* When present, controller route declarations will automatically be prefixed with this namespace.
*
* @var string|null
*/
// protected $namespace = 'App\\Http\\Controllers';
/**
* Define your route model bindings, pattern filters, etc.
*
* @return void
*/
public function boot()
{
$this->configureRateLimiting();
$this->routes(function () {
Route::prefix('api')
->middleware('api')
->namespace($this->namespace)
->group(base_path('routes/api.php'));
Route::middleware('web')
->namespace($this->namespace)
->group(base_path('routes/web.php'));
});
}
/**
* Configure the rate limiters for the application.
*
* @return void
*/
protected function configureRateLimiting()
{
RateLimiter::for('api', function (Request $request) {
return Limit::perMinute(60)->by($request->user()?->id ?: $request->ip());
});
}
}