-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Nova estructura, modificacions al enrutador, linting (laravel pint) + exemple complet CRUD.
- Loading branch information
Showing
76 changed files
with
1,718 additions
and
681 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,10 +3,10 @@ INSERT INTO roles (name) VALUES | |
('Administrador'), | ||
('Gerente'), | ||
('Trabajador'); | ||
INSERT INTO workers (company, name, dni, password, email, role_id, created_at, updated_at, deleted_at) VALUES | ||
('TechCorp', 'Carlos García', '12345678A', 'hashedpassword1', '[email protected]', 1, NOW(), NOW(), NULL), | ||
('InnovaTech', 'Ana Martínez', '23456789B', 'hashedpassword2', '[email protected]', 2, NOW(), NOW(), NULL), | ||
('DesignWorks', 'José Rodríguez', '34567890C', 'hashedpassword3', '[email protected]', 3, NOW(), NOW(), NULL); | ||
INSERT INTO workers (company, name, dni, password, email, role_id) VALUES | ||
('TechCorp', 'Carlos García', '12345678A', 'hashedpassword1', '[email protected]', 1), | ||
('InnovaTech', 'Ana Martínez', '23456789B', 'hashedpassword2', '[email protected]', 2), | ||
('DesignWorks', 'José Rodríguez', '34567890C', 'hashedpassword3', '[email protected]', 3); | ||
INSERT INTO contracts (name, start_date, end_date, invoice_proposed, invoice_agreed, invoice_paid) VALUES | ||
('Ayuntamiento de Valencia', '2021-01-01', '2021-12-31', 1000.00, 900.00, 900.00), | ||
('Administración General del Estado', '2021-01-01', '2021-12-31', 2000.00, 1800.00, 1800.00), | ||
|
@@ -50,7 +50,7 @@ INSERT INTO incidences (name, element_id, description) VALUES | |
('Banco pintado', 2, 'Banco pintado con grafitis'), | ||
('Fuente con fuga', 3, 'Fuente con fuga de agua'); | ||
--TODO: tasks, routes and works | ||
INSERT INTO work_orders (contract_id) VALUES | ||
INSERT INTO work_orders (contract_id) VALUES | ||
(1), | ||
(2), | ||
(3); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
<?php | ||
|
||
namespace App\Controllers; | ||
|
||
use App\Core\Session; | ||
use App\Core\View; | ||
use App\Models\User; | ||
|
||
class AuthController | ||
{ | ||
public function index() | ||
{ | ||
View::render([ | ||
'view' => 'Auth/Login', | ||
'title' => 'Login Page', | ||
'layout' => 'AuthLayout', | ||
'data' => [ | ||
'error' => Session::get('error'), | ||
], | ||
]); | ||
|
||
// Clear the error message after displaying it | ||
Session::remove('error'); | ||
} | ||
|
||
public function login($postData) | ||
{ | ||
$email = $postData['email'] ?? null; | ||
$password = $postData['password'] ?? null; | ||
|
||
if (! $email || ! $password) { | ||
// Redirect back with error if fields are missing | ||
Session::set('error', 'Email and password are required.'); | ||
header('Location: /auth/login'); | ||
exit; | ||
} | ||
|
||
// Check if the user exists and password matches | ||
$user = User::findBy(['email' => $email, 'password' => $password], true); | ||
|
||
if (! $user || strcmp($user->password, $password) !== 0) { // TODO: Verify hashed password not raw password | ||
echo 'Invalid email or password.'; | ||
// Redirect back with error if authentication fails | ||
Session::set('error', 'Invalid email or password.'); | ||
header('Location: /auth/login'); | ||
exit; | ||
} | ||
|
||
Session::set('user', [ | ||
'id' => $user->getId(), | ||
'name' => $user->name, | ||
'email' => $user->email, | ||
'role_id' => $user->role_id, | ||
]); | ||
|
||
header('Location: /'); | ||
exit; | ||
} | ||
|
||
public function logout() | ||
{ | ||
Session::destroy(); | ||
header('Location: /auth/login'); | ||
exit; | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
|
||
namespace App\Controllers; | ||
|
||
use App\Core\View; | ||
use App\Models\Contract; | ||
|
||
class ContractController | ||
{ | ||
public function index() | ||
{ | ||
$contracts = Contract::findAll(); | ||
View::render([ | ||
'view' => 'Contracts', | ||
'title' => 'Contracts', | ||
'layout' => 'MainLayout', | ||
'data' => ['contracts' => $contracts], | ||
]); | ||
} | ||
} |
Oops, something went wrong.