This commit is contained in:
Sándor Máté Magony
2025-05-11 13:07:54 +02:00
parent ec057787fd
commit a85c207b44
13 changed files with 25 additions and 169 deletions

View File

@@ -35,7 +35,7 @@ class AuthController extends Controller
'nev' => $request->nev, 'nev' => $request->nev,
'email' => $request->email, 'email' => $request->email,
'felh_nev' => $request->felh_nev, 'felh_nev' => $request->felh_nev,
'jelszo' => $request->jelszo, // This will be hashed via the mutator 'jelszo' => $request->jelszo,
'is_admin' => $request->is_admin ?? false 'is_admin' => $request->is_admin ?? false
]); ]);
@@ -56,10 +56,9 @@ class AuthController extends Controller
return response()->json($validator->errors(), 422); return response()->json($validator->errors(), 422);
} }
// Since your login fields are custom, you need to specify the fields
$credentials = [ $credentials = [
'felh_nev' => $request->felh_nev, 'felh_nev' => $request->felh_nev,
'password' => $request->jelszo // Laravel expects 'password' internally 'password' => $request->jelszo
]; ];
if (!$token = auth('api')->attempt($credentials)) { if (!$token = auth('api')->attempt($credentials)) {
@@ -96,7 +95,7 @@ class AuthController extends Controller
return response()->json([ return response()->json([
'access_token' => $token, 'access_token' => $token,
'token_type' => 'bearer', 'token_type' => 'bearer',
'expires_in' => config('jwt.ttl') * 60, // Getting TTL from config 'expires_in' => config('jwt.ttl') * 60,
'user' => auth('api')->user() 'user' => auth('api')->user()
]); ]);
} }

View File

@@ -1,100 +0,0 @@
<?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

@@ -8,17 +8,6 @@ use Illuminate\Support\Facades\Hash;
class UserController extends Controller 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) public function store(Request $request)
{ {
$validatedData = $request->validate([ $validatedData = $request->validate([
@@ -34,7 +23,7 @@ class UserController extends Controller
'nev' => $validatedData['nev'], 'nev' => $validatedData['nev'],
'email' => $validatedData['email'], 'email' => $validatedData['email'],
'felh_nev' => $validatedData['felh_nev'], 'felh_nev' => $validatedData['felh_nev'],
'jelszo' => $validatedData['jelszo'], // Will be hashed by mutator 'jelszo' => $validatedData['jelszo'],
'is_admin' => $validatedData['is_admin'] ?? false 'is_admin' => $validatedData['is_admin'] ?? false
]); ]);
@@ -49,28 +38,4 @@ class UserController extends Controller
], 500); ], 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

@@ -104,6 +104,4 @@ class WcController extends Controller
return response()->json(['message' => 'Nem található'], 404); return response()->json(['message' => 'Nem található'], 404);
} }
} }
} }

View File

