feat: Complete Woles Framework v1.0 with enterprise-grade UI
- Add comprehensive error handling system with custom error pages - Implement professional enterprise-style design with Tailwind CSS - Create modular HMVC architecture with clean separation of concerns - Add security features: CSRF protection, XSS filtering, Argon2ID hashing - Include CLI tools for development workflow - Add error reporting dashboard with system monitoring - Implement responsive design with consistent slate color scheme - Replace all emoji icons with professional SVG icons - Add comprehensive test suite with PHPUnit - Include database migrations and seeders - Add proper exception handling with fallback pages - Implement template engine with custom syntax support - Add helper functions and facades for clean code - Include proper logging and debugging capabilities
This commit is contained in:
219
app/Modules/User/Controller.php
Normal file
219
app/Modules/User/Controller.php
Normal file
@@ -0,0 +1,219 @@
|
||||
<?php
|
||||
|
||||
namespace App\Modules\User;
|
||||
|
||||
use App\Core\Controller as BaseController;
|
||||
|
||||
/**
|
||||
* User Controller
|
||||
* Handles user management
|
||||
*/
|
||||
class Controller extends BaseController
|
||||
{
|
||||
private Model $model;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->model = new Model();
|
||||
}
|
||||
|
||||
/**
|
||||
* List all users
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$users = $this->model->all();
|
||||
|
||||
if ($this->request()->expectsJson()) {
|
||||
return $this->json($users);
|
||||
}
|
||||
|
||||
return $this->view('User.view.index', [
|
||||
'title' => 'Users - NovaCore Framework',
|
||||
'users' => $users
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Show user details
|
||||
*/
|
||||
public function show(int $id)
|
||||
{
|
||||
$user = $this->model->findById($id);
|
||||
|
||||
if (!$user) {
|
||||
if ($this->request()->expectsJson()) {
|
||||
return $this->error('User not found', 404);
|
||||
}
|
||||
|
||||
http_response_code(404);
|
||||
echo "<h1>404 - User Not Found</h1>";
|
||||
return;
|
||||
}
|
||||
|
||||
if ($this->request()->expectsJson()) {
|
||||
return $this->json($user);
|
||||
}
|
||||
|
||||
return $this->view('User.view.show', [
|
||||
'title' => 'User Details - NovaCore Framework',
|
||||
'user' => $user
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Show create user form
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
return $this->view('User.view.create', [
|
||||
'title' => 'Create User - NovaCore Framework'
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Store new user
|
||||
*/
|
||||
public function store()
|
||||
{
|
||||
$data = $this->request()->all();
|
||||
|
||||
// Validation
|
||||
$errors = $this->validate($data, [
|
||||
'name' => 'required|min:2',
|
||||
'email' => 'required|email',
|
||||
'password' => 'required|min:6'
|
||||
]);
|
||||
|
||||
// Check if email exists
|
||||
if (empty($errors) && $this->model->emailExists($data['email'])) {
|
||||
$errors['email'] = 'Email already exists.';
|
||||
}
|
||||
|
||||
if (!empty($errors)) {
|
||||
if ($this->request()->expectsJson()) {
|
||||
return $this->error('Validation failed', 422);
|
||||
}
|
||||
|
||||
return $this->view('User.view.create', [
|
||||
'title' => 'Create User - NovaCore Framework',
|
||||
'errors' => $errors,
|
||||
'old' => $data
|
||||
]);
|
||||
}
|
||||
|
||||
// Create user
|
||||
$userId = $this->model->create($data);
|
||||
|
||||
if ($this->request()->expectsJson()) {
|
||||
return $this->success(['id' => $userId], 'User created successfully');
|
||||
}
|
||||
|
||||
return $this->redirect('/users');
|
||||
}
|
||||
|
||||
/**
|
||||
* Show edit user form
|
||||
*/
|
||||
public function edit(int $id)
|
||||
{
|
||||
$user = $this->model->findById($id);
|
||||
|
||||
if (!$user) {
|
||||
http_response_code(404);
|
||||
echo "<h1>404 - User Not Found</h1>";
|
||||
return;
|
||||
}
|
||||
|
||||
return $this->view('User.view.edit', [
|
||||
'title' => 'Edit User - NovaCore Framework',
|
||||
'user' => $user
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update user
|
||||
*/
|
||||
public function update(int $id)
|
||||
{
|
||||
$user = $this->model->findById($id);
|
||||
|
||||
if (!$user) {
|
||||
if ($this->request()->expectsJson()) {
|
||||
return $this->error('User not found', 404);
|
||||
}
|
||||
|
||||
http_response_code(404);
|
||||
echo "<h1>404 - User Not Found</h1>";
|
||||
return;
|
||||
}
|
||||
|
||||
$data = $this->request()->all();
|
||||
|
||||
// Validation
|
||||
$errors = $this->validate($data, [
|
||||
'name' => 'required|min:2',
|
||||
'email' => 'required|email'
|
||||
]);
|
||||
|
||||
// Check if email exists (excluding current user)
|
||||
if (empty($errors) && $this->model->emailExists($data['email'], $id)) {
|
||||
$errors['email'] = 'Email already exists.';
|
||||
}
|
||||
|
||||
if (!empty($errors)) {
|
||||
if ($this->request()->expectsJson()) {
|
||||
return $this->error('Validation failed', 422);
|
||||
}
|
||||
|
||||
return $this->view('User.view.edit', [
|
||||
'title' => 'Edit User - NovaCore Framework',
|
||||
'user' => array_merge($user, $data),
|
||||
'errors' => $errors
|
||||
]);
|
||||
}
|
||||
|
||||
// Remove password if empty
|
||||
if (empty($data['password'])) {
|
||||
unset($data['password']);
|
||||
} else {
|
||||
$data['password'] = password_hash($data['password'], PASSWORD_ARGON2ID);
|
||||
}
|
||||
|
||||
// Update user
|
||||
$this->model->update($id, $data);
|
||||
|
||||
if ($this->request()->expectsJson()) {
|
||||
return $this->success([], 'User updated successfully');
|
||||
}
|
||||
|
||||
return $this->redirect('/users');
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete user
|
||||
*/
|
||||
public function destroy(int $id)
|
||||
{
|
||||
$user = $this->model->findById($id);
|
||||
|
||||
if (!$user) {
|
||||
if ($this->request()->expectsJson()) {
|
||||
return $this->error('User not found', 404);
|
||||
}
|
||||
|
||||
http_response_code(404);
|
||||
echo "<h1>404 - User Not Found</h1>";
|
||||
return;
|
||||
}
|
||||
|
||||
$this->model->delete($id);
|
||||
|
||||
if ($this->request()->expectsJson()) {
|
||||
return $this->success([], 'User deleted successfully');
|
||||
}
|
||||
|
||||
return $this->redirect('/users');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user