- 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
154 lines
3.8 KiB
PHP
154 lines
3.8 KiB
PHP
<?php
|
|
|
|
namespace App\Modules\Auth;
|
|
|
|
use App\Core\Controller as BaseController;
|
|
|
|
/**
|
|
* Auth Controller
|
|
* Handles authentication
|
|
*/
|
|
class Controller extends BaseController
|
|
{
|
|
/**
|
|
* Show login form
|
|
*/
|
|
public function showLogin()
|
|
{
|
|
return $this->view('Auth.view.login', [
|
|
'title' => 'Login - Woles Framework'
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* Handle login
|
|
*/
|
|
public function login()
|
|
{
|
|
$data = $this->request()->all();
|
|
|
|
// Basic validation
|
|
$errors = $this->validate($data, [
|
|
'email' => 'required|email',
|
|
'password' => 'required|min:6'
|
|
]);
|
|
|
|
if (!empty($errors)) {
|
|
if ($this->request()->expectsJson()) {
|
|
return $this->error('Validation failed', 422);
|
|
}
|
|
|
|
return $this->view('Auth.view.login', [
|
|
'title' => 'Login - NovaCore Framework',
|
|
'errors' => $errors,
|
|
'old' => $data
|
|
]);
|
|
}
|
|
|
|
// Simple authentication (in production, use proper user model)
|
|
if ($data['email'] === 'admin@novacore.dev' && $data['password'] === 'password123') {
|
|
$_SESSION['auth'] = true;
|
|
$_SESSION['user'] = [
|
|
'id' => 1,
|
|
'email' => $data['email'],
|
|
'name' => 'Administrator'
|
|
];
|
|
|
|
if ($this->request()->expectsJson()) {
|
|
return $this->success(['user' => $_SESSION['user']], 'Login successful');
|
|
}
|
|
|
|
return $this->redirect('/dashboard');
|
|
}
|
|
|
|
if ($this->request()->expectsJson()) {
|
|
return $this->error('Invalid credentials', 401);
|
|
}
|
|
|
|
return $this->view('Auth.view.login', [
|
|
'title' => 'Login - NovaCore Framework',
|
|
'error' => 'Invalid email or password',
|
|
'old' => $data
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* Handle logout
|
|
*/
|
|
public function logout()
|
|
{
|
|
session_destroy();
|
|
|
|
if ($this->request()->expectsJson()) {
|
|
return $this->success([], 'Logout successful');
|
|
}
|
|
|
|
return $this->redirect('/login');
|
|
}
|
|
|
|
/**
|
|
* Show registration form
|
|
*/
|
|
public function showRegister()
|
|
{
|
|
return $this->view('Auth.view.register', [
|
|
'title' => 'Register - NovaCore Framework'
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* Handle registration
|
|
*/
|
|
public function register()
|
|
{
|
|
$data = $this->request()->all();
|
|
|
|
// Basic validation
|
|
$errors = $this->validate($data, [
|
|
'name' => 'required|min:2',
|
|
'email' => 'required|email',
|
|
'password' => 'required|min:6',
|
|
'password_confirmation' => 'required'
|
|
]);
|
|
|
|
if ($data['password'] !== $data['password_confirmation']) {
|
|
$errors['password_confirmation'] = 'Password confirmation does not match.';
|
|
}
|
|
|
|
if (!empty($errors)) {
|
|
if ($this->request()->expectsJson()) {
|
|
return $this->error('Validation failed', 422);
|
|
}
|
|
|
|
return $this->view('Auth.view.register', [
|
|
'title' => 'Register - NovaCore Framework',
|
|
'errors' => $errors,
|
|
'old' => $data
|
|
]);
|
|
}
|
|
|
|
// In production, save to database
|
|
// For now, just redirect to login
|
|
if ($this->request()->expectsJson()) {
|
|
return $this->success([], 'Registration successful');
|
|
}
|
|
|
|
return $this->redirect('/login');
|
|
}
|
|
|
|
/**
|
|
* Show dashboard
|
|
*/
|
|
public function dashboard()
|
|
{
|
|
if (!isset($_SESSION['auth']) || !$_SESSION['auth']) {
|
|
return $this->redirect('/login');
|
|
}
|
|
|
|
return $this->view('Auth.view.dashboard', [
|
|
'title' => 'Dashboard - NovaCore Framework',
|
|
'user' => $_SESSION['user']
|
|
]);
|
|
}
|
|
}
|