@@ -22,7 +22,6 @@ class User extends Authenticatable implements JWTSubject
return []; return [];
} }
// Change to match your migration
protected $table = 'felhasznalok'; protected $table = 'felhasznalok';
protected $fillable = [ protected $fillable = [
@@ -43,13 +42,11 @@ class User extends Authenticatable implements JWTSubject
'email_verified_at' => 'datetime', 'email_verified_at' => 'datetime',
]; ];
// This method tells Laravel to use jelszo field for passwords
public function getAuthPassword() public function getAuthPassword()
{ {
return $this->jelszo; return $this->jelszo;
} }
// Fix this to use 'jelszo' instead of 'password'
public function setJelszoAttribute($value) public function setJelszoAttribute($value)
{ {
$this->attributes['jelszo'] = \Illuminate\Support\Facades\Hash::make($value); $this->attributes['jelszo'] = \Illuminate\Support\Facades\Hash::make($value);

View File

@@ -6,9 +6,6 @@ use Illuminate\Support\Facades\Schema;
return new class extends Migration return new class extends Migration
{ {
/**
* Run the migrations.
*/
public function up(): void public function up(): void
{ {
Schema::create('keruletek', function (Blueprint $t) { Schema::create('keruletek', function (Blueprint $t) {
@@ -42,11 +39,10 @@ return new class extends Migration
}); });
} }
/**
* Reverse the migrations.
*/
public function down(): void public function down(): void
{ {
// Schema::dropIfExists('keruletek');
Schema::dropIfExists('felhasznalok');
Schema::dropIfExists('wc_adatok');
} }
}; };

View File

@@ -8,9 +8,6 @@ use Illuminate\Database\Seeder;
class DatabaseSeeder extends Seeder class DatabaseSeeder extends Seeder
{ {
/**
* Seed the application's database.
*/
public function run(): void public function run(): void
{ {
$this -> call([ $this -> call([

View File

@@ -14,14 +14,22 @@ class FelhasznaloFeltoltes extends Seeder
*/ */
public function run(): void public function run(): void
{ {
DB::table('felhasznalok')->insert([ DB::table('felhasznalok')->insert([[
'nev' => 'Magony Sándor', 'nev' => 'Admin',
'email' => 'magonys2006@gmail.com', 'email' => 'admin@gmail.com',
'felh_nev' => 'admin', 'felh_nev' => 'admin',
'jelszo' => Hash::make('admin'), 'jelszo' => Hash::make('admin'),
'is_admin' => true, 'is_admin' => true,
'created_at' => now(), 'created_at' => now(),
'updated_at' => now() 'updated_at' => now()
]); ], [
'nev' => 'Felhasználó',
'email' => 'felhasznalo@gmail.com',
'felh_nev' => 'felhaszalo',
'jelszo' => Hash::make('felhasznalo'),
'is_admin' => false,
'created_at' => now(),
'updated_at' => now()
]]);
} }
} }

View File

@@ -1,5 +1,5 @@
import { useState } from 'react'; import { useState } from 'react';
import { useAuth } from './AuthContext'; // Update this path import { useAuth } from './AuthContext';
import { useNavigate } from 'react-router-dom'; import { useNavigate } from 'react-router-dom';
export default function Regisztracio() { export default function Regisztracio() {
@@ -43,9 +43,8 @@ export default function Regisztracio() {
const result = await register(formData); const result = await register(formData);
if (result.success) { if (result.success) {
navigate('/bejelentkezes'); // Navigate to login page after successful registration navigate('/bejelentkezes');
} else if (result.errors) { } else if (result.errors) {
// Format Laravel validation errors
const serverErrors = {}; const serverErrors = {};
for (const key in result.errors) { for (const key in result.errors) {
if (Array.isArray(result.errors[key])) { if (Array.isArray(result.errors[key])) {

View File

@@ -34,7 +34,6 @@ export default function Csempe() {
}) })
.then(response => { .then(response => {
if (response.ok) { if (response.ok) {
// Sikeres törlés után szűrd ki az adott elemet a state-ből
setMosdok(prev => prev.filter(m => m.id !== mosdoId)); setMosdok(prev => prev.filter(m => m.id !== mosdoId));
} else { } else {
console.error("Törlés sikertelen"); console.error("Törlés sikertelen");

View File

@@ -29,7 +29,7 @@ describe('Csempe komponens', () => {
]; ];
beforeEach(() => { beforeEach(() => {
fetch.resetMocks?.(); // ha használsz jest-fetch-mock-ot fetch.resetMocks?.();
jest.clearAllMocks(); jest.clearAllMocks();
}); });
@@ -68,9 +68,9 @@ describe('Csempe komponens', () => {
test('Betöltés alatt megjelenik spinner', async () => { test('Betöltés alatt megjelenik spinner', async () => {
useAuth.mockReturnValue({ user: { is_admin: true } }); useAuth.mockReturnValue({ user: { is_admin: true } });
fetchModule.mosdokFetch.mockImplementation(() => new Promise(() => {})); // never resolves fetchModule.mosdokFetch.mockImplementation(() => new Promise(() => {}));
render(<Csempe />); render(<Csempe />);
expect(screen.getByRole('status')).toBeInTheDocument(); // a spinner div-ben legyen pl. role="status" expect(screen.getByRole('status')).toBeInTheDocument();
}); });
}); });

View File

@@ -17,7 +17,6 @@ export default function HozzaadForm() {
const handleSubmit = async (event) => { const handleSubmit = async (event) => {
event.preventDefault(); event.preventDefault();
// Validáció: egyszerű kötelező mező ellenőrzések
const newErrors = {}; const newErrors = {};
if (!nev.trim()) newErrors.nev = "A név megadása kötelező."; if (!nev.trim()) newErrors.nev = "A név megadása kötelező.";
if (!kerulet_id) newErrors.kerulet_id = "Kerület kiválasztása kötelező."; if (!kerulet_id) newErrors.kerulet_id = "Kerület kiválasztása kötelező.";

View File

@@ -2,11 +2,10 @@ import React, { useState } from 'react';
import { TfiWheelchair } from "react-icons/tfi"; import { TfiWheelchair } from "react-icons/tfi";
import { mosdokFetch } from '../../apiFetch'; import { mosdokFetch } from '../../apiFetch';
// Egyszerű koordináta-alapú távolság (nincs konverzió km-re)
const calculateDistance = (lat1, lon1, lat2, lon2) => { const calculateDistance = (lat1, lon1, lat2, lon2) => {
const dx = lat1 - lat2; const dx = lat1 - lat2;
const dy = lon1 - lon2; const dy = lon1 - lon2;
return dx * dx + dy * dy; // távolság négyzete (nem baj, hogy nincs gyök alatt) return dx * dx + dy * dy;
}; };
export default function LegkozelebbiMosdo() { export default function LegkozelebbiMosdo() {