Compare commits
4 Commits
master
...
dynamic-si
| Author | SHA1 | Date | |
|---|---|---|---|
| 5bdc5271a0 | |||
| 7ec30b8d5e | |||
| 8b7ab9d66e | |||
| f96b7d47e0 |
35
.env.example
35
.env.example
@@ -1,4 +1,33 @@
|
|||||||
APP_HOST=127.0.0.1
|
# Flask/Quart Configuration
|
||||||
|
DEBUG=False
|
||||||
|
SECRET_KEY=your-super-secret-key-here-change-this
|
||||||
|
|
||||||
|
# Server Configuration
|
||||||
|
APP_HOST=0.0.0.0
|
||||||
APP_PORT=5000
|
APP_PORT=5000
|
||||||
DEBUG=True
|
|
||||||
SECRET_KEY=yoursecretkey
|
# MySQL Database Configuration
|
||||||
|
DB_HOST=localhost
|
||||||
|
DB_PORT=3306
|
||||||
|
DB_USER=hersel_user
|
||||||
|
DB_PASSWORD=your_secure_password_here
|
||||||
|
DB_NAME=hersel_portfolio
|
||||||
|
|
||||||
|
# Upload Configuration
|
||||||
|
UPLOAD_FOLDER=static/uploads
|
||||||
|
MAX_CONTENT_LENGTH=16777216
|
||||||
|
|
||||||
|
# Email Configuration (optional)
|
||||||
|
MAIL_SERVER=smtp.gmail.com
|
||||||
|
MAIL_PORT=587
|
||||||
|
MAIL_USE_TLS=True
|
||||||
|
MAIL_USERNAME=your-email@gmail.com
|
||||||
|
MAIL_PASSWORD=your-email-password
|
||||||
|
|
||||||
|
# Pagination
|
||||||
|
POSTS_PER_PAGE=10
|
||||||
|
PROJECTS_PER_PAGE=12
|
||||||
|
|
||||||
|
# Cache
|
||||||
|
CACHE_TYPE=simple
|
||||||
|
CACHE_DEFAULT_TIMEOUT=300
|
||||||
|
|||||||
78
app.py
78
app.py
@@ -2,10 +2,19 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
# Copyright Hersel Giannella
|
# Copyright Hersel Giannella
|
||||||
|
# Enhanced Quart Application with Database and Authentication
|
||||||
|
|
||||||
from quart import Quart, send_from_directory
|
import asyncio
|
||||||
|
from quart import Quart, send_from_directory, session, g, render_template
|
||||||
from config import config
|
from config import config
|
||||||
from routes.home import route_home
|
from models.database import init_database, db_manager
|
||||||
|
from utils.helpers import get_flash_messages
|
||||||
|
from utils.auth import get_current_user
|
||||||
|
|
||||||
|
# Import Blueprints
|
||||||
|
from routes.home import home_bp
|
||||||
|
from routes.auth import auth_bp
|
||||||
|
from routes.dashboard import dashboard_bp
|
||||||
|
|
||||||
app = Quart(
|
app = Quart(
|
||||||
__name__,
|
__name__,
|
||||||
@@ -13,7 +22,25 @@ app = Quart(
|
|||||||
static_folder="static",
|
static_folder="static",
|
||||||
)
|
)
|
||||||
|
|
||||||
# favicon.ico, sitemap.xml and robots.txt
|
# Configuration
|
||||||
|
app.config.from_object(config)
|
||||||
|
app.secret_key = config.SECRET_KEY
|
||||||
|
|
||||||
|
# Template globals
|
||||||
|
@app.template_global('get_flashed_messages')
|
||||||
|
def template_get_flashed_messages(with_categories=False):
|
||||||
|
return get_flash_messages()
|
||||||
|
|
||||||
|
# Context processor for current user
|
||||||
|
@app.before_request
|
||||||
|
async def load_current_user():
|
||||||
|
g.current_user = await get_current_user()
|
||||||
|
|
||||||
|
@app.context_processor
|
||||||
|
def inject_user():
|
||||||
|
return {'current_user': getattr(g, 'current_user', None)}
|
||||||
|
|
||||||
|
# Static files routes
|
||||||
@app.route('/favicon.ico')
|
@app.route('/favicon.ico')
|
||||||
async def favicon():
|
async def favicon():
|
||||||
return await send_from_directory(app.static_folder, 'favicon.ico')
|
return await send_from_directory(app.static_folder, 'favicon.ico')
|
||||||
@@ -26,8 +53,47 @@ async def sitemap():
|
|||||||
async def robots():
|
async def robots():
|
||||||
return await send_from_directory(app.static_folder, 'robots.txt')
|
return await send_from_directory(app.static_folder, 'robots.txt')
|
||||||
|
|
||||||
# BluePrint Routes
|
# Register Blueprints
|
||||||
app.register_blueprint(route_home)
|
app.register_blueprint(home_bp)
|
||||||
|
app.register_blueprint(auth_bp)
|
||||||
|
app.register_blueprint(dashboard_bp)
|
||||||
|
|
||||||
|
# Database initialization
|
||||||
|
@app.before_serving
|
||||||
|
async def initialize_app():
|
||||||
|
"""Initialize database and other services"""
|
||||||
|
print("🚀 Initializing Hersel.it application...")
|
||||||
|
try:
|
||||||
|
await init_database()
|
||||||
|
print("✅ Database initialized successfully")
|
||||||
|
except Exception as e:
|
||||||
|
print(f"❌ Error initializing database: {e}")
|
||||||
|
# Don't crash the app, but log the error
|
||||||
|
|
||||||
|
@app.after_serving
|
||||||
|
async def cleanup_app():
|
||||||
|
"""Cleanup resources"""
|
||||||
|
print("🔒 Shutting down Hersel.it application...")
|
||||||
|
await db_manager.close_pool()
|
||||||
|
print("✅ Application shutdown complete")
|
||||||
|
|
||||||
|
# Error handlers
|
||||||
|
@app.errorhandler(404)
|
||||||
|
async def not_found(error):
|
||||||
|
return await render_template('errors/404.html'), 404
|
||||||
|
|
||||||
|
@app.errorhandler(500)
|
||||||
|
async def internal_error(error):
|
||||||
|
return await render_template('errors/500.html'), 500
|
||||||
|
|
||||||
|
# Health check endpoint
|
||||||
|
@app.route('/health')
|
||||||
|
async def health_check():
|
||||||
|
return {'status': 'healthy', 'app': 'Hersel.it Portfolio'}
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
app.run(debug=config.DEBUG, host=config.APP_HOST, port=config.APP_PORT)
|
app.run(
|
||||||
|
debug=config.DEBUG,
|
||||||
|
host=config.APP_HOST,
|
||||||
|
port=config.APP_PORT
|
||||||
|
)
|
||||||
|
|||||||
57
config.py
57
config.py
@@ -1,17 +1,58 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
# Copyright Hersel Giannella
|
# Enhanced Configuration with Database Settings
|
||||||
|
|
||||||
from pydantic_settings import BaseSettings
|
import os
|
||||||
|
from dotenv import load_dotenv
|
||||||
|
|
||||||
class Config(BaseSettings):
|
# Load environment variables from .env file
|
||||||
APP_HOST: str = "127.0.0.1"
|
load_dotenv()
|
||||||
APP_PORT: int = 5000
|
|
||||||
DEBUG: bool = True
|
|
||||||
SECRET_KEY: str = "default_secret_key"
|
|
||||||
|
|
||||||
class Config:
|
class Config:
|
||||||
env_file = ".env"
|
# Flask/Quart Settings
|
||||||
|
DEBUG = os.getenv('DEBUG', 'False').lower() == 'true'
|
||||||
|
SECRET_KEY = os.getenv('SECRET_KEY', 'dev-secret-key-change-in-production')
|
||||||
|
|
||||||
|
# Server Settings
|
||||||
|
APP_HOST = os.getenv('APP_HOST', '0.0.0.0')
|
||||||
|
APP_PORT = int(os.getenv('APP_PORT', '5000'))
|
||||||
|
|
||||||
|
# Database Settings
|
||||||
|
DB_HOST = os.getenv('DB_HOST', 'localhost')
|
||||||
|
DB_PORT = int(os.getenv('DB_PORT', '3306'))
|
||||||
|
DB_USER = os.getenv('DB_USER', 'hersel_user')
|
||||||
|
DB_PASSWORD = os.getenv('DB_PASSWORD', 'your_password_here')
|
||||||
|
DB_NAME = os.getenv('DB_NAME', 'hersel_portfolio')
|
||||||
|
|
||||||
|
# Session Settings
|
||||||
|
SESSION_PERMANENT = False
|
||||||
|
SESSION_TYPE = 'filesystem'
|
||||||
|
PERMANENT_SESSION_LIFETIME = 60 * 60 * 24 * 7 # 7 days
|
||||||
|
|
||||||
|
# Upload Settings
|
||||||
|
UPLOAD_FOLDER = os.getenv('UPLOAD_FOLDER', 'static/uploads')
|
||||||
|
MAX_CONTENT_LENGTH = int(os.getenv('MAX_CONTENT_LENGTH', '16777216')) # 16MB
|
||||||
|
ALLOWED_EXTENSIONS = {'png', 'jpg', 'jpeg', 'gif', 'webp', 'pdf', 'txt', 'doc', 'docx'}
|
||||||
|
|
||||||
|
# Email Settings (for future use)
|
||||||
|
MAIL_SERVER = os.getenv('MAIL_SERVER', 'localhost')
|
||||||
|
MAIL_PORT = int(os.getenv('MAIL_PORT', '587'))
|
||||||
|
MAIL_USE_TLS = os.getenv('MAIL_USE_TLS', 'True').lower() == 'true'
|
||||||
|
MAIL_USERNAME = os.getenv('MAIL_USERNAME', '')
|
||||||
|
MAIL_PASSWORD = os.getenv('MAIL_PASSWORD', '')
|
||||||
|
|
||||||
|
# Security Settings
|
||||||
|
WTF_CSRF_ENABLED = True
|
||||||
|
WTF_CSRF_TIME_LIMIT = None
|
||||||
|
|
||||||
|
# Pagination
|
||||||
|
POSTS_PER_PAGE = int(os.getenv('POSTS_PER_PAGE', '10'))
|
||||||
|
PROJECTS_PER_PAGE = int(os.getenv('PROJECTS_PER_PAGE', '12'))
|
||||||
|
|
||||||
|
# Cache Settings
|
||||||
|
CACHE_TYPE = os.getenv('CACHE_TYPE', 'simple')
|
||||||
|
CACHE_DEFAULT_TIMEOUT = int(os.getenv('CACHE_DEFAULT_TIMEOUT', '300'))
|
||||||
|
|
||||||
|
# Create config instance
|
||||||
config = Config()
|
config = Config()
|
||||||
|
|||||||
@@ -1,20 +1,53 @@
|
|||||||
version: "3.9"
|
version: '3.9'
|
||||||
|
|
||||||
services:
|
services:
|
||||||
|
# MySQL Database
|
||||||
|
mysql:
|
||||||
|
image: mysql:8.0
|
||||||
|
container_name: hersel_mysql
|
||||||
|
restart: always
|
||||||
|
environment:
|
||||||
|
MYSQL_ROOT_PASSWORD: root_password_change_me
|
||||||
|
MYSQL_DATABASE: hersel_portfolio
|
||||||
|
MYSQL_USER: hersel_user
|
||||||
|
MYSQL_PASSWORD: secure_password_123
|
||||||
|
ports:
|
||||||
|
- "3307:3306"
|
||||||
|
volumes:
|
||||||
|
- mysql_data:/var/lib/mysql
|
||||||
|
- ./init.sql:/docker-entrypoint-initdb.d/init.sql:ro
|
||||||
|
command: --default-authentication-plugin=mysql_native_password
|
||||||
|
healthcheck:
|
||||||
|
test: ["CMD", "mysqladmin", "ping", "-h", "localhost"]
|
||||||
|
timeout: 20s
|
||||||
|
retries: 10
|
||||||
|
|
||||||
|
# Quart Application
|
||||||
quartapp:
|
quartapp:
|
||||||
image: python:3.10-slim
|
build: .
|
||||||
container_name: quartapp
|
container_name: hersel_app
|
||||||
working_dir: /app
|
restart: always
|
||||||
ports:
|
ports:
|
||||||
- "127.0.0.1:5000:5000"
|
- "127.0.0.1:5000:5000"
|
||||||
restart: always
|
|
||||||
command: >
|
|
||||||
sh -c "
|
|
||||||
apt-get update &&
|
|
||||||
apt-get install -y git &&
|
|
||||||
[ -d /app/.git ] || git clone https://github.com/BluLupo/hersel.it.git /app &&
|
|
||||||
pip install --no-cache-dir -r requirements.txt &&
|
|
||||||
hypercorn -c hypercorn_config.toml app:app
|
|
||||||
"
|
|
||||||
environment:
|
environment:
|
||||||
|
- DEBUG=False
|
||||||
|
- SECRET_KEY=super-secret-key-change-in-production-please
|
||||||
|
- DB_HOST=mysql
|
||||||
|
- DB_PORT=3306
|
||||||
|
- DB_USER=hersel_user
|
||||||
|
- DB_PASSWORD=secure_password_123
|
||||||
|
- DB_NAME=hersel_portfolio
|
||||||
- PYTHONUNBUFFERED=1
|
- PYTHONUNBUFFERED=1
|
||||||
|
depends_on:
|
||||||
|
mysql:
|
||||||
|
condition: service_healthy
|
||||||
|
volumes:
|
||||||
|
- ./static/uploads:/app/static/uploads
|
||||||
|
|
||||||
|
volumes:
|
||||||
|
mysql_data:
|
||||||
|
driver: local
|
||||||
|
|
||||||
|
networks:
|
||||||
|
default:
|
||||||
|
name: hersel_network
|
||||||
|
|||||||
143
init.sql
Normal file
143
init.sql
Normal file
@@ -0,0 +1,143 @@
|
|||||||
|
-- Initial database setup for Hersel.it Portfolio
|
||||||
|
-- This file is automatically executed when MySQL container starts
|
||||||
|
|
||||||
|
USE hersel_portfolio;
|
||||||
|
|
||||||
|
-- Enable UTF8MB4 charset for emoji and international characters
|
||||||
|
SET NAMES utf8mb4;
|
||||||
|
SET character_set_client = utf8mb4;
|
||||||
|
|
||||||
|
-- Create categories table
|
||||||
|
CREATE TABLE IF NOT EXISTS categories (
|
||||||
|
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||||
|
name VARCHAR(100) NOT NULL,
|
||||||
|
slug VARCHAR(100) UNIQUE NOT NULL,
|
||||||
|
description TEXT,
|
||||||
|
color VARCHAR(7) DEFAULT '#007bff',
|
||||||
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
||||||
|
) ENGINE=InnoDB CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
||||||
|
|
||||||
|
-- Create users table
|
||||||
|
CREATE TABLE IF NOT EXISTS users (
|
||||||
|
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||||
|
username VARCHAR(50) UNIQUE NOT NULL,
|
||||||
|
email VARCHAR(100) UNIQUE NOT NULL,
|
||||||
|
password_hash VARCHAR(255) NOT NULL,
|
||||||
|
first_name VARCHAR(50),
|
||||||
|
last_name VARCHAR(50),
|
||||||
|
role ENUM('admin', 'user') DEFAULT 'user',
|
||||||
|
is_active BOOLEAN DEFAULT TRUE,
|
||||||
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
|
||||||
|
) ENGINE=InnoDB CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
||||||
|
|
||||||
|
-- Create projects table
|
||||||
|
CREATE TABLE IF NOT EXISTS projects (
|
||||||
|
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||||
|
title VARCHAR(200) NOT NULL,
|
||||||
|
slug VARCHAR(200) UNIQUE NOT NULL,
|
||||||
|
description TEXT,
|
||||||
|
content LONGTEXT,
|
||||||
|
image_url VARCHAR(500),
|
||||||
|
github_url VARCHAR(500),
|
||||||
|
demo_url VARCHAR(500),
|
||||||
|
technologies JSON,
|
||||||
|
category_id INT,
|
||||||
|
is_featured BOOLEAN DEFAULT FALSE,
|
||||||
|
is_published BOOLEAN DEFAULT TRUE,
|
||||||
|
created_by INT,
|
||||||
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||||
|
FOREIGN KEY (category_id) REFERENCES categories(id) ON DELETE SET NULL,
|
||||||
|
FOREIGN KEY (created_by) REFERENCES users(id) ON DELETE SET NULL
|
||||||
|
) ENGINE=InnoDB CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
||||||
|
|
||||||
|
-- Create posts table (for future blog functionality)
|
||||||
|
CREATE TABLE IF NOT EXISTS posts (
|
||||||
|
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||||
|
title VARCHAR(200) NOT NULL,
|
||||||
|
slug VARCHAR(200) UNIQUE NOT NULL,
|
||||||
|
excerpt TEXT,
|
||||||
|
content LONGTEXT,
|
||||||
|
featured_image VARCHAR(500),
|
||||||
|
category_id INT,
|
||||||
|
author_id INT,
|
||||||
|
is_published BOOLEAN DEFAULT FALSE,
|
||||||
|
published_at TIMESTAMP NULL,
|
||||||
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||||
|
FOREIGN KEY (category_id) REFERENCES categories(id) ON DELETE SET NULL,
|
||||||
|
FOREIGN KEY (author_id) REFERENCES users(id) ON DELETE SET NULL
|
||||||
|
) ENGINE=InnoDB CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
||||||
|
|
||||||
|
-- Create settings table
|
||||||
|
CREATE TABLE IF NOT EXISTS settings (
|
||||||
|
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||||
|
setting_key VARCHAR(100) UNIQUE NOT NULL,
|
||||||
|
setting_value LONGTEXT,
|
||||||
|
description TEXT,
|
||||||
|
type ENUM('text', 'textarea', 'boolean', 'json') DEFAULT 'text',
|
||||||
|
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
|
||||||
|
) ENGINE=InnoDB CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
||||||
|
|
||||||
|
-- Insert default categories
|
||||||
|
INSERT INTO categories (name, slug, description, color) VALUES
|
||||||
|
('Web Development', 'web-development', 'Progetti di sviluppo web', '#007bff'),
|
||||||
|
('Mobile Apps', 'mobile-apps', 'Applicazioni mobile', '#28a745'),
|
||||||
|
('Desktop Apps', 'desktop-apps', 'Applicazioni desktop', '#ffc107'),
|
||||||
|
('APIs', 'apis', 'API e servizi web', '#dc3545'),
|
||||||
|
('Tools & Utilities', 'tools-utilities', 'Strumenti e utility', '#6f42c1'),
|
||||||
|
('Open Source', 'open-source', 'Progetti open source', '#20c997')
|
||||||
|
ON DUPLICATE KEY UPDATE name=VALUES(name);
|
||||||
|
|
||||||
|
-- Insert default settings
|
||||||
|
INSERT INTO settings (setting_key, setting_value, description, type) VALUES
|
||||||
|
('site_name', 'Hersel.it', 'Nome del sito', 'text'),
|
||||||
|
('site_description', 'Portfolio personale di Hersel Giannella - Developer', 'Descrizione del sito', 'textarea'),
|
||||||
|
('admin_email', 'admin@hersel.it', 'Email amministratore', 'text'),
|
||||||
|
('site_logo', '/static/img/logo.png', 'URL del logo', 'text'),
|
||||||
|
('social_github', 'https://github.com/BluLupo', 'GitHub URL', 'text'),
|
||||||
|
('social_linkedin', '', 'LinkedIn URL', 'text'),
|
||||||
|
('social_twitter', '', 'Twitter URL', 'text'),
|
||||||
|
('site_maintenance', 'false', 'Modalità manutenzione', 'boolean'),
|
||||||
|
('analytics_code', '', 'Codice Analytics', 'textarea'),
|
||||||
|
('projects_per_page', '12', 'Progetti per pagina', 'text'),
|
||||||
|
('featured_projects_limit', '6', 'Limite progetti in evidenza', 'text')
|
||||||
|
ON DUPLICATE KEY UPDATE setting_value=VALUES(setting_value);
|
||||||
|
|
||||||
|
-- Create admin user (password: AdminPass123!)
|
||||||
|
-- This creates a default admin user for initial access
|
||||||
|
-- Password hash for 'AdminPass123!' generated with bcrypt
|
||||||
|
INSERT INTO users (username, email, password_hash, first_name, last_name, role) VALUES
|
||||||
|
('admin', 'admin@hersel.it', '$2b$12$LQv3c1yqBWVHxkd0LHAkCOYz6TtxMQJqyaqr06eoAGNz9CpahtY1q', 'Admin', 'User', 'admin')
|
||||||
|
ON DUPLICATE KEY UPDATE role=VALUES(role);
|
||||||
|
|
||||||
|
-- Insert sample projects (optional)
|
||||||
|
INSERT INTO projects (title, slug, description, content, github_url, technologies, is_featured, is_published, created_by) VALUES
|
||||||
|
('Hersel.it Portfolio', 'hersel-it-portfolio', 'Portfolio dinamico sviluppato con Quart e MySQL',
|
||||||
|
'<h2>Portfolio Dinamico</h2><p>Questo portfolio è stato sviluppato utilizzando le seguenti tecnologie:</p><ul><li>Python con Quart framework</li><li>MySQL per il database</li><li>Bootstrap 5 per il frontend</li><li>Docker per il deployment</li></ul>',
|
||||||
|
'https://github.com/BluLupo/hersel.it',
|
||||||
|
'["Python", "Quart", "MySQL", "Bootstrap", "Docker"]',
|
||||||
|
TRUE, TRUE, 1),
|
||||||
|
|
||||||
|
('API REST con Quart', 'api-rest-quart', 'API RESTful asincrona per gestione dati',
|
||||||
|
'<h2>API REST</h2><p>API asincrona sviluppata con Quart per gestire operazioni CRUD su database MySQL.</p>',
|
||||||
|
'',
|
||||||
|
'["Python", "Quart", "MySQL", "REST API", "Async"]',
|
||||||
|
FALSE, TRUE, 1)
|
||||||
|
ON DUPLICATE KEY UPDATE title=VALUES(title);
|
||||||
|
|
||||||
|
-- Create indexes for better performance
|
||||||
|
CREATE INDEX idx_projects_published ON projects(is_published);
|
||||||
|
CREATE INDEX idx_projects_featured ON projects(is_featured);
|
||||||
|
CREATE INDEX idx_projects_category ON projects(category_id);
|
||||||
|
CREATE INDEX idx_users_email ON users(email);
|
||||||
|
CREATE INDEX idx_users_username ON users(username);
|
||||||
|
CREATE INDEX idx_posts_published ON posts(is_published);
|
||||||
|
|
||||||
|
-- Show confirmation message
|
||||||
|
SELECT 'Database initialized successfully!' as Status;
|
||||||
|
SELECT COUNT(*) as 'Total Categories' FROM categories;
|
||||||
|
SELECT COUNT(*) as 'Total Settings' FROM settings;
|
||||||
|
SELECT COUNT(*) as 'Admin Users' FROM users WHERE role='admin';
|
||||||
|
SELECT COUNT(*) as 'Sample Projects' FROM projects;
|
||||||
8
models/__init__.py
Normal file
8
models/__init__.py
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
# Database Models Package
|
||||||
|
from .user import User
|
||||||
|
from .post import Post
|
||||||
|
from .project import Project
|
||||||
|
from .category import Category
|
||||||
|
from .settings import Settings
|
||||||
|
|
||||||
|
__all__ = ['User', 'Post', 'Project', 'Category', 'Settings']
|
||||||
97
models/category.py
Normal file
97
models/category.py
Normal file
@@ -0,0 +1,97 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
# Category Model
|
||||||
|
|
||||||
|
from typing import Optional, Dict, List
|
||||||
|
from .database import db_manager
|
||||||
|
from datetime import datetime
|
||||||
|
|
||||||
|
class Category:
|
||||||
|
def __init__(self, **kwargs):
|
||||||
|
self.id = kwargs.get('id')
|
||||||
|
self.name = kwargs.get('name')
|
||||||
|
self.slug = kwargs.get('slug')
|
||||||
|
self.description = kwargs.get('description')
|
||||||
|
self.color = kwargs.get('color', '#007bff')
|
||||||
|
self.created_at = kwargs.get('created_at')
|
||||||
|
|
||||||
|
async def save(self) -> int:
|
||||||
|
"""Save category to database"""
|
||||||
|
if self.id:
|
||||||
|
# Update existing category
|
||||||
|
query = """
|
||||||
|
UPDATE categories SET
|
||||||
|
name=%s, slug=%s, description=%s, color=%s
|
||||||
|
WHERE id=%s
|
||||||
|
"""
|
||||||
|
params = (self.name, self.slug, self.description, self.color, self.id)
|
||||||
|
await db_manager.execute_update(query, params)
|
||||||
|
return self.id
|
||||||
|
else:
|
||||||
|
# Insert new category
|
||||||
|
query = """
|
||||||
|
INSERT INTO categories (name, slug, description, color)
|
||||||
|
VALUES (%s, %s, %s, %s)
|
||||||
|
"""
|
||||||
|
params = (self.name, self.slug, self.description, self.color)
|
||||||
|
category_id = await db_manager.execute_insert(query, params)
|
||||||
|
self.id = category_id
|
||||||
|
return category_id
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
async def find_by_id(cls, category_id: int) -> Optional['Category']:
|
||||||
|
"""Find category by ID"""
|
||||||
|
query = "SELECT * FROM categories WHERE id = %s"
|
||||||
|
results = await db_manager.execute_query(query, (category_id,))
|
||||||
|
if results:
|
||||||
|
return cls(**results[0])
|
||||||
|
return None
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
async def find_by_slug(cls, slug: str) -> Optional['Category']:
|
||||||
|
"""Find category by slug"""
|
||||||
|
query = "SELECT * FROM categories WHERE slug = %s"
|
||||||
|
results = await db_manager.execute_query(query, (slug,))
|
||||||
|
if results:
|
||||||
|
return cls(**results[0])
|
||||||
|
return None
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
async def get_all(cls, limit: int = 50) -> List['Category']:
|
||||||
|
"""Get all categories"""
|
||||||
|
query = "SELECT * FROM categories ORDER BY name ASC LIMIT %s"
|
||||||
|
results = await db_manager.execute_query(query, (limit,))
|
||||||
|
return [cls(**row) for row in results]
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
async def count(cls) -> int:
|
||||||
|
"""Count total categories"""
|
||||||
|
query = "SELECT COUNT(*) as count FROM categories"
|
||||||
|
results = await db_manager.execute_query(query)
|
||||||
|
return results[0]['count'] if results else 0
|
||||||
|
|
||||||
|
async def delete(self) -> bool:
|
||||||
|
"""Delete category"""
|
||||||
|
query = "DELETE FROM categories WHERE id = %s"
|
||||||
|
affected = await db_manager.execute_update(query, (self.id,))
|
||||||
|
return affected > 0
|
||||||
|
|
||||||
|
def to_dict(self) -> Dict:
|
||||||
|
"""Convert category to dictionary"""
|
||||||
|
return {
|
||||||
|
'id': self.id,
|
||||||
|
'name': self.name,
|
||||||
|
'slug': self.slug,
|
||||||
|
'description': self.description,
|
||||||
|
'color': self.color,
|
||||||
|
'created_at': self.created_at.isoformat() if self.created_at else None
|
||||||
|
}
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def generate_slug(name: str) -> str:
|
||||||
|
"""Generate URL-friendly slug from name"""
|
||||||
|
import re
|
||||||
|
slug = re.sub(r'[^\w\s-]', '', name).strip().lower()
|
||||||
|
slug = re.sub(r'[\s_-]+', '-', slug)
|
||||||
|
return slug
|
||||||
194
models/database.py
Normal file
194
models/database.py
Normal file
@@ -0,0 +1,194 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
# Database Configuration and Connection Manager
|
||||||
|
|
||||||
|
import asyncio
|
||||||
|
import aiomysql
|
||||||
|
from typing import Optional
|
||||||
|
from config import config
|
||||||
|
|
||||||
|
class DatabaseManager:
|
||||||
|
def __init__(self):
|
||||||
|
self.pool: Optional[aiomysql.Pool] = None
|
||||||
|
|
||||||
|
async def init_pool(self):
|
||||||
|
"""Initialize connection pool"""
|
||||||
|
try:
|
||||||
|
self.pool = await aiomysql.create_pool(
|
||||||
|
host=config.DB_HOST,
|
||||||
|
port=config.DB_PORT,
|
||||||
|
user=config.DB_USER,
|
||||||
|
password=config.DB_PASSWORD,
|
||||||
|
db=config.DB_NAME,
|
||||||
|
minsize=1,
|
||||||
|
maxsize=10,
|
||||||
|
autocommit=True,
|
||||||
|
charset='utf8mb4'
|
||||||
|
)
|
||||||
|
print("✅ Database connection pool initialized")
|
||||||
|
except Exception as e:
|
||||||
|
print(f"❌ Error initializing database pool: {e}")
|
||||||
|
raise
|
||||||
|
|
||||||
|
async def close_pool(self):
|
||||||
|
"""Close connection pool"""
|
||||||
|
if self.pool:
|
||||||
|
self.pool.close()
|
||||||
|
await self.pool.wait_closed()
|
||||||
|
print("🔒 Database connection pool closed")
|
||||||
|
|
||||||
|
async def get_connection(self):
|
||||||
|
"""Get connection from pool"""
|
||||||
|
if not self.pool:
|
||||||
|
await self.init_pool()
|
||||||
|
return self.pool.acquire()
|
||||||
|
|
||||||
|
async def execute_query(self, query: str, params: tuple = None):
|
||||||
|
"""Execute a query and return results"""
|
||||||
|
async with self.pool.acquire() as conn:
|
||||||
|
async with conn.cursor(aiomysql.DictCursor) as cursor:
|
||||||
|
await cursor.execute(query, params)
|
||||||
|
return await cursor.fetchall()
|
||||||
|
|
||||||
|
async def execute_insert(self, query: str, params: tuple = None):
|
||||||
|
"""Execute insert query and return last insert id"""
|
||||||
|
async with self.pool.acquire() as conn:
|
||||||
|
async with conn.cursor() as cursor:
|
||||||
|
await cursor.execute(query, params)
|
||||||
|
return cursor.lastrowid
|
||||||
|
|
||||||
|
async def execute_update(self, query: str, params: tuple = None):
|
||||||
|
"""Execute update/delete query and return affected rows"""
|
||||||
|
async with self.pool.acquire() as conn:
|
||||||
|
async with conn.cursor() as cursor:
|
||||||
|
await cursor.execute(query, params)
|
||||||
|
return cursor.rowcount
|
||||||
|
|
||||||
|
# Global database manager instance
|
||||||
|
db_manager = DatabaseManager()
|
||||||
|
|
||||||
|
async def init_database():
|
||||||
|
"""Initialize database and create tables"""
|
||||||
|
await db_manager.init_pool()
|
||||||
|
await create_tables()
|
||||||
|
|
||||||
|
async def create_tables():
|
||||||
|
"""Create database tables if they don't exist"""
|
||||||
|
tables = [
|
||||||
|
# Users table
|
||||||
|
"""
|
||||||
|
CREATE TABLE IF NOT EXISTS users (
|
||||||
|
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||||
|
username VARCHAR(50) UNIQUE NOT NULL,
|
||||||
|
email VARCHAR(100) UNIQUE NOT NULL,
|
||||||
|
password_hash VARCHAR(255) NOT NULL,
|
||||||
|
first_name VARCHAR(50),
|
||||||
|
last_name VARCHAR(50),
|
||||||
|
role ENUM('admin', 'user') DEFAULT 'user',
|
||||||
|
is_active BOOLEAN DEFAULT TRUE,
|
||||||
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
|
||||||
|
) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci
|
||||||
|
""",
|
||||||
|
|
||||||
|
# Categories table
|
||||||
|
"""
|
||||||
|
CREATE TABLE IF NOT EXISTS categories (
|
||||||
|
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||||
|
name VARCHAR(100) NOT NULL,
|
||||||
|
slug VARCHAR(100) UNIQUE NOT NULL,
|
||||||
|
description TEXT,
|
||||||
|
color VARCHAR(7) DEFAULT '#007bff',
|
||||||
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
||||||
|
) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci
|
||||||
|
""",
|
||||||
|
|
||||||
|
# Projects table
|
||||||
|
"""
|
||||||
|
CREATE TABLE IF NOT EXISTS projects (
|
||||||
|
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||||
|
title VARCHAR(200) NOT NULL,
|
||||||
|
slug VARCHAR(200) UNIQUE NOT NULL,
|
||||||
|
description TEXT,
|
||||||
|
content LONGTEXT,
|
||||||
|
image_url VARCHAR(500),
|
||||||
|
github_url VARCHAR(500),
|
||||||
|
demo_url VARCHAR(500),
|
||||||
|
technologies JSON,
|
||||||
|
category_id INT,
|
||||||
|
is_featured BOOLEAN DEFAULT FALSE,
|
||||||
|
is_published BOOLEAN DEFAULT TRUE,
|
||||||
|
created_by INT,
|
||||||
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||||
|
FOREIGN KEY (category_id) REFERENCES categories(id) ON DELETE SET NULL,
|
||||||
|
FOREIGN KEY (created_by) REFERENCES users(id) ON DELETE SET NULL
|
||||||
|
) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci
|
||||||
|
""",
|
||||||
|
|
||||||
|
# Posts table (for blog functionality)
|
||||||
|
"""
|
||||||
|
CREATE TABLE IF NOT EXISTS posts (
|
||||||
|
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||||
|
title VARCHAR(200) NOT NULL,
|
||||||
|
slug VARCHAR(200) UNIQUE NOT NULL,
|
||||||
|
excerpt TEXT,
|
||||||
|
content LONGTEXT,
|
||||||
|
featured_image VARCHAR(500),
|
||||||
|
category_id INT,
|
||||||
|
author_id INT,
|
||||||
|
is_published BOOLEAN DEFAULT FALSE,
|
||||||
|
published_at TIMESTAMP NULL,
|
||||||
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||||
|
FOREIGN KEY (category_id) REFERENCES categories(id) ON DELETE SET NULL,
|
||||||
|
FOREIGN KEY (author_id) REFERENCES users(id) ON DELETE SET NULL
|
||||||
|
) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci
|
||||||
|
""",
|
||||||
|
|
||||||
|
# Settings table
|
||||||
|
"""
|
||||||
|
CREATE TABLE IF NOT EXISTS settings (
|
||||||
|
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||||
|
setting_key VARCHAR(100) UNIQUE NOT NULL,
|
||||||
|
setting_value LONGTEXT,
|
||||||
|
description TEXT,
|
||||||
|
type ENUM('text', 'textarea', 'boolean', 'json') DEFAULT 'text',
|
||||||
|
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
|
||||||
|
) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci
|
||||||
|
"""
|
||||||
|
]
|
||||||
|
|
||||||
|
for table_sql in tables:
|
||||||
|
try:
|
||||||
|
await db_manager.execute_update(table_sql)
|
||||||
|
print(f"✅ Table created/verified")
|
||||||
|
except Exception as e:
|
||||||
|
print(f"❌ Error creating table: {e}")
|
||||||
|
|
||||||
|
# Insert default settings
|
||||||
|
await insert_default_settings()
|
||||||
|
|
||||||
|
async def insert_default_settings():
|
||||||
|
"""Insert default settings if they don't exist"""
|
||||||
|
default_settings = [
|
||||||
|
('site_name', 'Hersel.it', 'Nome del sito', 'text'),
|
||||||
|
('site_description', 'Portfolio personale di Hersel Giannella', 'Descrizione del sito', 'textarea'),
|
||||||
|
('admin_email', 'admin@hersel.it', 'Email amministratore', 'text'),
|
||||||
|
('site_logo', '/static/img/logo.png', 'URL del logo', 'text'),
|
||||||
|
('social_github', 'https://github.com/BluLupo', 'GitHub URL', 'text'),
|
||||||
|
('social_linkedin', '', 'LinkedIn URL', 'text'),
|
||||||
|
('social_twitter', '', 'Twitter URL', 'text'),
|
||||||
|
('site_maintenance', 'false', 'Modalità manutenzione', 'boolean'),
|
||||||
|
('analytics_code', '', 'Codice Analytics', 'textarea')
|
||||||
|
]
|
||||||
|
|
||||||
|
for key, value, desc, type_val in default_settings:
|
||||||
|
try:
|
||||||
|
await db_manager.execute_insert(
|
||||||
|
"INSERT IGNORE INTO settings (setting_key, setting_value, description, type) VALUES (%s, %s, %s, %s)",
|
||||||
|
(key, value, desc, type_val)
|
||||||
|
)
|
||||||
|
except Exception as e:
|
||||||
|
print(f"Warning: Could not insert setting {key}: {e}")
|
||||||
116
models/post.py
Normal file
116
models/post.py
Normal file
@@ -0,0 +1,116 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
# Post Model (for future blog functionality)
|
||||||
|
|
||||||
|
from typing import Optional, Dict, List
|
||||||
|
from .database import db_manager
|
||||||
|
from datetime import datetime
|
||||||
|
|
||||||
|
class Post:
|
||||||
|
def __init__(self, **kwargs):
|
||||||
|
self.id = kwargs.get('id')
|
||||||
|
self.title = kwargs.get('title')
|
||||||
|
self.slug = kwargs.get('slug')
|
||||||
|
self.excerpt = kwargs.get('excerpt')
|
||||||
|
self.content = kwargs.get('content')
|
||||||
|
self.featured_image = kwargs.get('featured_image')
|
||||||
|
self.category_id = kwargs.get('category_id')
|
||||||
|
self.author_id = kwargs.get('author_id')
|
||||||
|
self.is_published = kwargs.get('is_published', False)
|
||||||
|
self.published_at = kwargs.get('published_at')
|
||||||
|
self.created_at = kwargs.get('created_at')
|
||||||
|
self.updated_at = kwargs.get('updated_at')
|
||||||
|
|
||||||
|
async def save(self) -> int:
|
||||||
|
"""Save post to database"""
|
||||||
|
if self.id:
|
||||||
|
# Update existing post
|
||||||
|
query = """
|
||||||
|
UPDATE posts SET
|
||||||
|
title=%s, slug=%s, excerpt=%s, content=%s, featured_image=%s,
|
||||||
|
category_id=%s, is_published=%s, published_at=%s, updated_at=NOW()
|
||||||
|
WHERE id=%s
|
||||||
|
"""
|
||||||
|
params = (self.title, self.slug, self.excerpt, self.content, self.featured_image,
|
||||||
|
self.category_id, self.is_published, self.published_at, self.id)
|
||||||
|
await db_manager.execute_update(query, params)
|
||||||
|
return self.id
|
||||||
|
else:
|
||||||
|
# Insert new post
|
||||||
|
query = """
|
||||||
|
INSERT INTO posts (title, slug, excerpt, content, featured_image, category_id,
|
||||||
|
author_id, is_published, published_at)
|
||||||
|
VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s)
|
||||||
|
"""
|
||||||
|
params = (self.title, self.slug, self.excerpt, self.content, self.featured_image,
|
||||||
|
self.category_id, self.author_id, self.is_published, self.published_at)
|
||||||
|
post_id = await db_manager.execute_insert(query, params)
|
||||||
|
self.id = post_id
|
||||||
|
return post_id
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
async def find_by_id(cls, post_id: int) -> Optional['Post']:
|
||||||
|
"""Find post by ID"""
|
||||||
|
query = "SELECT * FROM posts WHERE id = %s"
|
||||||
|
results = await db_manager.execute_query(query, (post_id,))
|
||||||
|
if results:
|
||||||
|
return cls(**results[0])
|
||||||
|
return None
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
async def find_by_slug(cls, slug: str) -> Optional['Post']:
|
||||||
|
"""Find post by slug"""
|
||||||
|
query = "SELECT * FROM posts WHERE slug = %s AND is_published = TRUE"
|
||||||
|
results = await db_manager.execute_query(query, (slug,))
|
||||||
|
if results:
|
||||||
|
return cls(**results[0])
|
||||||
|
return None
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
async def get_all(cls, published_only: bool = True, limit: int = 50, offset: int = 0) -> List['Post']:
|
||||||
|
"""Get all posts with pagination"""
|
||||||
|
query = "SELECT * FROM posts"
|
||||||
|
params = []
|
||||||
|
|
||||||
|
if published_only:
|
||||||
|
query += " WHERE is_published = TRUE"
|
||||||
|
|
||||||
|
query += " ORDER BY created_at DESC LIMIT %s OFFSET %s"
|
||||||
|
params.extend([limit, offset])
|
||||||
|
|
||||||
|
results = await db_manager.execute_query(query, tuple(params))
|
||||||
|
return [cls(**row) for row in results]
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
async def count(cls, published_only: bool = True) -> int:
|
||||||
|
"""Count total posts"""
|
||||||
|
query = "SELECT COUNT(*) as count FROM posts"
|
||||||
|
if published_only:
|
||||||
|
query += " WHERE is_published = TRUE"
|
||||||
|
|
||||||
|
results = await db_manager.execute_query(query)
|
||||||
|
return results[0]['count'] if results else 0
|
||||||
|
|
||||||
|
async def delete(self) -> bool:
|
||||||
|
"""Delete post"""
|
||||||
|
query = "DELETE FROM posts WHERE id = %s"
|
||||||
|
affected = await db_manager.execute_update(query, (self.id,))
|
||||||
|
return affected > 0
|
||||||
|
|
||||||
|
def to_dict(self) -> Dict:
|
||||||
|
"""Convert post to dictionary"""
|
||||||
|
return {
|
||||||
|
'id': self.id,
|
||||||
|
'title': self.title,
|
||||||
|
'slug': self.slug,
|
||||||
|
'excerpt': self.excerpt,
|
||||||
|
'content': self.content,
|
||||||
|
'featured_image': self.featured_image,
|
||||||
|
'category_id': self.category_id,
|
||||||
|
'author_id': self.author_id,
|
||||||
|
'is_published': self.is_published,
|
||||||
|
'published_at': self.published_at.isoformat() if self.published_at else None,
|
||||||
|
'created_at': self.created_at.isoformat() if self.created_at else None,
|
||||||
|
'updated_at': self.updated_at.isoformat() if self.updated_at else None
|
||||||
|
}
|
||||||
183
models/project.py
Normal file
183
models/project.py
Normal file
@@ -0,0 +1,183 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
# Project Model
|
||||||
|
|
||||||
|
import json
|
||||||
|
from typing import Optional, Dict, List
|
||||||
|
from .database import db_manager
|
||||||
|
from datetime import datetime
|
||||||
|
|
||||||
|
class Project:
|
||||||
|
def __init__(self, **kwargs):
|
||||||
|
self.id = kwargs.get('id')
|
||||||
|
self.title = kwargs.get('title')
|
||||||
|
self.slug = kwargs.get('slug')
|
||||||
|
self.description = kwargs.get('description')
|
||||||
|
self.content = kwargs.get('content')
|
||||||
|
self.image_url = kwargs.get('image_url')
|
||||||
|
self.github_url = kwargs.get('github_url')
|
||||||
|
self.demo_url = kwargs.get('demo_url')
|
||||||
|
self.technologies = kwargs.get('technologies', [])
|
||||||
|
self.category_id = kwargs.get('category_id')
|
||||||
|
self.is_featured = kwargs.get('is_featured', False)
|
||||||
|
self.is_published = kwargs.get('is_published', True)
|
||||||
|
self.created_by = kwargs.get('created_by')
|
||||||
|
self.created_at = kwargs.get('created_at')
|
||||||
|
self.updated_at = kwargs.get('updated_at')
|
||||||
|
|
||||||
|
# Handle JSON technologies field
|
||||||
|
if isinstance(self.technologies, str):
|
||||||
|
try:
|
||||||
|
self.technologies = json.loads(self.technologies)
|
||||||
|
except:
|
||||||
|
self.technologies = []
|
||||||
|
|
||||||
|
@property
|
||||||
|
def technologies_json(self) -> str:
|
||||||
|
"""Get technologies as JSON string"""
|
||||||
|
return json.dumps(self.technologies) if self.technologies else '[]'
|
||||||
|
|
||||||
|
async def save(self) -> int:
|
||||||
|
"""Save project to database"""
|
||||||
|
if self.id:
|
||||||
|
# Update existing project
|
||||||
|
query = """
|
||||||
|
UPDATE projects SET
|
||||||
|
title=%s, slug=%s, description=%s, content=%s, image_url=%s,
|
||||||
|
github_url=%s, demo_url=%s, technologies=%s, category_id=%s,
|
||||||
|
is_featured=%s, is_published=%s, updated_at=NOW()
|
||||||
|
WHERE id=%s
|
||||||
|
"""
|
||||||
|
params = (self.title, self.slug, self.description, self.content, self.image_url,
|
||||||
|
self.github_url, self.demo_url, self.technologies_json, self.category_id,
|
||||||
|
self.is_featured, self.is_published, self.id)
|
||||||
|
await db_manager.execute_update(query, params)
|
||||||
|
return self.id
|
||||||
|
else:
|
||||||
|
# Insert new project
|
||||||
|
query = """
|
||||||
|
INSERT INTO projects (title, slug, description, content, image_url, github_url, demo_url,
|
||||||
|
technologies, category_id, is_featured, is_published, created_by)
|
||||||
|
VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)
|
||||||
|
"""
|
||||||
|
params = (self.title, self.slug, self.description, self.content, self.image_url,
|
||||||
|
self.github_url, self.demo_url, self.technologies_json, self.category_id,
|
||||||
|
self.is_featured, self.is_published, self.created_by)
|
||||||
|
project_id = await db_manager.execute_insert(query, params)
|
||||||
|
self.id = project_id
|
||||||
|
return project_id
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
async def find_by_id(cls, project_id: int) -> Optional['Project']:
|
||||||
|
"""Find project by ID"""
|
||||||
|
query = "SELECT * FROM projects WHERE id = %s"
|
||||||
|
results = await db_manager.execute_query(query, (project_id,))
|
||||||
|
if results:
|
||||||
|
return cls(**results[0])
|
||||||
|
return None
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
async def find_by_slug(cls, slug: str) -> Optional['Project']:
|
||||||
|
"""Find project by slug"""
|
||||||
|
query = "SELECT * FROM projects WHERE slug = %s AND is_published = TRUE"
|
||||||
|
results = await db_manager.execute_query(query, (slug,))
|
||||||
|
if results:
|
||||||
|
return cls(**results[0])
|
||||||
|
return None
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
async def get_all(cls, published_only: bool = True, limit: int = 50, offset: int = 0) -> List['Project']:
|
||||||
|
"""Get all projects with pagination"""
|
||||||
|
query = "SELECT * FROM projects"
|
||||||
|
params = []
|
||||||
|
|
||||||
|
if published_only:
|
||||||
|
query += " WHERE is_published = TRUE"
|
||||||
|
|
||||||
|
query += " ORDER BY created_at DESC LIMIT %s OFFSET %s"
|
||||||
|
params.extend([limit, offset])
|
||||||
|
|
||||||
|
results = await db_manager.execute_query(query, tuple(params))
|
||||||
|
return [cls(**row) for row in results]
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
async def get_featured(cls, limit: int = 6) -> List['Project']:
|
||||||
|
"""Get featured projects"""
|
||||||
|
query = """
|
||||||
|
SELECT * FROM projects
|
||||||
|
WHERE is_published = TRUE AND is_featured = TRUE
|
||||||
|
ORDER BY created_at DESC
|
||||||
|
LIMIT %s
|
||||||
|
"""
|
||||||
|
results = await db_manager.execute_query(query, (limit,))
|
||||||
|
return [cls(**row) for row in results]
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
async def get_by_category(cls, category_id: int, limit: int = 20) -> List['Project']:
|
||||||
|
"""Get projects by category"""
|
||||||
|
query = """
|
||||||
|
SELECT * FROM projects
|
||||||
|
WHERE category_id = %s AND is_published = TRUE
|
||||||
|
ORDER BY created_at DESC
|
||||||
|
LIMIT %s
|
||||||
|
"""
|
||||||
|
results = await db_manager.execute_query(query, (category_id, limit))
|
||||||
|
return [cls(**row) for row in results]
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
async def search(cls, search_term: str, limit: int = 20) -> List['Project']:
|
||||||
|
"""Search projects by title and description"""
|
||||||
|
query = """
|
||||||
|
SELECT * FROM projects
|
||||||
|
WHERE (title LIKE %s OR description LIKE %s) AND is_published = TRUE
|
||||||
|
ORDER BY created_at DESC
|
||||||
|
LIMIT %s
|
||||||
|
"""
|
||||||
|
search_pattern = f"%{search_term}%"
|
||||||
|
results = await db_manager.execute_query(query, (search_pattern, search_pattern, limit))
|
||||||
|
return [cls(**row) for row in results]
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
async def count(cls, published_only: bool = True) -> int:
|
||||||
|
"""Count total projects"""
|
||||||
|
query = "SELECT COUNT(*) as count FROM projects"
|
||||||
|
if published_only:
|
||||||
|
query += " WHERE is_published = TRUE"
|
||||||
|
|
||||||
|
results = await db_manager.execute_query(query)
|
||||||
|
return results[0]['count'] if results else 0
|
||||||
|
|
||||||
|
async def delete(self) -> bool:
|
||||||
|
"""Delete project"""
|
||||||
|
query = "DELETE FROM projects WHERE id = %s"
|
||||||
|
affected = await db_manager.execute_update(query, (self.id,))
|
||||||
|
return affected > 0
|
||||||
|
|
||||||
|
def to_dict(self) -> Dict:
|
||||||
|
"""Convert project to dictionary"""
|
||||||
|
return {
|
||||||
|
'id': self.id,
|
||||||
|
'title': self.title,
|
||||||
|
'slug': self.slug,
|
||||||
|
'description': self.description,
|
||||||
|
'content': self.content,
|
||||||
|
'image_url': self.image_url,
|
||||||
|
'github_url': self.github_url,
|
||||||
|
'demo_url': self.demo_url,
|
||||||
|
'technologies': self.technologies,
|
||||||
|
'category_id': self.category_id,
|
||||||
|
'is_featured': self.is_featured,
|
||||||
|
'is_published': self.is_published,
|
||||||
|
'created_by': self.created_by,
|
||||||
|
'created_at': self.created_at.isoformat() if self.created_at else None,
|
||||||
|
'updated_at': self.updated_at.isoformat() if self.updated_at else None
|
||||||
|
}
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def generate_slug(title: str) -> str:
|
||||||
|
"""Generate URL-friendly slug from title"""
|
||||||
|
import re
|
||||||
|
slug = re.sub(r'[^\w\s-]', '', title).strip().lower()
|
||||||
|
slug = re.sub(r'[\s_-]+', '-', slug)
|
||||||
|
return slug
|
||||||
127
models/settings.py
Normal file
127
models/settings.py
Normal file
@@ -0,0 +1,127 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
# Settings Model
|
||||||
|
|
||||||
|
import json
|
||||||
|
from typing import Optional, Dict, List, Any
|
||||||
|
from .database import db_manager
|
||||||
|
|
||||||
|
class Settings:
|
||||||
|
def __init__(self, **kwargs):
|
||||||
|
self.id = kwargs.get('id')
|
||||||
|
self.setting_key = kwargs.get('setting_key')
|
||||||
|
self.setting_value = kwargs.get('setting_value')
|
||||||
|
self.description = kwargs.get('description')
|
||||||
|
self.type = kwargs.get('type', 'text')
|
||||||
|
self.updated_at = kwargs.get('updated_at')
|
||||||
|
|
||||||
|
@property
|
||||||
|
def parsed_value(self) -> Any:
|
||||||
|
"""Parse setting value based on type"""
|
||||||
|
if not self.setting_value:
|
||||||
|
return None
|
||||||
|
|
||||||
|
if self.type == 'boolean':
|
||||||
|
return self.setting_value.lower() in ('true', '1', 'yes', 'on')
|
||||||
|
elif self.type == 'json':
|
||||||
|
try:
|
||||||
|
return json.loads(self.setting_value)
|
||||||
|
except:
|
||||||
|
return {}
|
||||||
|
else:
|
||||||
|
return self.setting_value
|
||||||
|
|
||||||
|
async def save(self) -> int:
|
||||||
|
"""Save setting to database"""
|
||||||
|
if self.id:
|
||||||
|
# Update existing setting
|
||||||
|
query = """
|
||||||
|
UPDATE settings SET
|
||||||
|
setting_key=%s, setting_value=%s, description=%s, type=%s, updated_at=NOW()
|
||||||
|
WHERE id=%s
|
||||||
|
"""
|
||||||
|
params = (self.setting_key, self.setting_value, self.description, self.type, self.id)
|
||||||
|
await db_manager.execute_update(query, params)
|
||||||
|
return self.id
|
||||||
|
else:
|
||||||
|
# Insert new setting
|
||||||
|
query = """
|
||||||
|
INSERT INTO settings (setting_key, setting_value, description, type)
|
||||||
|
VALUES (%s, %s, %s, %s)
|
||||||
|
ON DUPLICATE KEY UPDATE
|
||||||
|
setting_value=VALUES(setting_value),
|
||||||
|
description=VALUES(description),
|
||||||
|
type=VALUES(type),
|
||||||
|
updated_at=NOW()
|
||||||
|
"""
|
||||||
|
params = (self.setting_key, self.setting_value, self.description, self.type)
|
||||||
|
setting_id = await db_manager.execute_insert(query, params)
|
||||||
|
self.id = setting_id or self.id
|
||||||
|
return self.id
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
async def get(cls, key: str, default: Any = None) -> Any:
|
||||||
|
"""Get setting value by key"""
|
||||||
|
query = "SELECT * FROM settings WHERE setting_key = %s"
|
||||||
|
results = await db_manager.execute_query(query, (key,))
|
||||||
|
if results:
|
||||||
|
setting = cls(**results[0])
|
||||||
|
return setting.parsed_value
|
||||||
|
return default
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
async def set(cls, key: str, value: Any, description: str = '', setting_type: str = 'text') -> bool:
|
||||||
|
"""Set setting value"""
|
||||||
|
# Convert value to string based on type
|
||||||
|
if setting_type == 'boolean':
|
||||||
|
str_value = 'true' if value else 'false'
|
||||||
|
elif setting_type == 'json':
|
||||||
|
str_value = json.dumps(value) if isinstance(value, (dict, list)) else str(value)
|
||||||
|
else:
|
||||||
|
str_value = str(value)
|
||||||
|
|
||||||
|
setting = cls(
|
||||||
|
setting_key=key,
|
||||||
|
setting_value=str_value,
|
||||||
|
description=description,
|
||||||
|
type=setting_type
|
||||||
|
)
|
||||||
|
|
||||||
|
try:
|
||||||
|
await setting.save()
|
||||||
|
return True
|
||||||
|
except:
|
||||||
|
return False
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
async def get_all(cls) -> List['Settings']:
|
||||||
|
"""Get all settings"""
|
||||||
|
query = "SELECT * FROM settings ORDER BY setting_key ASC"
|
||||||
|
results = await db_manager.execute_query(query)
|
||||||
|
return [cls(**row) for row in results]
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
async def get_by_prefix(cls, prefix: str) -> List['Settings']:
|
||||||
|
"""Get settings by key prefix"""
|
||||||
|
query = "SELECT * FROM settings WHERE setting_key LIKE %s ORDER BY setting_key ASC"
|
||||||
|
results = await db_manager.execute_query(query, (f"{prefix}%",))
|
||||||
|
return [cls(**row) for row in results]
|
||||||
|
|
||||||
|
async def delete(self) -> bool:
|
||||||
|
"""Delete setting"""
|
||||||
|
query = "DELETE FROM settings WHERE id = %s"
|
||||||
|
affected = await db_manager.execute_update(query, (self.id,))
|
||||||
|
return affected > 0
|
||||||
|
|
||||||
|
def to_dict(self) -> Dict:
|
||||||
|
"""Convert setting to dictionary"""
|
||||||
|
return {
|
||||||
|
'id': self.id,
|
||||||
|
'setting_key': self.setting_key,
|
||||||
|
'setting_value': self.setting_value,
|
||||||
|
'parsed_value': self.parsed_value,
|
||||||
|
'description': self.description,
|
||||||
|
'type': self.type,
|
||||||
|
'updated_at': self.updated_at.isoformat() if self.updated_at else None
|
||||||
|
}
|
||||||
154
models/user.py
Normal file
154
models/user.py
Normal file
@@ -0,0 +1,154 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
# User Model
|
||||||
|
|
||||||
|
import bcrypt
|
||||||
|
from typing import Optional, Dict, List
|
||||||
|
from .database import db_manager
|
||||||
|
from datetime import datetime
|
||||||
|
|
||||||
|
class User:
|
||||||
|
def __init__(self, **kwargs):
|
||||||
|
self.id = kwargs.get('id')
|
||||||
|
self.username = kwargs.get('username')
|
||||||
|
self.email = kwargs.get('email')
|
||||||
|
self.password_hash = kwargs.get('password_hash')
|
||||||
|
self.first_name = kwargs.get('first_name')
|
||||||
|
self.last_name = kwargs.get('last_name')
|
||||||
|
self.role = kwargs.get('role', 'user')
|
||||||
|
self.is_active = kwargs.get('is_active', True)
|
||||||
|
self.created_at = kwargs.get('created_at')
|
||||||
|
self.updated_at = kwargs.get('updated_at')
|
||||||
|
|
||||||
|
@property
|
||||||
|
def full_name(self) -> str:
|
||||||
|
"""Get user's full name"""
|
||||||
|
if self.first_name and self.last_name:
|
||||||
|
return f"{self.first_name} {self.last_name}"
|
||||||
|
return self.username
|
||||||
|
|
||||||
|
@property
|
||||||
|
def is_admin(self) -> bool:
|
||||||
|
"""Check if user is admin"""
|
||||||
|
return self.role == 'admin'
|
||||||
|
|
||||||
|
def set_password(self, password: str) -> None:
|
||||||
|
"""Hash and set user password"""
|
||||||
|
salt = bcrypt.gensalt()
|
||||||
|
self.password_hash = bcrypt.hashpw(password.encode('utf-8'), salt).decode('utf-8')
|
||||||
|
|
||||||
|
def check_password(self, password: str) -> bool:
|
||||||
|
"""Check if provided password matches hash"""
|
||||||
|
if not self.password_hash:
|
||||||
|
return False
|
||||||
|
return bcrypt.checkpw(password.encode('utf-8'), self.password_hash.encode('utf-8'))
|
||||||
|
|
||||||
|
async def save(self) -> int:
|
||||||
|
"""Save user to database"""
|
||||||
|
if self.id:
|
||||||
|
# Update existing user
|
||||||
|
query = """
|
||||||
|
UPDATE users SET
|
||||||
|
username=%s, email=%s, first_name=%s, last_name=%s,
|
||||||
|
role=%s, is_active=%s, updated_at=NOW()
|
||||||
|
WHERE id=%s
|
||||||
|
"""
|
||||||
|
params = (self.username, self.email, self.first_name, self.last_name,
|
||||||
|
self.role, self.is_active, self.id)
|
||||||
|
await db_manager.execute_update(query, params)
|
||||||
|
return self.id
|
||||||
|
else:
|
||||||
|
# Insert new user
|
||||||
|
query = """
|
||||||
|
INSERT INTO users (username, email, password_hash, first_name, last_name, role, is_active)
|
||||||
|
VALUES (%s, %s, %s, %s, %s, %s, %s)
|
||||||
|
"""
|
||||||
|
params = (self.username, self.email, self.password_hash, self.first_name,
|
||||||
|
self.last_name, self.role, self.is_active)
|
||||||
|
user_id = await db_manager.execute_insert(query, params)
|
||||||
|
self.id = user_id
|
||||||
|
return user_id
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
async def find_by_id(cls, user_id: int) -> Optional['User']:
|
||||||
|
"""Find user by ID"""
|
||||||
|
query = "SELECT * FROM users WHERE id = %s AND is_active = TRUE"
|
||||||
|
results = await db_manager.execute_query(query, (user_id,))
|
||||||
|
if results:
|
||||||
|
return cls(**results[0])
|
||||||
|
return None
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
async def find_by_username(cls, username: str) -> Optional['User']:
|
||||||
|
"""Find user by username"""
|
||||||
|
query = "SELECT * FROM users WHERE username = %s AND is_active = TRUE"
|
||||||
|
results = await db_manager.execute_query(query, (username,))
|
||||||
|
if results:
|
||||||
|
return cls(**results[0])
|
||||||
|
return None
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
async def find_by_email(cls, email: str) -> Optional['User']:
|
||||||
|
"""Find user by email"""
|
||||||
|
query = "SELECT * FROM users WHERE email = %s AND is_active = TRUE"
|
||||||
|
results = await db_manager.execute_query(query, (email,))
|
||||||
|
if results:
|
||||||
|
return cls(**results[0])
|
||||||
|
return None
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
async def authenticate(cls, username_or_email: str, password: str) -> Optional['User']:
|
||||||
|
"""Authenticate user with username/email and password"""
|
||||||
|
# Try to find by username first, then by email
|
||||||
|
user = await cls.find_by_username(username_or_email)
|
||||||
|
if not user:
|
||||||
|
user = await cls.find_by_email(username_or_email)
|
||||||
|
|
||||||
|
if user and user.check_password(password):
|
||||||
|
return user
|
||||||
|
return None
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
async def get_all(cls, limit: int = 50, offset: int = 0) -> List['User']:
|
||||||
|
"""Get all users with pagination"""
|
||||||
|
query = """
|
||||||
|
SELECT * FROM users
|
||||||
|
ORDER BY created_at DESC
|
||||||
|
LIMIT %s OFFSET %s
|
||||||
|
"""
|
||||||
|
results = await db_manager.execute_query(query, (limit, offset))
|
||||||
|
return [cls(**row) for row in results]
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
async def count(cls) -> int:
|
||||||
|
"""Count total users"""
|
||||||
|
query = "SELECT COUNT(*) as count FROM users WHERE is_active = TRUE"
|
||||||
|
results = await db_manager.execute_query(query)
|
||||||
|
return results[0]['count'] if results else 0
|
||||||
|
|
||||||
|
async def delete(self) -> bool:
|
||||||
|
"""Soft delete user (mark as inactive)"""
|
||||||
|
query = "UPDATE users SET is_active = FALSE WHERE id = %s"
|
||||||
|
affected = await db_manager.execute_update(query, (self.id,))
|
||||||
|
return affected > 0
|
||||||
|
|
||||||
|
def to_dict(self, include_sensitive: bool = False) -> Dict:
|
||||||
|
"""Convert user to dictionary"""
|
||||||
|
data = {
|
||||||
|
'id': self.id,
|
||||||
|
'username': self.username,
|
||||||
|
'email': self.email,
|
||||||
|
'first_name': self.first_name,
|
||||||
|
'last_name': self.last_name,
|
||||||
|
'full_name': self.full_name,
|
||||||
|
'role': self.role,
|
||||||
|
'is_active': self.is_active,
|
||||||
|
'is_admin': self.is_admin,
|
||||||
|
'created_at': self.created_at.isoformat() if self.created_at else None
|
||||||
|
}
|
||||||
|
|
||||||
|
if include_sensitive:
|
||||||
|
data['password_hash'] = self.password_hash
|
||||||
|
|
||||||
|
return data
|
||||||
@@ -1,24 +1,41 @@
|
|||||||
|
# Core Framework
|
||||||
|
Quart==0.20.0
|
||||||
|
Hypercorn==0.17.3
|
||||||
|
|
||||||
|
# Database
|
||||||
|
aiomysql==0.2.0
|
||||||
|
PyMySQL==1.1.0
|
||||||
|
cryptography==41.0.8
|
||||||
|
|
||||||
|
# Authentication
|
||||||
|
bcrypt==4.1.2
|
||||||
|
|
||||||
|
# Utilities
|
||||||
aiofiles==24.1.0
|
aiofiles==24.1.0
|
||||||
annotated-types==0.7.0
|
python-dotenv==1.0.1
|
||||||
blinker==1.9.0
|
Jinja2==3.1.5
|
||||||
|
MarkupSafe==3.0.2
|
||||||
|
Werkzeug==3.1.3
|
||||||
|
|
||||||
|
# Core Dependencies
|
||||||
click==8.1.8
|
click==8.1.8
|
||||||
Flask==3.1.0
|
blinker==1.9.0
|
||||||
|
itsdangerous==2.2.0
|
||||||
|
typing_extensions==4.12.2
|
||||||
|
|
||||||
|
# HTTP/Network
|
||||||
h11==0.14.0
|
h11==0.14.0
|
||||||
h2==4.1.0
|
h2==4.1.0
|
||||||
hpack==4.0.0
|
hpack==4.0.0
|
||||||
Hypercorn==0.17.3
|
|
||||||
hyperframe==6.0.1
|
hyperframe==6.0.1
|
||||||
itsdangerous==2.2.0
|
|
||||||
Jinja2==3.1.5
|
|
||||||
MarkupSafe==3.0.2
|
|
||||||
priority==2.0.0
|
priority==2.0.0
|
||||||
|
wsproto==1.2.0
|
||||||
|
httpx==0.27.0
|
||||||
|
|
||||||
|
# Optional
|
||||||
|
Flask==3.1.0
|
||||||
pydantic==2.10.4
|
pydantic==2.10.4
|
||||||
pydantic-settings==2.7.1
|
pydantic-settings==2.7.1
|
||||||
pydantic_core==2.27.2
|
pydantic_core==2.27.2
|
||||||
python-dotenv==1.0.1
|
annotated-types==0.7.0
|
||||||
Quart==0.20.0
|
|
||||||
typing_extensions==4.12.2
|
|
||||||
Werkzeug==3.1.3
|
|
||||||
wsproto==1.2.0
|
|
||||||
httpx==0.27.0
|
|
||||||
Sphinx==8.2.3
|
Sphinx==8.2.3
|
||||||
|
|||||||
123
routes/auth.py
Normal file
123
routes/auth.py
Normal file
@@ -0,0 +1,123 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
# Authentication Routes
|
||||||
|
|
||||||
|
from quart import Blueprint, request, render_template, redirect, url_for, session, flash
|
||||||
|
from models.user import User
|
||||||
|
from utils.auth import login_user, logout_user, get_current_user
|
||||||
|
from utils.validators import validate_email, validate_password, validate_username
|
||||||
|
from utils.helpers import flash_message
|
||||||
|
|
||||||
|
auth_bp = Blueprint('auth', __name__, url_prefix='/auth')
|
||||||
|
|
||||||
|
@auth_bp.route('/login', methods=['GET', 'POST'])
|
||||||
|
async def login():
|
||||||
|
"""Login page"""
|
||||||
|
if request.method == 'GET':
|
||||||
|
return await render_template('auth/login.html')
|
||||||
|
|
||||||
|
form_data = await request.form
|
||||||
|
username_or_email = form_data.get('username', '').strip()
|
||||||
|
password = form_data.get('password', '')
|
||||||
|
|
||||||
|
if not username_or_email or not password:
|
||||||
|
flash_message('Username/Email e password sono richiesti', 'error')
|
||||||
|
return await render_template('auth/login.html')
|
||||||
|
|
||||||
|
# Authenticate user
|
||||||
|
user = await User.authenticate(username_or_email, password)
|
||||||
|
|
||||||
|
if user:
|
||||||
|
login_user(user)
|
||||||
|
flash_message(f'Benvenuto, {user.full_name}!', 'success')
|
||||||
|
|
||||||
|
# Redirect to dashboard if admin, home otherwise
|
||||||
|
if user.is_admin:
|
||||||
|
return redirect(url_for('dashboard.index'))
|
||||||
|
else:
|
||||||
|
return redirect(url_for('home.index'))
|
||||||
|
else:
|
||||||
|
flash_message('Credenziali non valide', 'error')
|
||||||
|
return await render_template('auth/login.html')
|
||||||
|
|
||||||
|
@auth_bp.route('/register', methods=['GET', 'POST'])
|
||||||
|
async def register():
|
||||||
|
"""Registration page"""
|
||||||
|
if request.method == 'GET':
|
||||||
|
return await render_template('auth/register.html')
|
||||||
|
|
||||||
|
form_data = await request.form
|
||||||
|
username = form_data.get('username', '').strip()
|
||||||
|
email = form_data.get('email', '').strip()
|
||||||
|
password = form_data.get('password', '')
|
||||||
|
confirm_password = form_data.get('confirm_password', '')
|
||||||
|
first_name = form_data.get('first_name', '').strip()
|
||||||
|
last_name = form_data.get('last_name', '').strip()
|
||||||
|
|
||||||
|
errors = {}
|
||||||
|
|
||||||
|
# Validate inputs
|
||||||
|
is_valid, error = validate_username(username)
|
||||||
|
if not is_valid:
|
||||||
|
errors['username'] = error
|
||||||
|
|
||||||
|
is_valid, error = validate_email(email)
|
||||||
|
if not is_valid:
|
||||||
|
errors['email'] = error
|
||||||
|
|
||||||
|
is_valid, error = validate_password(password)
|
||||||
|
if not is_valid:
|
||||||
|
errors['password'] = error
|
||||||
|
|
||||||
|
if password != confirm_password:
|
||||||
|
errors['confirm_password'] = 'Le password non coincidono'
|
||||||
|
|
||||||
|
# Check if user already exists
|
||||||
|
if not errors:
|
||||||
|
existing_user = await User.find_by_username(username)
|
||||||
|
if existing_user:
|
||||||
|
errors['username'] = 'Username già in uso'
|
||||||
|
|
||||||
|
existing_email = await User.find_by_email(email)
|
||||||
|
if existing_email:
|
||||||
|
errors['email'] = 'Email già registrata'
|
||||||
|
|
||||||
|
if errors:
|
||||||
|
for field, error in errors.items():
|
||||||
|
flash_message(error, 'error')
|
||||||
|
return await render_template('auth/register.html')
|
||||||
|
|
||||||
|
# Create new user
|
||||||
|
user = User(
|
||||||
|
username=username,
|
||||||
|
email=email,
|
||||||
|
first_name=first_name,
|
||||||
|
last_name=last_name,
|
||||||
|
role='user' # First user can be manually promoted to admin
|
||||||
|
)
|
||||||
|
user.set_password(password)
|
||||||
|
|
||||||
|
try:
|
||||||
|
await user.save()
|
||||||
|
flash_message('Registrazione completata! Ora puoi effettuare il login.', 'success')
|
||||||
|
return redirect(url_for('auth.login'))
|
||||||
|
except Exception as e:
|
||||||
|
flash_message('Errore durante la registrazione. Riprova.', 'error')
|
||||||
|
return await render_template('auth/register.html')
|
||||||
|
|
||||||
|
@auth_bp.route('/logout')
|
||||||
|
async def logout():
|
||||||
|
"""Logout user"""
|
||||||
|
logout_user()
|
||||||
|
flash_message('Logout effettuato con successo', 'success')
|
||||||
|
return redirect(url_for('home.index'))
|
||||||
|
|
||||||
|
@auth_bp.route('/profile')
|
||||||
|
async def profile():
|
||||||
|
"""User profile page"""
|
||||||
|
user = await get_current_user()
|
||||||
|
if not user:
|
||||||
|
return redirect(url_for('auth.login'))
|
||||||
|
|
||||||
|
return await render_template('auth/profile.html', user=user)
|
||||||
218
routes/dashboard.py
Normal file
218
routes/dashboard.py
Normal file
@@ -0,0 +1,218 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
# Dashboard Routes (Admin)
|
||||||
|
|
||||||
|
from quart import Blueprint, request, render_template, redirect, url_for, jsonify
|
||||||
|
from models.user import User
|
||||||
|
from models.project import Project
|
||||||
|
from models.category import Category
|
||||||
|
from utils.auth import admin_required, get_current_user
|
||||||
|
from utils.helpers import flash_message, generate_slug, calculate_pagination
|
||||||
|
from utils.validators import validate_project_data
|
||||||
|
|
||||||
|
dashboard_bp = Blueprint('dashboard', __name__, url_prefix='/dashboard')
|
||||||
|
|
||||||
|
@dashboard_bp.route('/')
|
||||||
|
@admin_required
|
||||||
|
async def index():
|
||||||
|
"""Dashboard home"""
|
||||||
|
current_user = await get_current_user()
|
||||||
|
|
||||||
|
# Get statistics
|
||||||
|
stats = {
|
||||||
|
'total_users': await User.count(),
|
||||||
|
'total_projects': await Project.count(published_only=False),
|
||||||
|
'published_projects': await Project.count(published_only=True),
|
||||||
|
'featured_projects': len(await Project.get_featured())
|
||||||
|
}
|
||||||
|
|
||||||
|
# Get recent projects
|
||||||
|
recent_projects = await Project.get_all(published_only=False, limit=5)
|
||||||
|
|
||||||
|
return await render_template('dashboard/index.html',
|
||||||
|
user=current_user,
|
||||||
|
stats=stats,
|
||||||
|
recent_projects=recent_projects)
|
||||||
|
|
||||||
|
@dashboard_bp.route('/projects')
|
||||||
|
@admin_required
|
||||||
|
async def projects():
|
||||||
|
"""Projects management"""
|
||||||
|
page = int(request.args.get('page', 1))
|
||||||
|
per_page = 10
|
||||||
|
|
||||||
|
# Get projects with pagination
|
||||||
|
projects = await Project.get_all(published_only=False, limit=per_page, offset=(page-1)*per_page)
|
||||||
|
total_projects = await Project.count(published_only=False)
|
||||||
|
|
||||||
|
pagination = calculate_pagination(total_projects, page, per_page)
|
||||||
|
|
||||||
|
return await render_template('dashboard/projects.html',
|
||||||
|
projects=projects,
|
||||||
|
pagination=pagination)
|
||||||
|
|
||||||
|
@dashboard_bp.route('/projects/new', methods=['GET', 'POST'])
|
||||||
|
@admin_required
|
||||||
|
async def new_project():
|
||||||
|
"""Create new project"""
|
||||||
|
if request.method == 'GET':
|
||||||
|
categories = await Category.get_all()
|
||||||
|
return await render_template('dashboard/project_form.html',
|
||||||
|
project=None,
|
||||||
|
categories=categories,
|
||||||
|
action='create')
|
||||||
|
|
||||||
|
form_data = await request.form
|
||||||
|
data = {
|
||||||
|
'title': form_data.get('title', '').strip(),
|
||||||
|
'description': form_data.get('description', '').strip(),
|
||||||
|
'content': form_data.get('content', '').strip(),
|
||||||
|
'github_url': form_data.get('github_url', '').strip(),
|
||||||
|
'demo_url': form_data.get('demo_url', '').strip(),
|
||||||
|
'image_url': form_data.get('image_url', '').strip(),
|
||||||
|
'technologies': form_data.getlist('technologies'),
|
||||||
|
'category_id': int(form_data.get('category_id')) if form_data.get('category_id') else None,
|
||||||
|
'is_featured': bool(form_data.get('is_featured')),
|
||||||
|
'is_published': bool(form_data.get('is_published'))
|
||||||
|
}
|
||||||
|
|
||||||
|
# Validate data
|
||||||
|
is_valid, errors = validate_project_data(data)
|
||||||
|
|
||||||
|
if not is_valid:
|
||||||
|
for field, error in errors.items():
|
||||||
|
flash_message(error, 'error')
|
||||||
|
categories = await Category.get_all()
|
||||||
|
return await render_template('dashboard/project_form.html',
|
||||||
|
project=data,
|
||||||
|
categories=categories,
|
||||||
|
action='create')
|
||||||
|
|
||||||
|
# Create project
|
||||||
|
current_user = await get_current_user()
|
||||||
|
project = Project(
|
||||||
|
title=data['title'],
|
||||||
|
slug=generate_slug(data['title']),
|
||||||
|
description=data['description'],
|
||||||
|
content=data['content'],
|
||||||
|
github_url=data['github_url'],
|
||||||
|
demo_url=data['demo_url'],
|
||||||
|
image_url=data['image_url'],
|
||||||
|
technologies=data['technologies'],
|
||||||
|
category_id=data['category_id'],
|
||||||
|
is_featured=data['is_featured'],
|
||||||
|
is_published=data['is_published'],
|
||||||
|
created_by=current_user.id
|
||||||
|
)
|
||||||
|
|
||||||
|
try:
|
||||||
|
await project.save()
|
||||||
|
flash_message('Progetto creato con successo!', 'success')
|
||||||
|
return redirect(url_for('dashboard.projects'))
|
||||||
|
except Exception as e:
|
||||||
|
flash_message('Errore durante la creazione del progetto', 'error')
|
||||||
|
categories = await Category.get_all()
|
||||||
|
return await render_template('dashboard/project_form.html',
|
||||||
|
project=data,
|
||||||
|
categories=categories,
|
||||||
|
action='create')
|
||||||
|
|
||||||
|
@dashboard_bp.route('/projects/<int:project_id>/edit', methods=['GET', 'POST'])
|
||||||
|
@admin_required
|
||||||
|
async def edit_project(project_id):
|
||||||
|
"""Edit project"""
|
||||||
|
project = await Project.find_by_id(project_id)
|
||||||
|
if not project:
|
||||||
|
flash_message('Progetto non trovato', 'error')
|
||||||
|
return redirect(url_for('dashboard.projects'))
|
||||||
|
|
||||||
|
if request.method == 'GET':
|
||||||
|
categories = await Category.get_all()
|
||||||
|
return await render_template('dashboard/project_form.html',
|
||||||
|
project=project,
|
||||||
|
categories=categories,
|
||||||
|
action='edit')
|
||||||
|
|
||||||
|
form_data = await request.form
|
||||||
|
data = {
|
||||||
|
'title': form_data.get('title', '').strip(),
|
||||||
|
'description': form_data.get('description', '').strip(),
|
||||||
|
'content': form_data.get('content', '').strip(),
|
||||||
|
'github_url': form_data.get('github_url', '').strip(),
|
||||||
|
'demo_url': form_data.get('demo_url', '').strip(),
|
||||||
|
'image_url': form_data.get('image_url', '').strip(),
|
||||||
|
'technologies': form_data.getlist('technologies'),
|
||||||
|
'category_id': int(form_data.get('category_id')) if form_data.get('category_id') else None,
|
||||||
|
'is_featured': bool(form_data.get('is_featured')),
|
||||||
|
'is_published': bool(form_data.get('is_published'))
|
||||||
|
}
|
||||||
|
|
||||||
|
# Validate data
|
||||||
|
is_valid, errors = validate_project_data(data)
|
||||||
|
|
||||||
|
if not is_valid:
|
||||||
|
for field, error in errors.items():
|
||||||
|
flash_message(error, 'error')
|
||||||
|
categories = await Category.get_all()
|
||||||
|
return await render_template('dashboard/project_form.html',
|
||||||
|
project=project,
|
||||||
|
categories=categories,
|
||||||
|
action='edit')
|
||||||
|
|
||||||
|
# Update project
|
||||||
|
project.title = data['title']
|
||||||
|
project.slug = generate_slug(data['title'])
|
||||||
|
project.description = data['description']
|
||||||
|
project.content = data['content']
|
||||||
|
project.github_url = data['github_url']
|
||||||
|
project.demo_url = data['demo_url']
|
||||||
|
project.image_url = data['image_url']
|
||||||
|
project.technologies = data['technologies']
|
||||||
|
project.category_id = data['category_id']
|
||||||
|
project.is_featured = data['is_featured']
|
||||||
|
project.is_published = data['is_published']
|
||||||
|
|
||||||
|
try:
|
||||||
|
await project.save()
|
||||||
|
flash_message('Progetto aggiornato con successo!', 'success')
|
||||||
|
return redirect(url_for('dashboard.projects'))
|
||||||
|
except Exception as e:
|
||||||
|
flash_message('Errore durante l\'aggiornamento del progetto', 'error')
|
||||||
|
categories = await Category.get_all()
|
||||||
|
return await render_template('dashboard/project_form.html',
|
||||||
|
project=project,
|
||||||
|
categories=categories,
|
||||||
|
action='edit')
|
||||||
|
|
||||||
|
@dashboard_bp.route('/projects/<int:project_id>/delete', methods=['POST'])
|
||||||
|
@admin_required
|
||||||
|
async def delete_project(project_id):
|
||||||
|
"""Delete project"""
|
||||||
|
project = await Project.find_by_id(project_id)
|
||||||
|
if not project:
|
||||||
|
return jsonify({'error': 'Progetto non trovato'}), 404
|
||||||
|
|
||||||
|
try:
|
||||||
|
await project.delete()
|
||||||
|
flash_message('Progetto eliminato con successo!', 'success')
|
||||||
|
return redirect(url_for('dashboard.projects'))
|
||||||
|
except Exception as e:
|
||||||
|
flash_message('Errore durante l\'eliminazione del progetto', 'error')
|
||||||
|
return redirect(url_for('dashboard.projects'))
|
||||||
|
|
||||||
|
@dashboard_bp.route('/users')
|
||||||
|
@admin_required
|
||||||
|
async def users():
|
||||||
|
"""Users management"""
|
||||||
|
page = int(request.args.get('page', 1))
|
||||||
|
per_page = 10
|
||||||
|
|
||||||
|
users = await User.get_all(limit=per_page, offset=(page-1)*per_page)
|
||||||
|
total_users = await User.count()
|
||||||
|
|
||||||
|
pagination = calculate_pagination(total_users, page, per_page)
|
||||||
|
|
||||||
|
return await render_template('dashboard/users.html',
|
||||||
|
users=users,
|
||||||
|
pagination=pagination)
|
||||||
@@ -2,11 +2,56 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
# Copyright Hersel Giannella
|
# Copyright Hersel Giannella
|
||||||
|
# Home Routes
|
||||||
|
|
||||||
from quart import Blueprint, render_template
|
from quart import Blueprint, render_template
|
||||||
|
from models.project import Project
|
||||||
|
from models.settings import Settings
|
||||||
|
|
||||||
route_home = Blueprint('route_home', __name__)
|
# Blueprint with correct name
|
||||||
|
home_bp = Blueprint('home', __name__)
|
||||||
|
|
||||||
@route_home.route('/')
|
@home_bp.route('/')
|
||||||
async def home():
|
async def index():
|
||||||
return await render_template('index.html')
|
"""Homepage with featured projects"""
|
||||||
|
# Get featured projects
|
||||||
|
featured_projects = await Project.get_featured(limit=6)
|
||||||
|
|
||||||
|
# Get site settings
|
||||||
|
site_name = await Settings.get('site_name', 'Hersel.it')
|
||||||
|
site_description = await Settings.get('site_description', 'Portfolio personale di Hersel Giannella')
|
||||||
|
|
||||||
|
return await render_template('home/index.html',
|
||||||
|
featured_projects=featured_projects,
|
||||||
|
site_name=site_name,
|
||||||
|
site_description=site_description)
|
||||||
|
|
||||||
|
@home_bp.route('/progetti')
|
||||||
|
async def projects():
|
||||||
|
"""Projects page"""
|
||||||
|
# Get all published projects
|
||||||
|
projects = await Project.get_all(published_only=True, limit=50)
|
||||||
|
|
||||||
|
return await render_template('home/projects.html', projects=projects)
|
||||||
|
|
||||||
|
@home_bp.route('/progetto/<slug>')
|
||||||
|
async def project_detail(slug):
|
||||||
|
"""Single project page"""
|
||||||
|
project = await Project.find_by_slug(slug)
|
||||||
|
if not project:
|
||||||
|
return await render_template('errors/404.html'), 404
|
||||||
|
|
||||||
|
return await render_template('home/project_detail.html', project=project)
|
||||||
|
|
||||||
|
@home_bp.route('/about')
|
||||||
|
async def about():
|
||||||
|
"""About page"""
|
||||||
|
return await render_template('home/about.html')
|
||||||
|
|
||||||
|
@home_bp.route('/contatti')
|
||||||
|
async def contact():
|
||||||
|
"""Contact page"""
|
||||||
|
return await render_template('home/contact.html')
|
||||||
|
|
||||||
|
# Keep backward compatibility
|
||||||
|
route_home = home_bp
|
||||||
|
|||||||
62
templates/auth/login.html
Normal file
62
templates/auth/login.html
Normal file
@@ -0,0 +1,62 @@
|
|||||||
|
{% extends "base.html" %}
|
||||||
|
|
||||||
|
{% block title %}Login - Hersel.it{% endblock %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
<div class="container mt-5">
|
||||||
|
<div class="row justify-content-center">
|
||||||
|
<div class="col-md-6 col-lg-5">
|
||||||
|
<div class="card shadow">
|
||||||
|
<div class="card-body p-5">
|
||||||
|
<div class="text-center mb-4">
|
||||||
|
<h2 class="card-title">Accedi</h2>
|
||||||
|
<p class="text-muted">Benvenuto su Hersel.it</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<form method="POST">
|
||||||
|
<div class="mb-3">
|
||||||
|
<label for="username" class="form-label">Username o Email</label>
|
||||||
|
<div class="input-group">
|
||||||
|
<span class="input-group-text">
|
||||||
|
<i class="bi bi-person"></i>
|
||||||
|
</span>
|
||||||
|
<input type="text" class="form-control" id="username" name="username" required>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="mb-3">
|
||||||
|
<label for="password" class="form-label">Password</label>
|
||||||
|
<div class="input-group">
|
||||||
|
<span class="input-group-text">
|
||||||
|
<i class="bi bi-lock"></i>
|
||||||
|
</span>
|
||||||
|
<input type="password" class="form-control" id="password" name="password" required>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="mb-3 form-check">
|
||||||
|
<input type="checkbox" class="form-check-input" id="remember" name="remember">
|
||||||
|
<label class="form-check-label" for="remember">
|
||||||
|
Ricordami
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="d-grid">
|
||||||
|
<button type="submit" class="btn btn-primary btn-lg">
|
||||||
|
<i class="bi bi-box-arrow-in-right"></i> Accedi
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
<div class="text-center mt-4">
|
||||||
|
<p class="mb-0">
|
||||||
|
Non hai un account?
|
||||||
|
<a href="{{ url_for('auth.register') }}" class="text-decoration-none">Registrati qui</a>
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% endblock %}
|
||||||
100
templates/auth/profile.html
Normal file
100
templates/auth/profile.html
Normal file
@@ -0,0 +1,100 @@
|
|||||||
|
{% extends "base.html" %}
|
||||||
|
|
||||||
|
{% block title %}Il Mio Profilo - Hersel.it{% endblock %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
<div class="container mt-5">
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-lg-4">
|
||||||
|
<div class="card">
|
||||||
|
<div class="card-body text-center">
|
||||||
|
<div class="bg-primary bg-opacity-10 rounded-circle p-4 d-inline-block mb-3">
|
||||||
|
<i class="bi bi-person-circle display-3 text-primary"></i>
|
||||||
|
</div>
|
||||||
|
<h4>{{ user.full_name }}</h4>
|
||||||
|
<p class="text-muted">@{{ user.username }}</p>
|
||||||
|
{% if user.is_admin %}
|
||||||
|
<span class="badge bg-danger">Amministratore</span>
|
||||||
|
{% else %}
|
||||||
|
<span class="badge bg-primary">Utente</span>
|
||||||
|
{% endif %}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="col-lg-8">
|
||||||
|
<div class="card">
|
||||||
|
<div class="card-header">
|
||||||
|
<h5 class="mb-0">Informazioni Profilo</h5>
|
||||||
|
</div>
|
||||||
|
<div class="card-body">
|
||||||
|
<div class="row mb-3">
|
||||||
|
<div class="col-sm-3">
|
||||||
|
<strong>Username:</strong>
|
||||||
|
</div>
|
||||||
|
<div class="col-sm-9">
|
||||||
|
{{ user.username }}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="row mb-3">
|
||||||
|
<div class="col-sm-3">
|
||||||
|
<strong>Email:</strong>
|
||||||
|
</div>
|
||||||
|
<div class="col-sm-9">
|
||||||
|
{{ user.email }}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="row mb-3">
|
||||||
|
<div class="col-sm-3">
|
||||||
|
<strong>Nome Completo:</strong>
|
||||||
|
</div>
|
||||||
|
<div class="col-sm-9">
|
||||||
|
{{ user.full_name }}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="row mb-3">
|
||||||
|
<div class="col-sm-3">
|
||||||
|
<strong>Ruolo:</strong>
|
||||||
|
</div>
|
||||||
|
<div class="col-sm-9">
|
||||||
|
{% if user.is_admin %}
|
||||||
|
<span class="badge bg-danger">Amministratore</span>
|
||||||
|
{% else %}
|
||||||
|
<span class="badge bg-primary">Utente</span>
|
||||||
|
{% endif %}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="row mb-3">
|
||||||
|
<div class="col-sm-3">
|
||||||
|
<strong>Registrato il:</strong>
|
||||||
|
</div>
|
||||||
|
<div class="col-sm-9">
|
||||||
|
{{ user.created_at.strftime('%d/%m/%Y alle %H:%M') if user.created_at else 'N/D' }}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<hr>
|
||||||
|
|
||||||
|
<div class="d-flex gap-2">
|
||||||
|
{% if user.is_admin %}
|
||||||
|
<a href="{{ url_for('dashboard.index') }}" class="btn btn-primary">
|
||||||
|
<i class="bi bi-speedometer2"></i> Dashboard
|
||||||
|
</a>
|
||||||
|
{% endif %}
|
||||||
|
<button class="btn btn-outline-primary" onclick="alert('Funzione in sviluppo')">
|
||||||
|
<i class="bi bi-pencil"></i> Modifica Profilo
|
||||||
|
</button>
|
||||||
|
<a href="{{ url_for('auth.logout') }}" class="btn btn-outline-danger">
|
||||||
|
<i class="bi bi-box-arrow-right"></i> Logout
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% endblock %}
|
||||||
99
templates/auth/register.html
Normal file
99
templates/auth/register.html
Normal file
@@ -0,0 +1,99 @@
|
|||||||
|
{% extends "base.html" %}
|
||||||
|
|
||||||
|
{% block title %}Registrazione - Hersel.it{% endblock %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
<div class="container mt-5">
|
||||||
|
<div class="row justify-content-center">
|
||||||
|
<div class="col-md-8 col-lg-6">
|
||||||
|
<div class="card shadow">
|
||||||
|
<div class="card-body p-5">
|
||||||
|
<div class="text-center mb-4">
|
||||||
|
<h2 class="card-title">Registrati</h2>
|
||||||
|
<p class="text-muted">Crea il tuo account su Hersel.it</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<form method="POST">
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-md-6">
|
||||||
|
<div class="mb-3">
|
||||||
|
<label for="first_name" class="form-label">Nome</label>
|
||||||
|
<input type="text" class="form-control" id="first_name" name="first_name">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="col-md-6">
|
||||||
|
<div class="mb-3">
|
||||||
|
<label for="last_name" class="form-label">Cognome</label>
|
||||||
|
<input type="text" class="form-control" id="last_name" name="last_name">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="mb-3">
|
||||||
|
<label for="username" class="form-label">Username</label>
|
||||||
|
<div class="input-group">
|
||||||
|
<span class="input-group-text">
|
||||||
|
<i class="bi bi-person"></i>
|
||||||
|
</span>
|
||||||
|
<input type="text" class="form-control" id="username" name="username" required>
|
||||||
|
</div>
|
||||||
|
<div class="form-text">Minimo 3 caratteri, solo lettere, numeri e underscore</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="mb-3">
|
||||||
|
<label for="email" class="form-label">Email</label>
|
||||||
|
<div class="input-group">
|
||||||
|
<span class="input-group-text">
|
||||||
|
<i class="bi bi-envelope"></i>
|
||||||
|
</span>
|
||||||
|
<input type="email" class="form-control" id="email" name="email" required>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="mb-3">
|
||||||
|
<label for="password" class="form-label">Password</label>
|
||||||
|
<div class="input-group">
|
||||||
|
<span class="input-group-text">
|
||||||
|
<i class="bi bi-lock"></i>
|
||||||
|
</span>
|
||||||
|
<input type="password" class="form-control" id="password" name="password" required>
|
||||||
|
</div>
|
||||||
|
<div class="form-text">Minimo 8 caratteri con maiuscola, minuscola e numero</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="mb-3">
|
||||||
|
<label for="confirm_password" class="form-label">Conferma Password</label>
|
||||||
|
<div class="input-group">
|
||||||
|
<span class="input-group-text">
|
||||||
|
<i class="bi bi-lock-fill"></i>
|
||||||
|
</span>
|
||||||
|
<input type="password" class="form-control" id="confirm_password" name="confirm_password" required>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="mb-3 form-check">
|
||||||
|
<input type="checkbox" class="form-check-input" id="terms" name="terms" required>
|
||||||
|
<label class="form-check-label" for="terms">
|
||||||
|
Accetto i <a href="#" class="text-decoration-none">Termini e Condizioni</a>
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="d-grid">
|
||||||
|
<button type="submit" class="btn btn-primary btn-lg">
|
||||||
|
<i class="bi bi-person-plus"></i> Registrati
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
<div class="text-center mt-4">
|
||||||
|
<p class="mb-0">
|
||||||
|
Hai già un account?
|
||||||
|
<a href="{{ url_for('auth.login') }}" class="text-decoration-none">Accedi qui</a>
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% endblock %}
|
||||||
121
templates/base.html
Normal file
121
templates/base.html
Normal file
@@ -0,0 +1,121 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="it">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<title>{% block title %}Hersel.it - Portfolio{% endblock %}</title>
|
||||||
|
|
||||||
|
<!-- Bootstrap CSS -->
|
||||||
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
|
||||||
|
<!-- Bootstrap Icons -->
|
||||||
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.0/font/bootstrap-icons.css" rel="stylesheet">
|
||||||
|
|
||||||
|
{% block extra_head %}{% endblock %}
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<!-- Navigation -->
|
||||||
|
<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
|
||||||
|
<div class="container">
|
||||||
|
<a class="navbar-brand" href="{{ url_for('home.index') }}">
|
||||||
|
<strong>Hersel.it</strong>
|
||||||
|
</a>
|
||||||
|
|
||||||
|
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav">
|
||||||
|
<span class="navbar-toggler-icon"></span>
|
||||||
|
</button>
|
||||||
|
|
||||||
|
<div class="collapse navbar-collapse" id="navbarNav">
|
||||||
|
<ul class="navbar-nav me-auto">
|
||||||
|
<li class="nav-item">
|
||||||
|
<a class="nav-link" href="{{ url_for('home.index') }}">Home</a>
|
||||||
|
</li>
|
||||||
|
<li class="nav-item">
|
||||||
|
<a class="nav-link" href="#progetti">Progetti</a>
|
||||||
|
</li>
|
||||||
|
<li class="nav-item">
|
||||||
|
<a class="nav-link" href="#contatti">Contatti</a>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
<ul class="navbar-nav">
|
||||||
|
{% if session.get('user_id') %}
|
||||||
|
{% if session.get('is_admin') %}
|
||||||
|
<li class="nav-item">
|
||||||
|
<a class="nav-link" href="{{ url_for('dashboard.index') }}">
|
||||||
|
<i class="bi bi-speedometer2"></i> Dashboard
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
{% endif %}
|
||||||
|
<li class="nav-item dropdown">
|
||||||
|
<a class="nav-link dropdown-toggle" href="#" role="button" data-bs-toggle="dropdown">
|
||||||
|
<i class="bi bi-person-circle"></i> {{ session.get('username') }}
|
||||||
|
</a>
|
||||||
|
<ul class="dropdown-menu">
|
||||||
|
<li><a class="dropdown-item" href="{{ url_for('auth.profile') }}">Profilo</a></li>
|
||||||
|
<li><hr class="dropdown-divider"></li>
|
||||||
|
<li><a class="dropdown-item" href="{{ url_for('auth.logout') }}">Logout</a></li>
|
||||||
|
</ul>
|
||||||
|
</li>
|
||||||
|
{% else %}
|
||||||
|
<li class="nav-item">
|
||||||
|
<a class="nav-link" href="{{ url_for('auth.login') }}">Login</a>
|
||||||
|
</li>
|
||||||
|
<li class="nav-item">
|
||||||
|
<a class="nav-link" href="{{ url_for('auth.register') }}">Registrati</a>
|
||||||
|
</li>
|
||||||
|
{% endif %}
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</nav>
|
||||||
|
|
||||||
|
<!-- Flash Messages -->
|
||||||
|
{% with messages = get_flashed_messages(with_categories=true) %}
|
||||||
|
{% if messages %}
|
||||||
|
<div class="container mt-3">
|
||||||
|
{% for category, message in messages %}
|
||||||
|
<div class="alert alert-{{ 'danger' if category == 'error' else 'success' if category == 'success' else 'info' }} alert-dismissible fade show">
|
||||||
|
{{ message }}
|
||||||
|
<button type="button" class="btn-close" data-bs-dismiss="alert"></button>
|
||||||
|
</div>
|
||||||
|
{% endfor %}
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
|
{% endwith %}
|
||||||
|
|
||||||
|
<!-- Main Content -->
|
||||||
|
<main>
|
||||||
|
{% block content %}{% endblock %}
|
||||||
|
</main>
|
||||||
|
|
||||||
|
<!-- Footer -->
|
||||||
|
<footer class="bg-dark text-light py-4 mt-5">
|
||||||
|
<div class="container">
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-md-6">
|
||||||
|
<h5>Hersel Giannella</h5>
|
||||||
|
<p>Developer & Portfolio</p>
|
||||||
|
</div>
|
||||||
|
<div class="col-md-6 text-end">
|
||||||
|
<a href="https://github.com/BluLupo" class="text-light me-3">
|
||||||
|
<i class="bi bi-github"></i> GitHub
|
||||||
|
</a>
|
||||||
|
<a href="mailto:info@hersel.it" class="text-light">
|
||||||
|
<i class="bi bi-envelope"></i> Email
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<hr>
|
||||||
|
<div class="row">
|
||||||
|
<div class="col text-center">
|
||||||
|
<small>© 2024 Hersel.it - Tutti i diritti riservati</small>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</footer>
|
||||||
|
|
||||||
|
<!-- Bootstrap JS -->
|
||||||
|
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
|
||||||
|
{% block extra_scripts %}{% endblock %}
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
110
templates/dashboard/base.html
Normal file
110
templates/dashboard/base.html
Normal file
@@ -0,0 +1,110 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="it">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<title>{% block title %}Dashboard - Hersel.it{% endblock %}</title>
|
||||||
|
|
||||||
|
<!-- Bootstrap CSS -->
|
||||||
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
|
||||||
|
<!-- Bootstrap Icons -->
|
||||||
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.0/font/bootstrap-icons.css" rel="stylesheet">
|
||||||
|
|
||||||
|
<style>
|
||||||
|
.sidebar {
|
||||||
|
min-height: 100vh;
|
||||||
|
background-color: #f8f9fa;
|
||||||
|
}
|
||||||
|
.sidebar .nav-link {
|
||||||
|
color: #333;
|
||||||
|
}
|
||||||
|
.sidebar .nav-link:hover {
|
||||||
|
background-color: #e9ecef;
|
||||||
|
}
|
||||||
|
.sidebar .nav-link.active {
|
||||||
|
background-color: #0d6efd;
|
||||||
|
color: white;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|
||||||
|
{% block extra_head %}{% endblock %}
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div class="container-fluid">
|
||||||
|
<div class="row">
|
||||||
|
<!-- Sidebar -->
|
||||||
|
<nav class="col-md-3 col-lg-2 d-md-block sidebar collapse">
|
||||||
|
<div class="position-sticky pt-3">
|
||||||
|
<div class="text-center mb-4">
|
||||||
|
<a href="{{ url_for('home.index') }}" class="text-decoration-none">
|
||||||
|
<h4 class="text-primary">Hersel.it</h4>
|
||||||
|
</a>
|
||||||
|
<small class="text-muted">Dashboard Admin</small>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<ul class="nav flex-column">
|
||||||
|
<li class="nav-item">
|
||||||
|
<a class="nav-link {{ 'active' if request.endpoint == 'dashboard.index' }}" href="{{ url_for('dashboard.index') }}">
|
||||||
|
<i class="bi bi-speedometer2"></i> Overview
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
<li class="nav-item">
|
||||||
|
<a class="nav-link {{ 'active' if 'project' in request.endpoint }}" href="{{ url_for('dashboard.projects') }}">
|
||||||
|
<i class="bi bi-folder"></i> Progetti
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
<li class="nav-item">
|
||||||
|
<a class="nav-link {{ 'active' if request.endpoint == 'dashboard.users' }}" href="{{ url_for('dashboard.users') }}">
|
||||||
|
<i class="bi bi-people"></i> Utenti
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
<hr>
|
||||||
|
|
||||||
|
<ul class="nav flex-column">
|
||||||
|
<li class="nav-item">
|
||||||
|
<a class="nav-link" href="{{ url_for('home.index') }}">
|
||||||
|
<i class="bi bi-house"></i> Vai al Sito
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
<li class="nav-item">
|
||||||
|
<a class="nav-link" href="{{ url_for('auth.logout') }}">
|
||||||
|
<i class="bi bi-box-arrow-right"></i> Logout
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
</nav>
|
||||||
|
|
||||||
|
<!-- Main Content -->
|
||||||
|
<main class="col-md-9 ms-sm-auto col-lg-10 px-md-4">
|
||||||
|
<div class="d-flex justify-content-between flex-wrap flex-md-nowrap align-items-center pt-3 pb-2 mb-3 border-bottom">
|
||||||
|
<h1 class="h2">{% block page_title %}Dashboard{% endblock %}</h1>
|
||||||
|
<div class="btn-toolbar mb-2 mb-md-0">
|
||||||
|
{% block page_actions %}{% endblock %}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Flash Messages -->
|
||||||
|
{% with messages = get_flashed_messages(with_categories=true) %}
|
||||||
|
{% if messages %}
|
||||||
|
{% for category, message in messages %}
|
||||||
|
<div class="alert alert-{{ 'danger' if category == 'error' else 'success' if category == 'success' else 'info' }} alert-dismissible fade show">
|
||||||
|
{{ message }}
|
||||||
|
<button type="button" class="btn-close" data-bs-dismiss="alert"></button>
|
||||||
|
</div>
|
||||||
|
{% endfor %}
|
||||||
|
{% endif %}
|
||||||
|
{% endwith %}
|
||||||
|
|
||||||
|
{% block content %}{% endblock %}
|
||||||
|
</main>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Bootstrap JS -->
|
||||||
|
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
|
||||||
|
{% block extra_scripts %}{% endblock %}
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
159
templates/dashboard/index.html
Normal file
159
templates/dashboard/index.html
Normal file
@@ -0,0 +1,159 @@
|
|||||||
|
{% extends "dashboard/base.html" %}
|
||||||
|
|
||||||
|
{% block page_title %}Dashboard{% endblock %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-lg-12">
|
||||||
|
<div class="mb-4">
|
||||||
|
<h3>Benvenuto, {{ user.full_name }}!</h3>
|
||||||
|
<p class="text-muted">Ecco una panoramica del tuo portfolio</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Statistics Cards -->
|
||||||
|
<div class="row mb-4">
|
||||||
|
<div class="col-md-3">
|
||||||
|
<div class="card bg-primary text-white">
|
||||||
|
<div class="card-body">
|
||||||
|
<div class="d-flex justify-content-between">
|
||||||
|
<div>
|
||||||
|
<h4>{{ stats.total_projects }}</h4>
|
||||||
|
<p class="mb-0">Progetti Totali</p>
|
||||||
|
</div>
|
||||||
|
<div class="align-self-center">
|
||||||
|
<i class="bi bi-folder fs-1"></i>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="col-md-3">
|
||||||
|
<div class="card bg-success text-white">
|
||||||
|
<div class="card-body">
|
||||||
|
<div class="d-flex justify-content-between">
|
||||||
|
<div>
|
||||||
|
<h4>{{ stats.published_projects }}</h4>
|
||||||
|
<p class="mb-0">Pubblicati</p>
|
||||||
|
</div>
|
||||||
|
<div class="align-self-center">
|
||||||
|
<i class="bi bi-check-circle fs-1"></i>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="col-md-3">
|
||||||
|
<div class="card bg-warning text-white">
|
||||||
|
<div class="card-body">
|
||||||
|
<div class="d-flex justify-content-between">
|
||||||
|
<div>
|
||||||
|
<h4>{{ stats.featured_projects }}</h4>
|
||||||
|
<p class="mb-0">In Evidenza</p>
|
||||||
|
</div>
|
||||||
|
<div class="align-self-center">
|
||||||
|
<i class="bi bi-star fs-1"></i>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="col-md-3">
|
||||||
|
<div class="card bg-info text-white">
|
||||||
|
<div class="card-body">
|
||||||
|
<div class="d-flex justify-content-between">
|
||||||
|
<div>
|
||||||
|
<h4>{{ stats.total_users }}</h4>
|
||||||
|
<p class="mb-0">Utenti</p>
|
||||||
|
</div>
|
||||||
|
<div class="align-self-center">
|
||||||
|
<i class="bi bi-people fs-1"></i>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Recent Projects -->
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-lg-8">
|
||||||
|
<div class="card">
|
||||||
|
<div class="card-header">
|
||||||
|
<h5 class="mb-0">Progetti Recenti</h5>
|
||||||
|
</div>
|
||||||
|
<div class="card-body">
|
||||||
|
{% if recent_projects %}
|
||||||
|
<div class="table-responsive">
|
||||||
|
<table class="table table-sm">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>Titolo</th>
|
||||||
|
<th>Stato</th>
|
||||||
|
<th>Creato</th>
|
||||||
|
<th>Azioni</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
{% for project in recent_projects %}
|
||||||
|
<tr>
|
||||||
|
<td>
|
||||||
|
<strong>{{ project.title }}</strong>
|
||||||
|
{% if project.is_featured %}
|
||||||
|
<span class="badge bg-warning ms-1">Featured</span>
|
||||||
|
{% endif %}
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
{% if project.is_published %}
|
||||||
|
<span class="badge bg-success">Pubblicato</span>
|
||||||
|
{% else %}
|
||||||
|
<span class="badge bg-secondary">Bozza</span>
|
||||||
|
{% endif %}
|
||||||
|
</td>
|
||||||
|
<td>{{ project.created_at.strftime('%d/%m/%Y') if project.created_at else 'N/D' }}</td>
|
||||||
|
<td>
|
||||||
|
<a href="{{ url_for('dashboard.edit_project', project_id=project.id) }}" class="btn btn-sm btn-outline-primary">
|
||||||
|
<i class="bi bi-pencil"></i>
|
||||||
|
</a>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
{% endfor %}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
{% else %}
|
||||||
|
<p class="text-muted">Nessun progetto ancora creato.</p>
|
||||||
|
<a href="{{ url_for('dashboard.new_project') }}" class="btn btn-primary">
|
||||||
|
<i class="bi bi-plus"></i> Crea il primo progetto
|
||||||
|
</a>
|
||||||
|
{% endif %}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="col-lg-4">
|
||||||
|
<div class="card">
|
||||||
|
<div class="card-header">
|
||||||
|
<h5 class="mb-0">Azioni Rapide</h5>
|
||||||
|
</div>
|
||||||
|
<div class="card-body">
|
||||||
|
<div class="d-grid gap-2">
|
||||||
|
<a href="{{ url_for('dashboard.new_project') }}" class="btn btn-primary">
|
||||||
|
<i class="bi bi-plus"></i> Nuovo Progetto
|
||||||
|
</a>
|
||||||
|
<a href="{{ url_for('dashboard.projects') }}" class="btn btn-outline-primary">
|
||||||
|
<i class="bi bi-folder"></i> Gestisci Progetti
|
||||||
|
</a>
|
||||||
|
<a href="{{ url_for('home.index') }}" class="btn btn-outline-secondary">
|
||||||
|
<i class="bi bi-eye"></i> Visualizza Sito
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% endblock %}
|
||||||
149
templates/dashboard/project_form.html
Normal file
149
templates/dashboard/project_form.html
Normal file
@@ -0,0 +1,149 @@
|
|||||||
|
{% extends "dashboard/base.html" %}
|
||||||
|
|
||||||
|
{% block page_title %}
|
||||||
|
{% if action == 'create' %}Nuovo Progetto{% else %}Modifica Progetto{% endif %}
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-lg-8">
|
||||||
|
<div class="card">
|
||||||
|
<div class="card-body">
|
||||||
|
<form method="POST">
|
||||||
|
<div class="mb-3">
|
||||||
|
<label for="title" class="form-label">Titolo *</label>
|
||||||
|
<input type="text" class="form-control" id="title" name="title"
|
||||||
|
value="{{ project.title if project else '' }}" required>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="mb-3">
|
||||||
|
<label for="description" class="form-label">Descrizione Breve</label>
|
||||||
|
<textarea class="form-control" id="description" name="description" rows="3"
|
||||||
|
maxlength="1000">{{ project.description if project else '' }}</textarea>
|
||||||
|
<div class="form-text">Massimo 1000 caratteri</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="mb-3">
|
||||||
|
<label for="content" class="form-label">Contenuto Completo</label>
|
||||||
|
<textarea class="form-control" id="content" name="content" rows="10">{{ project.content if project else '' }}</textarea>
|
||||||
|
<div class="form-text">Supporta HTML di base</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-md-6">
|
||||||
|
<div class="mb-3">
|
||||||
|
<label for="github_url" class="form-label">URL GitHub</label>
|
||||||
|
<input type="url" class="form-control" id="github_url" name="github_url"
|
||||||
|
value="{{ project.github_url if project else '' }}"
|
||||||
|
placeholder="https://github.com/username/repo">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="col-md-6">
|
||||||
|
<div class="mb-3">
|
||||||
|
<label for="demo_url" class="form-label">URL Demo/Live</label>
|
||||||
|
<input type="url" class="form-control" id="demo_url" name="demo_url"
|
||||||
|
value="{{ project.demo_url if project else '' }}"
|
||||||
|
placeholder="https://example.com">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="mb-3">
|
||||||
|
<label for="image_url" class="form-label">URL Immagine</label>
|
||||||
|
<input type="url" class="form-control" id="image_url" name="image_url"
|
||||||
|
value="{{ project.image_url if project else '' }}"
|
||||||
|
placeholder="https://example.com/image.jpg">
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="mb-3">
|
||||||
|
<label for="technologies" class="form-label">Tecnologie</label>
|
||||||
|
<div class="row">
|
||||||
|
{% set common_techs = ['Python', 'JavaScript', 'HTML', 'CSS', 'React', 'Vue.js', 'Node.js', 'MySQL', 'PostgreSQL', 'MongoDB', 'Docker', 'Git', 'Bootstrap', 'jQuery'] %}
|
||||||
|
{% for tech in common_techs %}
|
||||||
|
<div class="col-md-3 col-sm-4 col-6">
|
||||||
|
<div class="form-check">
|
||||||
|
<input class="form-check-input" type="checkbox" name="technologies"
|
||||||
|
value="{{ tech }}" id="tech_{{ loop.index }}"
|
||||||
|
{% if project and tech in project.technologies %}checked{% endif %}>
|
||||||
|
<label class="form-check-label" for="tech_{{ loop.index }}">
|
||||||
|
{{ tech }}
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% endfor %}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-md-6">
|
||||||
|
<div class="mb-3">
|
||||||
|
<label for="category_id" class="form-label">Categoria</label>
|
||||||
|
<select class="form-select" id="category_id" name="category_id">
|
||||||
|
<option value="">Seleziona categoria</option>
|
||||||
|
{% for category in categories %}
|
||||||
|
<option value="{{ category.id }}"
|
||||||
|
{% if project and project.category_id == category.id %}selected{% endif %}>
|
||||||
|
{{ category.name }}
|
||||||
|
</option>
|
||||||
|
{% endfor %}
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="mb-3">
|
||||||
|
<div class="form-check">
|
||||||
|
<input class="form-check-input" type="checkbox" id="is_featured" name="is_featured" value="1"
|
||||||
|
{% if project and project.is_featured %}checked{% endif %}>
|
||||||
|
<label class="form-check-label" for="is_featured">
|
||||||
|
Progetto in evidenza
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-check">
|
||||||
|
<input class="form-check-input" type="checkbox" id="is_published" name="is_published" value="1"
|
||||||
|
{% if not project or project.is_published %}checked{% endif %}>
|
||||||
|
<label class="form-check-label" for="is_published">
|
||||||
|
Pubblica progetto
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="d-flex justify-content-between">
|
||||||
|
<a href="{{ url_for('dashboard.projects') }}" class="btn btn-secondary">
|
||||||
|
<i class="bi bi-arrow-left"></i> Annulla
|
||||||
|
</a>
|
||||||
|
<button type="submit" class="btn btn-primary">
|
||||||
|
<i class="bi bi-check"></i>
|
||||||
|
{% if action == 'create' %}Crea Progetto{% else %}Aggiorna Progetto{% endif %}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="col-lg-4">
|
||||||
|
<div class="card">
|
||||||
|
<div class="card-body">
|
||||||
|
<h6 class="card-title">Suggerimenti</h6>
|
||||||
|
<ul class="list-unstyled small">
|
||||||
|
<li><i class="bi bi-lightbulb text-warning"></i> Un titolo chiaro e descrittivo attira più attenzione</li>
|
||||||
|
<li><i class="bi bi-lightbulb text-warning"></i> La descrizione breve appare nelle anteprime</li>
|
||||||
|
<li><i class="bi bi-lightbulb text-warning"></i> Usa il contenuto completo per dettagli tecnici</li>
|
||||||
|
<li><i class="bi bi-lightbulb text-warning"></i> I progetti "featured" appaiono in homepage</li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{% if project and project.image_url %}
|
||||||
|
<div class="card mt-3">
|
||||||
|
<div class="card-body">
|
||||||
|
<h6 class="card-title">Anteprima Immagine</h6>
|
||||||
|
<img src="{{ project.image_url }}" class="img-fluid rounded" alt="Project preview">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% endblock %}
|
||||||
117
templates/dashboard/projects.html
Normal file
117
templates/dashboard/projects.html
Normal file
@@ -0,0 +1,117 @@
|
|||||||
|
{% extends "dashboard/base.html" %}
|
||||||
|
|
||||||
|
{% block page_title %}Gestione Progetti{% endblock %}
|
||||||
|
|
||||||
|
{% block page_actions %}
|
||||||
|
<a href="{{ url_for('dashboard.new_project') }}" class="btn btn-primary">
|
||||||
|
<i class="bi bi-plus"></i> Nuovo Progetto
|
||||||
|
</a>
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
<div class="card">
|
||||||
|
<div class="card-body">
|
||||||
|
{% if projects %}
|
||||||
|
<div class="table-responsive">
|
||||||
|
<table class="table table-hover">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>Titolo</th>
|
||||||
|
<th>Stato</th>
|
||||||
|
<th>Featured</th>
|
||||||
|
<th>Creato</th>
|
||||||
|
<th>Azioni</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
{% for project in projects %}
|
||||||
|
<tr>
|
||||||
|
<td>
|
||||||
|
<strong>{{ project.title }}</strong>
|
||||||
|
{% if project.description %}
|
||||||
|
<br><small class="text-muted">{{ project.description[:100] }}...</small>
|
||||||
|
{% endif %}
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
{% if project.is_published %}
|
||||||
|
<span class="badge bg-success">Pubblicato</span>
|
||||||
|
{% else %}
|
||||||
|
<span class="badge bg-secondary">Bozza</span>
|
||||||
|
{% endif %}
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
{% if project.is_featured %}
|
||||||
|
<span class="badge bg-warning">Featured</span>
|
||||||
|
{% else %}
|
||||||
|
<span class="text-muted">-</span>
|
||||||
|
{% endif %}
|
||||||
|
</td>
|
||||||
|
<td>{{ project.created_at.strftime('%d/%m/%Y') if project.created_at else 'N/D' }}</td>
|
||||||
|
<td>
|
||||||
|
<div class="btn-group" role="group">
|
||||||
|
<a href="{{ url_for('dashboard.edit_project', project_id=project.id) }}"
|
||||||
|
class="btn btn-sm btn-outline-primary" title="Modifica">
|
||||||
|
<i class="bi bi-pencil"></i>
|
||||||
|
</a>
|
||||||
|
<form method="POST" action="{{ url_for('dashboard.delete_project', project_id=project.id) }}"
|
||||||
|
style="display: inline;"
|
||||||
|
onsubmit="return confirm('Sei sicuro di voler eliminare questo progetto?')">
|
||||||
|
<button type="submit" class="btn btn-sm btn-outline-danger" title="Elimina">
|
||||||
|
<i class="bi bi-trash"></i>
|
||||||
|
</button>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
{% endfor %}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Pagination -->
|
||||||
|
{% if pagination.total_pages > 1 %}
|
||||||
|
<nav aria-label="Pagination">
|
||||||
|
<ul class="pagination justify-content-center">
|
||||||
|
{% if pagination.has_prev %}
|
||||||
|
<li class="page-item">
|
||||||
|
<a class="page-link" href="?page={{ pagination.prev_page }}">Precedente</a>
|
||||||
|
</li>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
{% for page_num in range(1, pagination.total_pages + 1) %}
|
||||||
|
{% if page_num == pagination.page %}
|
||||||
|
<li class="page-item active">
|
||||||
|
<span class="page-link">{{ page_num }}</span>
|
||||||
|
</li>
|
||||||
|
{% elif page_num <= 3 or page_num > pagination.total_pages - 3 or (page_num >= pagination.page - 1 and page_num <= pagination.page + 1) %}
|
||||||
|
<li class="page-item">
|
||||||
|
<a class="page-link" href="?page={{ page_num }}">{{ page_num }}</a>
|
||||||
|
</li>
|
||||||
|
{% elif page_num == 4 or page_num == pagination.total_pages - 3 %}
|
||||||
|
<li class="page-item disabled">
|
||||||
|
<span class="page-link">...</span>
|
||||||
|
</li>
|
||||||
|
{% endif %}
|
||||||
|
{% endfor %}
|
||||||
|
|
||||||
|
{% if pagination.has_next %}
|
||||||
|
<li class="page-item">
|
||||||
|
<a class="page-link" href="?page={{ pagination.next_page }}">Successivo</a>
|
||||||
|
</li>
|
||||||
|
{% endif %}
|
||||||
|
</ul>
|
||||||
|
</nav>
|
||||||
|
{% endif %}
|
||||||
|
{% else %}
|
||||||
|
<div class="text-center py-5">
|
||||||
|
<i class="bi bi-folder2-open display-1 text-muted"></i>
|
||||||
|
<h4 class="mt-3">Nessun progetto ancora</h4>
|
||||||
|
<p class="text-muted">Inizia creando il tuo primo progetto</p>
|
||||||
|
<a href="{{ url_for('dashboard.new_project') }}" class="btn btn-primary">
|
||||||
|
<i class="bi bi-plus"></i> Crea Primo Progetto
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% endblock %}
|
||||||
28
templates/errors/404.html
Normal file
28
templates/errors/404.html
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
{% extends "base.html" %}
|
||||||
|
|
||||||
|
{% block title %}Pagina Non Trovata - Hersel.it{% endblock %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
<div class="container">
|
||||||
|
<div class="row justify-content-center">
|
||||||
|
<div class="col-lg-6 text-center py-5">
|
||||||
|
<div class="py-5">
|
||||||
|
<i class="bi bi-exclamation-triangle-fill display-1 text-warning"></i>
|
||||||
|
<h1 class="display-4 fw-bold mt-4">404</h1>
|
||||||
|
<h2 class="mb-4">Pagina Non Trovata</h2>
|
||||||
|
<p class="lead text-muted mb-4">
|
||||||
|
Spiacente, la pagina che stai cercando non esiste o è stata spostata.
|
||||||
|
</p>
|
||||||
|
<div class="d-flex gap-3 justify-content-center">
|
||||||
|
<a href="{{ url_for('home.index') }}" class="btn btn-primary">
|
||||||
|
<i class="bi bi-house"></i> Torna alla Home
|
||||||
|
</a>
|
||||||
|
<a href="{{ url_for('home.projects') }}" class="btn btn-outline-primary">
|
||||||
|
<i class="bi bi-folder"></i> Vedi i Progetti
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% endblock %}
|
||||||
29
templates/errors/500.html
Normal file
29
templates/errors/500.html
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
{% extends "base.html" %}
|
||||||
|
|
||||||
|
{% block title %}Errore del Server - Hersel.it{% endblock %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
<div class="container">
|
||||||
|
<div class="row justify-content-center">
|
||||||
|
<div class="col-lg-6 text-center py-5">
|
||||||
|
<div class="py-5">
|
||||||
|
<i class="bi bi-exclamation-octagon-fill display-1 text-danger"></i>
|
||||||
|
<h1 class="display-4 fw-bold mt-4">500</h1>
|
||||||
|
<h2 class="mb-4">Errore del Server</h2>
|
||||||
|
<p class="lead text-muted mb-4">
|
||||||
|
Si è verificato un errore interno del server.
|
||||||
|
Il problema è stato segnalato e verrà risolto al più presto.
|
||||||
|
</p>
|
||||||
|
<div class="d-flex gap-3 justify-content-center">
|
||||||
|
<a href="{{ url_for('home.index') }}" class="btn btn-primary">
|
||||||
|
<i class="bi bi-house"></i> Torna alla Home
|
||||||
|
</a>
|
||||||
|
<a href="javascript:history.back()" class="btn btn-outline-primary">
|
||||||
|
<i class="bi bi-arrow-left"></i> Torna Indietro
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% endblock %}
|
||||||
213
templates/home/index.html
Normal file
213
templates/home/index.html
Normal file
@@ -0,0 +1,213 @@
|
|||||||
|
{% extends "base.html" %}
|
||||||
|
|
||||||
|
{% block title %}{{ site_name }} - {{ site_description }}{% endblock %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
<!-- Hero Section -->
|
||||||
|
<section class="bg-primary text-white py-5">
|
||||||
|
<div class="container">
|
||||||
|
<div class="row align-items-center">
|
||||||
|
<div class="col-lg-8">
|
||||||
|
<h1 class="display-4 fw-bold">Ciao, sono Hersel Giannella</h1>
|
||||||
|
<p class="lead mb-4">{{ site_description }}</p>
|
||||||
|
<div class="d-flex gap-3">
|
||||||
|
<a href="#progetti" class="btn btn-light btn-lg">
|
||||||
|
<i class="bi bi-folder"></i> I Miei Progetti
|
||||||
|
</a>
|
||||||
|
<a href="{{ url_for('home.contact') }}" class="btn btn-outline-light btn-lg">
|
||||||
|
<i class="bi bi-envelope"></i> Contattami
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="col-lg-4 text-center">
|
||||||
|
<div class="bg-white bg-opacity-10 rounded-circle p-4 d-inline-block">
|
||||||
|
<i class="bi bi-code-slash display-1"></i>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<!-- Featured Projects Section -->
|
||||||
|
<section id="progetti" class="py-5">
|
||||||
|
<div class="container">
|
||||||
|
<div class="text-center mb-5">
|
||||||
|
<h2 class="fw-bold">Progetti in Evidenza</h2>
|
||||||
|
<p class="text-muted">Alcuni dei miei lavori più interessanti</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{% if featured_projects %}
|
||||||
|
<div class="row g-4">
|
||||||
|
{% for project in featured_projects %}
|
||||||
|
<div class="col-lg-4 col-md-6">
|
||||||
|
<div class="card h-100 shadow-sm hover-card">
|
||||||
|
{% if project.image_url %}
|
||||||
|
<img src="{{ project.image_url }}" class="card-img-top" alt="{{ project.title }}" style="height: 200px; object-fit: cover;">
|
||||||
|
{% else %}
|
||||||
|
<div class="card-img-top bg-light d-flex align-items-center justify-content-center" style="height: 200px;">
|
||||||
|
<i class="bi bi-folder display-4 text-muted"></i>
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
<div class="card-body">
|
||||||
|
<h5 class="card-title">{{ project.title }}</h5>
|
||||||
|
<p class="card-text text-muted">{{ project.description[:100] }}{% if project.description|length > 100 %}...{% endif %}</p>
|
||||||
|
|
||||||
|
{% if project.technologies %}
|
||||||
|
<div class="mb-3">
|
||||||
|
{% for tech in project.technologies[:3] %}
|
||||||
|
<span class="badge bg-secondary me-1">{{ tech }}</span>
|
||||||
|
{% endfor %}
|
||||||
|
{% if project.technologies|length > 3 %}
|
||||||
|
<span class="badge bg-light text-dark">+{{ project.technologies|length - 3 }}</span>
|
||||||
|
{% endif %}
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
<div class="d-flex justify-content-between align-items-center">
|
||||||
|
<div class="btn-group">
|
||||||
|
<a href="{{ url_for('home.project_detail', slug=project.slug) }}" class="btn btn-sm btn-primary">
|
||||||
|
<i class="bi bi-eye"></i> Dettagli
|
||||||
|
</a>
|
||||||
|
{% if project.github_url %}
|
||||||
|
<a href="{{ project.github_url }}" target="_blank" class="btn btn-sm btn-outline-primary">
|
||||||
|
<i class="bi bi-github"></i> GitHub
|
||||||
|
</a>
|
||||||
|
{% endif %}
|
||||||
|
</div>
|
||||||
|
{% if project.demo_url %}
|
||||||
|
<a href="{{ project.demo_url }}" target="_blank" class="btn btn-sm btn-success">
|
||||||
|
<i class="bi bi-box-arrow-up-right"></i> Demo
|
||||||
|
</a>
|
||||||
|
{% endif %}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% endfor %}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="text-center mt-5">
|
||||||
|
<a href="{{ url_for('home.projects') }}" class="btn btn-outline-primary btn-lg">
|
||||||
|
<i class="bi bi-folder"></i> Vedi Tutti i Progetti
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
{% else %}
|
||||||
|
<div class="text-center py-5">
|
||||||
|
<i class="bi bi-folder2-open display-1 text-muted"></i>
|
||||||
|
<h4 class="mt-3">Progetti in arrivo</h4>
|
||||||
|
<p class="text-muted">Sto lavorando su alcuni progetti interessanti!</p>
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<!-- Skills Section -->
|
||||||
|
<section class="bg-light py-5">
|
||||||
|
<div class="container">
|
||||||
|
<div class="text-center mb-5">
|
||||||
|
<h2 class="fw-bold">Le Mie Competenze</h2>
|
||||||
|
<p class="text-muted">Tecnologie e strumenti che utilizzo</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="row g-4">
|
||||||
|
<div class="col-lg-3 col-md-6">
|
||||||
|
<div class="text-center">
|
||||||
|
<div class="bg-primary bg-opacity-10 rounded-circle p-3 d-inline-block mb-3">
|
||||||
|
<i class="bi bi-code-slash fs-1 text-primary"></i>
|
||||||
|
</div>
|
||||||
|
<h5>Backend Development</h5>
|
||||||
|
<p class="text-muted">Python, Quart, Flask, FastAPI</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="col-lg-3 col-md-6">
|
||||||
|
<div class="text-center">
|
||||||
|
<div class="bg-success bg-opacity-10 rounded-circle p-3 d-inline-block mb-3">
|
||||||
|
<i class="bi bi-palette fs-1 text-success"></i>
|
||||||
|
</div>
|
||||||
|
<h5>Frontend Development</h5>
|
||||||
|
<p class="text-muted">HTML, CSS, JavaScript, Bootstrap</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="col-lg-3 col-md-6">
|
||||||
|
<div class="text-center">
|
||||||
|
<div class="bg-warning bg-opacity-10 rounded-circle p-3 d-inline-block mb-3">
|
||||||
|
<i class="bi bi-database fs-1 text-warning"></i>
|
||||||
|
</div>
|
||||||
|
<h5>Database</h5>
|
||||||
|
<p class="text-muted">MySQL, PostgreSQL, MongoDB</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="col-lg-3 col-md-6">
|
||||||
|
<div class="text-center">
|
||||||
|
<div class="bg-info bg-opacity-10 rounded-circle p-3 d-inline-block mb-3">
|
||||||
|
<i class="bi bi-tools fs-1 text-info"></i>
|
||||||
|
</div>
|
||||||
|
<h5>DevOps & Tools</h5>
|
||||||
|
<p class="text-muted">Docker, Git, Linux, CI/CD</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<!-- Contact Section -->
|
||||||
|
<section id="contatti" class="py-5">
|
||||||
|
<div class="container">
|
||||||
|
<div class="text-center mb-5">
|
||||||
|
<h2 class="fw-bold">Parliamo del Tuo Progetto</h2>
|
||||||
|
<p class="text-muted">Sono sempre interessato a nuove opportunità e collaborazioni</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="row justify-content-center">
|
||||||
|
<div class="col-lg-8">
|
||||||
|
<div class="row g-4">
|
||||||
|
<div class="col-md-4 text-center">
|
||||||
|
<div class="bg-primary bg-opacity-10 rounded-circle p-3 d-inline-block mb-3">
|
||||||
|
<i class="bi bi-envelope fs-2 text-primary"></i>
|
||||||
|
</div>
|
||||||
|
<h6>Email</h6>
|
||||||
|
<a href="mailto:info@hersel.it" class="text-decoration-none">info@hersel.it</a>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="col-md-4 text-center">
|
||||||
|
<div class="bg-dark rounded-circle p-3 d-inline-block mb-3">
|
||||||
|
<i class="bi bi-github fs-2 text-white"></i>
|
||||||
|
</div>
|
||||||
|
<h6>GitHub</h6>
|
||||||
|
<a href="https://github.com/BluLupo" target="_blank" class="text-decoration-none">BluLupo</a>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="col-md-4 text-center">
|
||||||
|
<div class="bg-info bg-opacity-10 rounded-circle p-3 d-inline-block mb-3">
|
||||||
|
<i class="bi bi-linkedin fs-2 text-info"></i>
|
||||||
|
</div>
|
||||||
|
<h6>LinkedIn</h6>
|
||||||
|
<a href="#" target="_blank" class="text-decoration-none">Hersel Giannella</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="text-center mt-5">
|
||||||
|
<a href="{{ url_for('home.contact') }}" class="btn btn-primary btn-lg">
|
||||||
|
<i class="bi bi-chat-dots"></i> Inizia una Conversazione
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block extra_head %}
|
||||||
|
<style>
|
||||||
|
.hover-card {
|
||||||
|
transition: transform 0.2s;
|
||||||
|
}
|
||||||
|
.hover-card:hover {
|
||||||
|
transform: translateY(-5px);
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
{% endblock %}
|
||||||
75
templates/home/projects.html
Normal file
75
templates/home/projects.html
Normal file
@@ -0,0 +1,75 @@
|
|||||||
|
{% extends "base.html" %}
|
||||||
|
|
||||||
|
{% block title %}Progetti - Hersel.it{% endblock %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
<div class="container py-5">
|
||||||
|
<div class="text-center mb-5">
|
||||||
|
<h1 class="fw-bold">I Miei Progetti</h1>
|
||||||
|
<p class="lead text-muted">Una raccolta dei lavori che ho realizzato</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{% if projects %}
|
||||||
|
<div class="row g-4">
|
||||||
|
{% for project in projects %}
|
||||||
|
<div class="col-lg-4 col-md-6">
|
||||||
|
<div class="card h-100 shadow-sm">
|
||||||
|
{% if project.image_url %}
|
||||||
|
<img src="{{ project.image_url }}" class="card-img-top" alt="{{ project.title }}" style="height: 200px; object-fit: cover;">
|
||||||
|
{% else %}
|
||||||
|
<div class="card-img-top bg-light d-flex align-items-center justify-content-center" style="height: 200px;">
|
||||||
|
<i class="bi bi-folder display-4 text-muted"></i>
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
<div class="card-body d-flex flex-column">
|
||||||
|
<div class="mb-auto">
|
||||||
|
<h5 class="card-title">{{ project.title }}</h5>
|
||||||
|
<p class="card-text text-muted">{{ project.description[:150] }}{% if project.description|length > 150 %}...{% endif %}</p>
|
||||||
|
|
||||||
|
{% if project.technologies %}
|
||||||
|
<div class="mb-3">
|
||||||
|
{% for tech in project.technologies[:4] %}
|
||||||
|
<span class="badge bg-secondary me-1 mb-1">{{ tech }}</span>
|
||||||
|
{% endfor %}
|
||||||
|
{% if project.technologies|length > 4 %}
|
||||||
|
<span class="badge bg-light text-dark">+{{ project.technologies|length - 4 }}</span>
|
||||||
|
{% endif %}
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="d-flex justify-content-between align-items-center mt-3">
|
||||||
|
<div class="btn-group">
|
||||||
|
<a href="{{ url_for('home.project_detail', slug=project.slug) }}" class="btn btn-sm btn-primary">
|
||||||
|
<i class="bi bi-eye"></i> Dettagli
|
||||||
|
</a>
|
||||||
|
{% if project.github_url %}
|
||||||
|
<a href="{{ project.github_url }}" target="_blank" class="btn btn-sm btn-outline-primary">
|
||||||
|
<i class="bi bi-github"></i> Codice
|
||||||
|
</a>
|
||||||
|
{% endif %}
|
||||||
|
</div>
|
||||||
|
{% if project.demo_url %}
|
||||||
|
<a href="{{ project.demo_url }}" target="_blank" class="btn btn-sm btn-success">
|
||||||
|
<i class="bi bi-box-arrow-up-right"></i> Demo Live
|
||||||
|
</a>
|
||||||
|
{% endif %}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% endfor %}
|
||||||
|
</div>
|
||||||
|
{% else %}
|
||||||
|
<div class="text-center py-5">
|
||||||
|
<i class="bi bi-folder2-open display-1 text-muted"></i>
|
||||||
|
<h4 class="mt-3">Nessun progetto disponibile</h4>
|
||||||
|
<p class="text-muted">Sto lavorando su alcuni progetti interessanti!</p>
|
||||||
|
<a href="{{ url_for('home.index') }}" class="btn btn-primary">
|
||||||
|
<i class="bi bi-arrow-left"></i> Torna alla Home
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
|
</div>
|
||||||
|
{% endblock %}
|
||||||
10
utils/__init__.py
Normal file
10
utils/__init__.py
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
# Utilities Package
|
||||||
|
from .auth import login_required, admin_required, get_current_user
|
||||||
|
from .helpers import flash_message, generate_slug, sanitize_html
|
||||||
|
from .validators import validate_email, validate_password
|
||||||
|
|
||||||
|
__all__ = [
|
||||||
|
'login_required', 'admin_required', 'get_current_user',
|
||||||
|
'flash_message', 'generate_slug', 'sanitize_html',
|
||||||
|
'validate_email', 'validate_password'
|
||||||
|
]
|
||||||
63
utils/auth.py
Normal file
63
utils/auth.py
Normal file
@@ -0,0 +1,63 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
# Authentication Utilities
|
||||||
|
|
||||||
|
from functools import wraps
|
||||||
|
from quart import session, request, redirect, url_for, jsonify
|
||||||
|
from typing import Optional
|
||||||
|
from models.user import User
|
||||||
|
|
||||||
|
def login_required(f):
|
||||||
|
"""Decorator to require login for a route"""
|
||||||
|
@wraps(f)
|
||||||
|
async def decorated_function(*args, **kwargs):
|
||||||
|
if 'user_id' not in session:
|
||||||
|
if request.is_json:
|
||||||
|
return jsonify({'error': 'Login required'}), 401
|
||||||
|
return redirect(url_for('auth.login'))
|
||||||
|
return await f(*args, **kwargs)
|
||||||
|
return decorated_function
|
||||||
|
|
||||||
|
def admin_required(f):
|
||||||
|
"""Decorator to require admin role for a route"""
|
||||||
|
@wraps(f)
|
||||||
|
async def decorated_function(*args, **kwargs):
|
||||||
|
if 'user_id' not in session:
|
||||||
|
if request.is_json:
|
||||||
|
return jsonify({'error': 'Login required'}), 401
|
||||||
|
return redirect(url_for('auth.login'))
|
||||||
|
|
||||||
|
user = await get_current_user()
|
||||||
|
if not user or not user.is_admin:
|
||||||
|
if request.is_json:
|
||||||
|
return jsonify({'error': 'Admin access required'}), 403
|
||||||
|
return redirect(url_for('home.index'))
|
||||||
|
|
||||||
|
return await f(*args, **kwargs)
|
||||||
|
return decorated_function
|
||||||
|
|
||||||
|
async def get_current_user() -> Optional[User]:
|
||||||
|
"""Get the currently logged-in user"""
|
||||||
|
if 'user_id' not in session:
|
||||||
|
return None
|
||||||
|
|
||||||
|
try:
|
||||||
|
user_id = session['user_id']
|
||||||
|
return await User.find_by_id(user_id)
|
||||||
|
except:
|
||||||
|
# Clear invalid session
|
||||||
|
session.pop('user_id', None)
|
||||||
|
return None
|
||||||
|
|
||||||
|
def login_user(user: User):
|
||||||
|
"""Log in a user (set session)"""
|
||||||
|
session['user_id'] = user.id
|
||||||
|
session['username'] = user.username
|
||||||
|
session['is_admin'] = user.is_admin
|
||||||
|
|
||||||
|
def logout_user():
|
||||||
|
"""Log out the current user (clear session)"""
|
||||||
|
session.pop('user_id', None)
|
||||||
|
session.pop('username', None)
|
||||||
|
session.pop('is_admin', None)
|
||||||
74
utils/helpers.py
Normal file
74
utils/helpers.py
Normal file
@@ -0,0 +1,74 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
# Helper Utilities
|
||||||
|
|
||||||
|
import re
|
||||||
|
import html
|
||||||
|
from quart import session
|
||||||
|
from typing import List
|
||||||
|
|
||||||
|
def flash_message(message: str, category: str = 'info'):
|
||||||
|
"""Add a flash message to session"""
|
||||||
|
if 'flash_messages' not in session:
|
||||||
|
session['flash_messages'] = []
|
||||||
|
session['flash_messages'].append({'message': message, 'category': category})
|
||||||
|
|
||||||
|
def get_flash_messages() -> List[dict]:
|
||||||
|
"""Get and clear flash messages from session"""
|
||||||
|
messages = session.pop('flash_messages', [])
|
||||||
|
return messages
|
||||||
|
|
||||||
|
def generate_slug(text: str) -> str:
|
||||||
|
"""Generate URL-friendly slug from text"""
|
||||||
|
# Remove HTML tags
|
||||||
|
text = re.sub(r'<[^>]+>', '', text)
|
||||||
|
# Convert to lowercase and replace spaces/special chars with hyphens
|
||||||
|
slug = re.sub(r'[^\w\s-]', '', text).strip().lower()
|
||||||
|
slug = re.sub(r'[\s_-]+', '-', slug)
|
||||||
|
# Remove leading/trailing hyphens
|
||||||
|
slug = slug.strip('-')
|
||||||
|
return slug
|
||||||
|
|
||||||
|
def sanitize_html(text: str) -> str:
|
||||||
|
"""Basic HTML sanitization"""
|
||||||
|
if not text:
|
||||||
|
return ''
|
||||||
|
# Escape HTML entities
|
||||||
|
return html.escape(text)
|
||||||
|
|
||||||
|
def truncate_text(text: str, max_length: int = 150, suffix: str = '...') -> str:
|
||||||
|
"""Truncate text to specified length"""
|
||||||
|
if not text or len(text) <= max_length:
|
||||||
|
return text
|
||||||
|
return text[:max_length].rsplit(' ', 1)[0] + suffix
|
||||||
|
|
||||||
|
def format_date(date_obj, format_str: str = '%d/%m/%Y') -> str:
|
||||||
|
"""Format datetime object to string"""
|
||||||
|
if not date_obj:
|
||||||
|
return ''
|
||||||
|
return date_obj.strftime(format_str)
|
||||||
|
|
||||||
|
def paginate_query_params(page: int = 1, per_page: int = 10) -> tuple:
|
||||||
|
"""Generate LIMIT and OFFSET for pagination"""
|
||||||
|
if page < 1:
|
||||||
|
page = 1
|
||||||
|
offset = (page - 1) * per_page
|
||||||
|
return per_page, offset
|
||||||
|
|
||||||
|
def calculate_pagination(total_items: int, page: int, per_page: int) -> dict:
|
||||||
|
"""Calculate pagination information"""
|
||||||
|
total_pages = (total_items + per_page - 1) // per_page
|
||||||
|
has_prev = page > 1
|
||||||
|
has_next = page < total_pages
|
||||||
|
|
||||||
|
return {
|
||||||
|
'page': page,
|
||||||
|
'per_page': per_page,
|
||||||
|
'total_pages': total_pages,
|
||||||
|
'total_items': total_items,
|
||||||
|
'has_prev': has_prev,
|
||||||
|
'has_next': has_next,
|
||||||
|
'prev_page': page - 1 if has_prev else None,
|
||||||
|
'next_page': page + 1 if has_next else None
|
||||||
|
}
|
||||||
113
utils/validators.py
Normal file
113
utils/validators.py
Normal file
@@ -0,0 +1,113 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
# Validation Utilities
|
||||||
|
|
||||||
|
import re
|
||||||
|
from typing import Tuple, Optional
|
||||||
|
|
||||||
|
def validate_email(email: str) -> Tuple[bool, Optional[str]]:
|
||||||
|
"""Validate email format"""
|
||||||
|
if not email:
|
||||||
|
return False, "Email è richiesta"
|
||||||
|
|
||||||
|
# Basic email regex pattern
|
||||||
|
pattern = r'^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$'
|
||||||
|
|
||||||
|
if not re.match(pattern, email):
|
||||||
|
return False, "Formato email non valido"
|
||||||
|
|
||||||
|
if len(email) > 100:
|
||||||
|
return False, "Email troppo lunga (max 100 caratteri)"
|
||||||
|
|
||||||
|
return True, None
|
||||||
|
|
||||||
|
def validate_password(password: str) -> Tuple[bool, Optional[str]]:
|
||||||
|
"""Validate password strength"""
|
||||||
|
if not password:
|
||||||
|
return False, "Password è richiesta"
|
||||||
|
|
||||||
|
if len(password) < 8:
|
||||||
|
return False, "Password deve essere almeno 8 caratteri"
|
||||||
|
|
||||||
|
if len(password) > 128:
|
||||||
|
return False, "Password troppo lunga (max 128 caratteri)"
|
||||||
|
|
||||||
|
# Check for at least one uppercase letter
|
||||||
|
if not re.search(r'[A-Z]', password):
|
||||||
|
return False, "Password deve contenere almeno una lettera maiuscola"
|
||||||
|
|
||||||
|
# Check for at least one lowercase letter
|
||||||
|
if not re.search(r'[a-z]', password):
|
||||||
|
return False, "Password deve contenere almeno una lettera minuscola"
|
||||||
|
|
||||||
|
# Check for at least one digit
|
||||||
|
if not re.search(r'\d', password):
|
||||||
|
return False, "Password deve contenere almeno un numero"
|
||||||
|
|
||||||
|
return True, None
|
||||||
|
|
||||||
|
def validate_username(username: str) -> Tuple[bool, Optional[str]]:
|
||||||
|
"""Validate username format"""
|
||||||
|
if not username:
|
||||||
|
return False, "Username è richiesto"
|
||||||
|
|
||||||
|
if len(username) < 3:
|
||||||
|
return False, "Username deve essere almeno 3 caratteri"
|
||||||
|
|
||||||
|
if len(username) > 50:
|
||||||
|
return False, "Username troppo lungo (max 50 caratteri)"
|
||||||
|
|
||||||
|
# Check for valid characters (alphanumeric and underscore)
|
||||||
|
if not re.match(r'^[a-zA-Z0-9_]+$', username):
|
||||||
|
return False, "Username può contenere solo lettere, numeri e underscore"
|
||||||
|
|
||||||
|
return True, None
|
||||||
|
|
||||||
|
def validate_project_data(data: dict) -> Tuple[bool, dict]:
|
||||||
|
"""Validate project data"""
|
||||||
|
errors = {}
|
||||||
|
|
||||||
|
# Title validation
|
||||||
|
if not data.get('title', '').strip():
|
||||||
|
errors['title'] = 'Titolo è richiesto'
|
||||||
|
elif len(data['title']) > 200:
|
||||||
|
errors['title'] = 'Titolo troppo lungo (max 200 caratteri)'
|
||||||
|
|
||||||
|
# Description validation
|
||||||
|
if data.get('description') and len(data['description']) > 1000:
|
||||||
|
errors['description'] = 'Descrizione troppo lunga (max 1000 caratteri)'
|
||||||
|
|
||||||
|
# URL validations
|
||||||
|
url_pattern = r'^https?://[^\s]+$'
|
||||||
|
|
||||||
|
if data.get('github_url') and not re.match(url_pattern, data['github_url']):
|
||||||
|
errors['github_url'] = 'URL GitHub non valido'
|
||||||
|
|
||||||
|
if data.get('demo_url') and not re.match(url_pattern, data['demo_url']):
|
||||||
|
errors['demo_url'] = 'URL Demo non valido'
|
||||||
|
|
||||||
|
if data.get('image_url') and not re.match(url_pattern, data['image_url']):
|
||||||
|
errors['image_url'] = 'URL Immagine non valido'
|
||||||
|
|
||||||
|
return len(errors) == 0, errors
|
||||||
|
|
||||||
|
def validate_post_data(data: dict) -> Tuple[bool, dict]:
|
||||||
|
"""Validate blog post data"""
|
||||||
|
errors = {}
|
||||||
|
|
||||||
|
# Title validation
|
||||||
|
if not data.get('title', '').strip():
|
||||||
|
errors['title'] = 'Titolo è richiesto'
|
||||||
|
elif len(data['title']) > 200:
|
||||||
|
errors['title'] = 'Titolo troppo lungo (max 200 caratteri)'
|
||||||
|
|
||||||
|
# Content validation
|
||||||
|
if not data.get('content', '').strip():
|
||||||
|
errors['content'] = 'Contenuto è richiesto'
|
||||||
|
|
||||||
|
# Excerpt validation
|
||||||
|
if data.get('excerpt') and len(data['excerpt']) > 500:
|
||||||
|
errors['excerpt'] = 'Riassunto troppo lungo (max 500 caratteri)'
|
||||||
|
|
||||||
|
return len(errors) == 0, errors
|
||||||
Reference in New Issue
Block a user