final stage of the app
This commit is contained in:
37
app/__init__.py
Normal file
37
app/__init__.py
Normal file
@@ -0,0 +1,37 @@
|
||||
"""
|
||||
QR Code Manager Flask Application
|
||||
A modern Flask web application for generating and managing QR codes with authentication
|
||||
"""
|
||||
|
||||
import os
|
||||
from flask import Flask
|
||||
from flask_cors import CORS
|
||||
from flask_session import Session
|
||||
from app.utils.auth import init_admin
|
||||
|
||||
def create_app():
|
||||
"""Create and configure the Flask application"""
|
||||
app = Flask(__name__)
|
||||
|
||||
# Configuration
|
||||
app.config['SECRET_KEY'] = os.environ.get('SECRET_KEY', 'your-secret-key-change-in-production')
|
||||
app.config['SESSION_TYPE'] = 'filesystem'
|
||||
app.config['SESSION_PERMANENT'] = False
|
||||
app.config['SESSION_USE_SIGNER'] = True
|
||||
|
||||
# Initialize CORS
|
||||
CORS(app)
|
||||
|
||||
# Initialize session
|
||||
Session(app)
|
||||
|
||||
# Initialize admin user
|
||||
init_admin()
|
||||
|
||||
# Register blueprints
|
||||
from app.routes import main, api, auth
|
||||
app.register_blueprint(main.bp)
|
||||
app.register_blueprint(api.bp, url_prefix='/api')
|
||||
app.register_blueprint(auth.bp)
|
||||
|
||||
return app
|
||||
7
app/routes/__init__.py
Normal file
7
app/routes/__init__.py
Normal file
@@ -0,0 +1,7 @@
|
||||
"""
|
||||
Route modules for QR Code Manager
|
||||
"""
|
||||
|
||||
from . import main, api, auth
|
||||
|
||||
__all__ = ['main', 'api', 'auth']
|
||||
304
app/routes/api.py
Normal file
304
app/routes/api.py
Normal file
@@ -0,0 +1,304 @@
|
||||
"""
|
||||
API routes for QR Code Manager
|
||||
"""
|
||||
|
||||
import os
|
||||
import io
|
||||
import base64
|
||||
import uuid
|
||||
from datetime import datetime
|
||||
from flask import Blueprint, request, jsonify, send_file
|
||||
from app.utils.auth import login_required
|
||||
from app.utils.qr_generator import QRCodeGenerator
|
||||
from app.utils.link_manager import LinkPageManager
|
||||
from app.utils.data_manager import QRDataManager
|
||||
|
||||
bp = Blueprint('api', __name__)
|
||||
|
||||
# Initialize managers
|
||||
qr_generator = QRCodeGenerator()
|
||||
link_manager = LinkPageManager()
|
||||
data_manager = QRDataManager()
|
||||
|
||||
# Configuration for file uploads
|
||||
UPLOAD_FOLDER = 'app/static/qr_codes'
|
||||
LOGOS_FOLDER = 'app/static/logos'
|
||||
os.makedirs(UPLOAD_FOLDER, exist_ok=True)
|
||||
os.makedirs(LOGOS_FOLDER, exist_ok=True)
|
||||
|
||||
@bp.route('/generate', methods=['POST'])
|
||||
@login_required
|
||||
def generate_qr():
|
||||
"""Generate QR code API endpoint"""
|
||||
try:
|
||||
data = request.json
|
||||
|
||||
# Extract QR code content
|
||||
qr_type = data.get('type', 'text')
|
||||
content = data.get('content', '')
|
||||
|
||||
# Process content based on type
|
||||
if qr_type == 'url':
|
||||
qr_content = content if content.startswith(('http://', 'https://')) else f'https://{content}'
|
||||
elif qr_type == 'wifi':
|
||||
wifi_data = data.get('wifi', {})
|
||||
qr_content = f"WIFI:T:{wifi_data.get('security', 'WPA')};S:{wifi_data.get('ssid', '')};P:{wifi_data.get('password', '')};H:{wifi_data.get('hidden', 'false')};;"
|
||||
elif qr_type == 'email':
|
||||
email_data = data.get('email', {})
|
||||
qr_content = f"mailto:{email_data.get('email', '')}?subject={email_data.get('subject', '')}&body={email_data.get('body', '')}"
|
||||
elif qr_type == 'phone':
|
||||
qr_content = f"tel:{content}"
|
||||
elif qr_type == 'sms':
|
||||
sms_data = data.get('sms', {})
|
||||
qr_content = f"smsto:{sms_data.get('phone', '')}:{sms_data.get('message', '')}"
|
||||
elif qr_type == 'vcard':
|
||||
vcard_data = data.get('vcard', {})
|
||||
qr_content = f"""BEGIN:VCARD
|
||||
VERSION:3.0
|
||||
FN:{vcard_data.get('name', '')}
|
||||
ORG:{vcard_data.get('organization', '')}
|
||||
TEL:{vcard_data.get('phone', '')}
|
||||
EMAIL:{vcard_data.get('email', '')}
|
||||
URL:{vcard_data.get('website', '')}
|
||||
END:VCARD"""
|
||||
else: # text
|
||||
qr_content = content
|
||||
|
||||
# Extract styling options
|
||||
settings = {
|
||||
'size': data.get('size', 10),
|
||||
'border': data.get('border', 4),
|
||||
'foreground_color': data.get('foreground_color', '#000000'),
|
||||
'background_color': data.get('background_color', '#FFFFFF'),
|
||||
'style': data.get('style', 'square')
|
||||
}
|
||||
|
||||
# Generate QR code
|
||||
qr_img = qr_generator.generate_qr_code(qr_content, settings)
|
||||
|
||||
# Add logo if provided
|
||||
logo_path = data.get('logo_path')
|
||||
if logo_path and os.path.exists(logo_path):
|
||||
qr_img = qr_generator.add_logo(qr_img, logo_path)
|
||||
|
||||
# Convert to base64
|
||||
img_buffer = io.BytesIO()
|
||||
qr_img.save(img_buffer, format='PNG')
|
||||
img_buffer.seek(0)
|
||||
img_base64 = base64.b64encode(img_buffer.getvalue()).decode()
|
||||
|
||||
# Save QR code record
|
||||
qr_id = data_manager.save_qr_record(qr_type, qr_content, settings, img_base64)
|
||||
|
||||
# Save image file
|
||||
img_path = os.path.join(UPLOAD_FOLDER, f'{qr_id}.png')
|
||||
qr_img.save(img_path)
|
||||
|
||||
return jsonify({
|
||||
'success': True,
|
||||
'qr_id': qr_id,
|
||||
'image_data': f'data:image/png;base64,{img_base64}',
|
||||
'download_url': f'/api/download/{qr_id}'
|
||||
})
|
||||
|
||||
except Exception as e:
|
||||
return jsonify({'success': False, 'error': str(e)}), 500
|
||||
|
||||
@bp.route('/download/<qr_id>')
|
||||
@login_required
|
||||
def download_qr(qr_id):
|
||||
"""Download QR code"""
|
||||
try:
|
||||
img_path = os.path.join(UPLOAD_FOLDER, f'{qr_id}.png')
|
||||
if os.path.exists(img_path):
|
||||
return send_file(img_path, as_attachment=True, download_name=f'qr_code_{qr_id}.png')
|
||||
else:
|
||||
return jsonify({'error': 'QR code not found'}), 404
|
||||
except Exception as e:
|
||||
return jsonify({'error': str(e)}), 500
|
||||
|
||||
@bp.route('/qr_codes')
|
||||
@login_required
|
||||
def list_qr_codes():
|
||||
"""List all generated QR codes"""
|
||||
return jsonify(data_manager.list_qr_codes())
|
||||
|
||||
@bp.route('/qr_codes/<qr_id>')
|
||||
@login_required
|
||||
def get_qr_code(qr_id):
|
||||
"""Get specific QR code details"""
|
||||
qr_data = data_manager.get_qr_record(qr_id)
|
||||
if qr_data:
|
||||
return jsonify(qr_data)
|
||||
else:
|
||||
return jsonify({'error': 'QR code not found'}), 404
|
||||
|
||||
@bp.route('/qr_codes/<qr_id>', methods=['DELETE'])
|
||||
@login_required
|
||||
def delete_qr_code(qr_id):
|
||||
"""Delete QR code"""
|
||||
try:
|
||||
if data_manager.qr_exists(qr_id):
|
||||
# Remove from database
|
||||
data_manager.delete_qr_record(qr_id)
|
||||
|
||||
# Remove image file
|
||||
img_path = os.path.join(UPLOAD_FOLDER, f'{qr_id}.png')
|
||||
if os.path.exists(img_path):
|
||||
os.remove(img_path)
|
||||
|
||||
return jsonify({'success': True})
|
||||
else:
|
||||
return jsonify({'error': 'QR code not found'}), 404
|
||||
except Exception as e:
|
||||
return jsonify({'error': str(e)}), 500
|
||||
|
||||
@bp.route('/upload_logo', methods=['POST'])
|
||||
@login_required
|
||||
def upload_logo():
|
||||
"""Upload logo for QR code"""
|
||||
try:
|
||||
if 'logo' not in request.files:
|
||||
return jsonify({'error': 'No logo file provided'}), 400
|
||||
|
||||
file = request.files['logo']
|
||||
if file.filename == '':
|
||||
return jsonify({'error': 'No file selected'}), 400
|
||||
|
||||
# Save logo
|
||||
logo_id = str(uuid.uuid4())
|
||||
logo_extension = file.filename.rsplit('.', 1)[1].lower()
|
||||
logo_filename = f'{logo_id}.{logo_extension}'
|
||||
logo_path = os.path.join(LOGOS_FOLDER, logo_filename)
|
||||
file.save(logo_path)
|
||||
|
||||
return jsonify({
|
||||
'success': True,
|
||||
'logo_path': logo_path,
|
||||
'logo_id': logo_id
|
||||
})
|
||||
|
||||
except Exception as e:
|
||||
return jsonify({'error': str(e)}), 500
|
||||
|
||||
# Dynamic Link Pages API Routes
|
||||
|
||||
@bp.route('/create_link_page', methods=['POST'])
|
||||
@login_required
|
||||
def create_link_page():
|
||||
"""Create a new dynamic link page and QR code"""
|
||||
try:
|
||||
data = request.json
|
||||
title = data.get('title', 'My Links')
|
||||
description = data.get('description', 'Collection of useful links')
|
||||
|
||||
# Create the link page
|
||||
page_id = link_manager.create_link_page(title, description)
|
||||
|
||||
# Create QR code pointing to the link page
|
||||
page_url = f"{request.url_root}links/{page_id}"
|
||||
|
||||
settings = {
|
||||
'size': data.get('size', 10),
|
||||
'border': data.get('border', 4),
|
||||
'foreground_color': data.get('foreground_color', '#000000'),
|
||||
'background_color': data.get('background_color', '#FFFFFF'),
|
||||
'style': data.get('style', 'square')
|
||||
}
|
||||
|
||||
# Generate QR code
|
||||
qr_img = qr_generator.generate_qr_code(page_url, settings)
|
||||
|
||||
# Convert to base64
|
||||
img_buffer = io.BytesIO()
|
||||
qr_img.save(img_buffer, format='PNG')
|
||||
img_buffer.seek(0)
|
||||
img_base64 = base64.b64encode(img_buffer.getvalue()).decode()
|
||||
|
||||
# Save QR code record
|
||||
qr_id = data_manager.save_qr_record('link_page', page_url, settings, img_base64, page_id)
|
||||
|
||||
# Save image file
|
||||
img_path = os.path.join(UPLOAD_FOLDER, f'{qr_id}.png')
|
||||
qr_img.save(img_path)
|
||||
|
||||
return jsonify({
|
||||
'success': True,
|
||||
'qr_id': qr_id,
|
||||
'page_id': page_id,
|
||||
'page_url': page_url,
|
||||
'edit_url': f"{request.url_root}edit/{page_id}",
|
||||
'image_data': f'data:image/png;base64,{img_base64}',
|
||||
'download_url': f'/api/download/{qr_id}'
|
||||
})
|
||||
|
||||
except Exception as e:
|
||||
return jsonify({'success': False, 'error': str(e)}), 500
|
||||
|
||||
@bp.route('/link_pages/<page_id>/links', methods=['POST'])
|
||||
@login_required
|
||||
def add_link_to_page(page_id):
|
||||
"""Add a link to a page"""
|
||||
try:
|
||||
data = request.json
|
||||
title = data.get('title', '')
|
||||
url = data.get('url', '')
|
||||
description = data.get('description', '')
|
||||
|
||||
if not title or not url:
|
||||
return jsonify({'error': 'Title and URL are required'}), 400
|
||||
|
||||
success = link_manager.add_link(page_id, title, url, description)
|
||||
|
||||
if success:
|
||||
return jsonify({'success': True})
|
||||
else:
|
||||
return jsonify({'error': 'Page not found'}), 404
|
||||
|
||||
except Exception as e:
|
||||
return jsonify({'error': str(e)}), 500
|
||||
|
||||
@bp.route('/link_pages/<page_id>/links/<link_id>', methods=['PUT'])
|
||||
@login_required
|
||||
def update_link_in_page(page_id, link_id):
|
||||
"""Update a link in a page"""
|
||||
try:
|
||||
data = request.json
|
||||
title = data.get('title')
|
||||
url = data.get('url')
|
||||
description = data.get('description')
|
||||
|
||||
success = link_manager.update_link(page_id, link_id, title, url, description)
|
||||
|
||||
if success:
|
||||
return jsonify({'success': True})
|
||||
else:
|
||||
return jsonify({'error': 'Page or link not found'}), 404
|
||||
|
||||
except Exception as e:
|
||||
return jsonify({'error': str(e)}), 500
|
||||
|
||||
@bp.route('/link_pages/<page_id>/links/<link_id>', methods=['DELETE'])
|
||||
@login_required
|
||||
def delete_link_from_page(page_id, link_id):
|
||||
"""Delete a link from a page"""
|
||||
try:
|
||||
success = link_manager.delete_link(page_id, link_id)
|
||||
|
||||
if success:
|
||||
return jsonify({'success': True})
|
||||
else:
|
||||
return jsonify({'error': 'Page or link not found'}), 404
|
||||
|
||||
except Exception as e:
|
||||
return jsonify({'error': str(e)}), 500
|
||||
|
||||
@bp.route('/link_pages/<page_id>')
|
||||
@login_required
|
||||
def get_link_page(page_id):
|
||||
"""Get link page data"""
|
||||
page_data = link_manager.get_page(page_id)
|
||||
if page_data:
|
||||
return jsonify(page_data)
|
||||
else:
|
||||
return jsonify({'error': 'Page not found'}), 404
|
||||
34
app/routes/auth.py
Normal file
34
app/routes/auth.py
Normal file
@@ -0,0 +1,34 @@
|
||||
"""
|
||||
Authentication routes for QR Code Manager
|
||||
"""
|
||||
|
||||
from flask import Blueprint, request, render_template, session, redirect, url_for, flash
|
||||
from app.utils.auth import get_admin_credentials, verify_password
|
||||
|
||||
bp = Blueprint('auth', __name__)
|
||||
|
||||
@bp.route('/login', methods=['GET', 'POST'])
|
||||
def login():
|
||||
"""Login page"""
|
||||
if request.method == 'POST':
|
||||
username = request.form.get('username')
|
||||
password = request.form.get('password')
|
||||
|
||||
admin_username, admin_password_hash = get_admin_credentials()
|
||||
|
||||
if username == admin_username and verify_password(password, admin_password_hash):
|
||||
session['logged_in'] = True
|
||||
session['username'] = username
|
||||
flash('Successfully logged in!', 'success')
|
||||
return redirect(url_for('main.index'))
|
||||
else:
|
||||
flash('Invalid username or password!', 'error')
|
||||
|
||||
return render_template('login.html')
|
||||
|
||||
@bp.route('/logout')
|
||||
def logout():
|
||||
"""Logout and clear session"""
|
||||
session.clear()
|
||||
flash('You have been logged out!', 'info')
|
||||
return redirect(url_for('auth.login'))
|
||||
46
app/routes/main.py
Normal file
46
app/routes/main.py
Normal file
@@ -0,0 +1,46 @@
|
||||
"""
|
||||
Main routes for QR Code Manager
|
||||
"""
|
||||
|
||||
from flask import Blueprint, render_template
|
||||
from app.utils.auth import login_required
|
||||
from app.utils.link_manager import LinkPageManager
|
||||
|
||||
bp = Blueprint('main', __name__)
|
||||
|
||||
# Initialize manager
|
||||
link_manager = LinkPageManager()
|
||||
|
||||
@bp.route('/')
|
||||
@login_required
|
||||
def index():
|
||||
"""Serve the main page"""
|
||||
return render_template('index.html')
|
||||
|
||||
@bp.route('/links/<page_id>')
|
||||
def view_link_page(page_id):
|
||||
"""Display the public link page"""
|
||||
if not link_manager.page_exists(page_id):
|
||||
return "Page not found", 404
|
||||
|
||||
link_manager.increment_view_count(page_id)
|
||||
page_data = link_manager.get_page(page_id)
|
||||
|
||||
return render_template('link_page.html', page=page_data)
|
||||
|
||||
@bp.route('/edit/<page_id>')
|
||||
@login_required
|
||||
def edit_link_page(page_id):
|
||||
"""Display the edit interface for the link page"""
|
||||
if not link_manager.page_exists(page_id):
|
||||
return "Page not found", 404
|
||||
|
||||
page_data = link_manager.get_page(page_id)
|
||||
return render_template('edit_links.html', page=page_data)
|
||||
|
||||
@bp.route('/health')
|
||||
def health_check():
|
||||
"""Health check endpoint for Docker"""
|
||||
from datetime import datetime
|
||||
from flask import jsonify
|
||||
return jsonify({'status': 'healthy', 'timestamp': datetime.now().isoformat()})
|
||||
454
app/templates/edit_links.html
Normal file
454
app/templates/edit_links.html
Normal file
@@ -0,0 +1,454 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Edit {{ page.title }}</title>
|
||||
<style>
|
||||
* {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
body {
|
||||
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
min-height: 100vh;
|
||||
padding: 20px;
|
||||
}
|
||||
|
||||
.container {
|
||||
max-width: 1000px;
|
||||
margin: 0 auto;
|
||||
background: white;
|
||||
border-radius: 15px;
|
||||
box-shadow: 0 20px 40px rgba(0,0,0,0.1);
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.header {
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
color: white;
|
||||
padding: 30px;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.header h1 {
|
||||
font-size: 2.2em;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
.header p {
|
||||
font-size: 1em;
|
||||
opacity: 0.9;
|
||||
}
|
||||
|
||||
.main-content {
|
||||
display: grid;
|
||||
grid-template-columns: 1fr 1fr;
|
||||
gap: 30px;
|
||||
padding: 30px;
|
||||
}
|
||||
|
||||
.form-section {
|
||||
background: #f8f9fa;
|
||||
padding: 25px;
|
||||
border-radius: 10px;
|
||||
border: 1px solid #e9ecef;
|
||||
}
|
||||
|
||||
.form-section h2 {
|
||||
color: #333;
|
||||
margin-bottom: 20px;
|
||||
font-size: 1.5em;
|
||||
}
|
||||
|
||||
.form-group {
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.form-group label {
|
||||
display: block;
|
||||
margin-bottom: 8px;
|
||||
font-weight: 600;
|
||||
color: #555;
|
||||
}
|
||||
|
||||
.form-group input,
|
||||
.form-group textarea {
|
||||
width: 100%;
|
||||
padding: 12px;
|
||||
border: 2px solid #e9ecef;
|
||||
border-radius: 8px;
|
||||
font-size: 14px;
|
||||
transition: border-color 0.3s;
|
||||
}
|
||||
|
||||
.form-group input:focus,
|
||||
.form-group textarea:focus {
|
||||
outline: none;
|
||||
border-color: #667eea;
|
||||
}
|
||||
|
||||
.form-group textarea {
|
||||
height: 80px;
|
||||
resize: vertical;
|
||||
}
|
||||
|
||||
.btn {
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
color: white;
|
||||
padding: 12px 25px;
|
||||
border: none;
|
||||
border-radius: 8px;
|
||||
font-size: 14px;
|
||||
cursor: pointer;
|
||||
transition: transform 0.2s;
|
||||
margin-right: 10px;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
.btn:hover {
|
||||
transform: translateY(-2px);
|
||||
}
|
||||
|
||||
.btn:disabled {
|
||||
opacity: 0.6;
|
||||
cursor: not-allowed;
|
||||
transform: none;
|
||||
}
|
||||
|
||||
.btn-success {
|
||||
background: linear-gradient(135deg, #28a745 0%, #20c997 100%);
|
||||
}
|
||||
|
||||
.btn-danger {
|
||||
background: linear-gradient(135deg, #dc3545 0%, #fd7e14 100%);
|
||||
}
|
||||
|
||||
.btn-secondary {
|
||||
background: linear-gradient(135deg, #6c757d 0%, #adb5bd 100%);
|
||||
}
|
||||
|
||||
.links-section h2 {
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.link-item {
|
||||
background: white;
|
||||
border: 1px solid #e9ecef;
|
||||
border-radius: 8px;
|
||||
padding: 20px;
|
||||
margin-bottom: 15px;
|
||||
}
|
||||
|
||||
.link-item.editing {
|
||||
border-color: #667eea;
|
||||
}
|
||||
|
||||
.link-display {
|
||||
display: block;
|
||||
}
|
||||
|
||||
.link-edit {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.link-item.editing .link-display {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.link-item.editing .link-edit {
|
||||
display: block;
|
||||
}
|
||||
|
||||
.link-title {
|
||||
font-size: 1.2em;
|
||||
font-weight: 600;
|
||||
color: #333;
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
|
||||
.link-description {
|
||||
color: #666;
|
||||
font-size: 0.9em;
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
|
||||
.link-url {
|
||||
color: #667eea;
|
||||
font-size: 0.9em;
|
||||
word-break: break-all;
|
||||
}
|
||||
|
||||
.link-actions {
|
||||
margin-top: 15px;
|
||||
display: flex;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.btn-small {
|
||||
padding: 8px 15px;
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.empty-state {
|
||||
text-align: center;
|
||||
padding: 40px 20px;
|
||||
color: #666;
|
||||
background: white;
|
||||
border-radius: 8px;
|
||||
border: 1px solid #e9ecef;
|
||||
}
|
||||
|
||||
.empty-state .icon {
|
||||
font-size: 3em;
|
||||
margin-bottom: 15px;
|
||||
opacity: 0.5;
|
||||
}
|
||||
|
||||
.page-actions {
|
||||
background: #f8f9fa;
|
||||
padding: 20px;
|
||||
text-align: center;
|
||||
border-top: 1px solid #e9ecef;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
gap: 15px;
|
||||
}
|
||||
|
||||
.alert {
|
||||
padding: 12px 20px;
|
||||
border-radius: 8px;
|
||||
margin-bottom: 20px;
|
||||
display: none;
|
||||
}
|
||||
|
||||
.alert-success {
|
||||
background: #d4edda;
|
||||
border: 1px solid #c3e6cb;
|
||||
color: #155724;
|
||||
}
|
||||
|
||||
.alert-error {
|
||||
background: #f8d7da;
|
||||
border: 1px solid #f5c6cb;
|
||||
color: #721c24;
|
||||
}
|
||||
|
||||
@media (max-width: 768px) {
|
||||
.main-content {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
|
||||
.page-actions {
|
||||
flex-direction: column;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="container">
|
||||
<div class="header">
|
||||
<h1>✏️ Edit Links</h1>
|
||||
<p>Manage your link collection: {{ page.title }}</p>
|
||||
</div>
|
||||
|
||||
<div class="alert alert-success" id="success-alert">
|
||||
Operation completed successfully!
|
||||
</div>
|
||||
|
||||
<div class="alert alert-error" id="error-alert">
|
||||
An error occurred. Please try again.
|
||||
</div>
|
||||
|
||||
<div class="main-content">
|
||||
<div class="form-section">
|
||||
<h2>Add New Link</h2>
|
||||
<form id="add-link-form">
|
||||
<div class="form-group">
|
||||
<label for="link-title">Title *</label>
|
||||
<input type="text" id="link-title" placeholder="Link title" required>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="link-url">URL *</label>
|
||||
<input type="url" id="link-url" placeholder="https://example.com" required>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="link-description">Description</label>
|
||||
<textarea id="link-description" placeholder="Optional description"></textarea>
|
||||
</div>
|
||||
|
||||
<button type="submit" class="btn btn-success">Add Link</button>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<div class="links-section">
|
||||
<h2>Current Links ({{ page.links|length }})</h2>
|
||||
<div id="links-container">
|
||||
{% if page.links %}
|
||||
{% for link in page.links %}
|
||||
<div class="link-item" data-link-id="{{ link.id }}">
|
||||
<div class="link-display">
|
||||
<div class="link-title">{{ link.title }}</div>
|
||||
{% if link.description %}
|
||||
<div class="link-description">{{ link.description }}</div>
|
||||
{% endif %}
|
||||
<div class="link-url">{{ link.url }}</div>
|
||||
<div class="link-actions">
|
||||
<button class="btn btn-small btn-secondary" onclick="editLink('{{ link.id }}')">Edit</button>
|
||||
<button class="btn btn-small btn-danger" onclick="deleteLink('{{ link.id }}')">Delete</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="link-edit">
|
||||
<div class="form-group">
|
||||
<label>Title</label>
|
||||
<input type="text" class="edit-title" value="{{ link.title }}">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>URL</label>
|
||||
<input type="url" class="edit-url" value="{{ link.url }}">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>Description</label>
|
||||
<textarea class="edit-description">{{ link.description or '' }}</textarea>
|
||||
</div>
|
||||
<div class="link-actions">
|
||||
<button class="btn btn-small btn-success" onclick="saveLink('{{ link.id }}')">Save</button>
|
||||
<button class="btn btn-small btn-secondary" onclick="cancelEdit('{{ link.id }}')">Cancel</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endfor %}
|
||||
{% else %}
|
||||
<div class="empty-state">
|
||||
<div class="icon">📝</div>
|
||||
<h3>No links yet</h3>
|
||||
<p>Add your first link using the form on the left.</p>
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="page-actions">
|
||||
<a href="/links/{{ page.id }}" target="_blank" class="btn">👁️ View Public Page</a>
|
||||
<a href="/" class="btn btn-secondary">🏠 Back to Dashboard</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
const pageId = '{{ page.id }}';
|
||||
|
||||
// Add new link
|
||||
document.getElementById('add-link-form').addEventListener('submit', async function(e) {
|
||||
e.preventDefault();
|
||||
|
||||
const title = document.getElementById('link-title').value;
|
||||
const url = document.getElementById('link-url').value;
|
||||
const description = document.getElementById('link-description').value;
|
||||
|
||||
try {
|
||||
const response = await fetch(`/api/link_pages/${pageId}/links`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify({ title, url, description })
|
||||
});
|
||||
|
||||
const result = await response.json();
|
||||
|
||||
if (result.success) {
|
||||
showAlert('Link added successfully!', 'success');
|
||||
setTimeout(() => location.reload(), 1000);
|
||||
} else {
|
||||
showAlert(result.error || 'Failed to add link', 'error');
|
||||
}
|
||||
} catch (error) {
|
||||
showAlert('Network error occurred', 'error');
|
||||
}
|
||||
});
|
||||
|
||||
// Edit link
|
||||
function editLink(linkId) {
|
||||
const linkItem = document.querySelector(`[data-link-id="${linkId}"]`);
|
||||
linkItem.classList.add('editing');
|
||||
}
|
||||
|
||||
// Cancel edit
|
||||
function cancelEdit(linkId) {
|
||||
const linkItem = document.querySelector(`[data-link-id="${linkId}"]`);
|
||||
linkItem.classList.remove('editing');
|
||||
}
|
||||
|
||||
// Save link
|
||||
async function saveLink(linkId) {
|
||||
const linkItem = document.querySelector(`[data-link-id="${linkId}"]`);
|
||||
const title = linkItem.querySelector('.edit-title').value;
|
||||
const url = linkItem.querySelector('.edit-url').value;
|
||||
const description = linkItem.querySelector('.edit-description').value;
|
||||
|
||||
try {
|
||||
const response = await fetch(`/api/link_pages/${pageId}/links/${linkId}`, {
|
||||
method: 'PUT',
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify({ title, url, description })
|
||||
});
|
||||
|
||||
const result = await response.json();
|
||||
|
||||
if (result.success) {
|
||||
showAlert('Link updated successfully!', 'success');
|
||||
setTimeout(() => location.reload(), 1000);
|
||||
} else {
|
||||
showAlert(result.error || 'Failed to update link', 'error');
|
||||
}
|
||||
} catch (error) {
|
||||
showAlert('Network error occurred', 'error');
|
||||
}
|
||||
}
|
||||
|
||||
// Delete link
|
||||
async function deleteLink(linkId) {
|
||||
if (!confirm('Are you sure you want to delete this link?')) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const response = await fetch(`/api/link_pages/${pageId}/links/${linkId}`, {
|
||||
method: 'DELETE'
|
||||
});
|
||||
|
||||
const result = await response.json();
|
||||
|
||||
if (result.success) {
|
||||
showAlert('Link deleted successfully!', 'success');
|
||||
setTimeout(() => location.reload(), 1000);
|
||||
} else {
|
||||
showAlert(result.error || 'Failed to delete link', 'error');
|
||||
}
|
||||
} catch (error) {
|
||||
showAlert('Network error occurred', 'error');
|
||||
}
|
||||
}
|
||||
|
||||
// Show alert
|
||||
function showAlert(message, type) {
|
||||
const alert = document.getElementById(`${type}-alert`);
|
||||
alert.textContent = message;
|
||||
alert.style.display = 'block';
|
||||
|
||||
setTimeout(() => {
|
||||
alert.style.display = 'none';
|
||||
}, 3000);
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
727
app/templates/index.html
Normal file
727
app/templates/index.html
Normal file
@@ -0,0 +1,727 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>QR Code Manager</title>
|
||||
<style>
|
||||
* {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
body {
|
||||
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
min-height: 100vh;
|
||||
padding: 20px;
|
||||
}
|
||||
|
||||
.container {
|
||||
max-width: 1200px;
|
||||
margin: 0 auto;
|
||||
background: white;
|
||||
border-radius: 15px;
|
||||
box-shadow: 0 20px 40px rgba(0,0,0,0.1);
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.header {
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
color: white;
|
||||
padding: 30px;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.header h1 {
|
||||
font-size: 2.5em;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
.header p {
|
||||
font-size: 1.1em;
|
||||
opacity: 0.9;
|
||||
}
|
||||
|
||||
.main-content {
|
||||
display: grid;
|
||||
grid-template-columns: 1fr 1fr;
|
||||
gap: 30px;
|
||||
padding: 30px;
|
||||
}
|
||||
|
||||
.form-section {
|
||||
background: #f8f9fa;
|
||||
padding: 25px;
|
||||
border-radius: 10px;
|
||||
border: 1px solid #e9ecef;
|
||||
}
|
||||
|
||||
.form-section h2 {
|
||||
color: #333;
|
||||
margin-bottom: 20px;
|
||||
font-size: 1.5em;
|
||||
}
|
||||
|
||||
.form-group {
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.form-group label {
|
||||
display: block;
|
||||
margin-bottom: 8px;
|
||||
font-weight: 600;
|
||||
color: #555;
|
||||
}
|
||||
|
||||
.form-group input,
|
||||
.form-group select,
|
||||
.form-group textarea {
|
||||
width: 100%;
|
||||
padding: 12px;
|
||||
border: 2px solid #e9ecef;
|
||||
border-radius: 8px;
|
||||
font-size: 14px;
|
||||
transition: border-color 0.3s;
|
||||
}
|
||||
|
||||
.form-group input:focus,
|
||||
.form-group select:focus,
|
||||
.form-group textarea:focus {
|
||||
outline: none;
|
||||
border-color: #667eea;
|
||||
}
|
||||
|
||||
.form-group textarea {
|
||||
height: 100px;
|
||||
resize: vertical;
|
||||
}
|
||||
|
||||
.color-inputs {
|
||||
display: grid;
|
||||
grid-template-columns: 1fr 1fr;
|
||||
gap: 15px;
|
||||
}
|
||||
|
||||
.color-input-group {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.color-input-group input[type="color"] {
|
||||
width: 50px;
|
||||
height: 40px;
|
||||
border: none;
|
||||
border-radius: 5px;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.style-selector {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(3, 1fr);
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.style-option {
|
||||
padding: 10px;
|
||||
border: 2px solid #e9ecef;
|
||||
border-radius: 8px;
|
||||
text-align: center;
|
||||
cursor: pointer;
|
||||
transition: all 0.3s;
|
||||
background: white;
|
||||
}
|
||||
|
||||
.style-option:hover {
|
||||
border-color: #667eea;
|
||||
}
|
||||
|
||||
.style-option.active {
|
||||
border-color: #667eea;
|
||||
background: #667eea;
|
||||
color: white;
|
||||
}
|
||||
|
||||
.wifi-fields,
|
||||
.link-page-fields,
|
||||
.email-fields,
|
||||
.sms-fields,
|
||||
.vcard-fields {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.wifi-fields.active,
|
||||
.link-page-fields.active,
|
||||
.email-fields.active,
|
||||
.sms-fields.active,
|
||||
.vcard-fields.active {
|
||||
display: block;
|
||||
}
|
||||
|
||||
.btn {
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
color: white;
|
||||
padding: 12px 30px;
|
||||
border: none;
|
||||
border-radius: 8px;
|
||||
font-size: 16px;
|
||||
cursor: pointer;
|
||||
transition: transform 0.2s;
|
||||
width: 100%;
|
||||
margin-top: 10px;
|
||||
}
|
||||
|
||||
.btn:hover {
|
||||
transform: translateY(-2px);
|
||||
}
|
||||
|
||||
.btn:disabled {
|
||||
opacity: 0.6;
|
||||
cursor: not-allowed;
|
||||
transform: none;
|
||||
}
|
||||
|
||||
.result-section {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.qr-preview {
|
||||
background: white;
|
||||
border: 2px dashed #ddd;
|
||||
border-radius: 10px;
|
||||
padding: 30px;
|
||||
margin-bottom: 20px;
|
||||
min-height: 300px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.qr-preview img {
|
||||
max-width: 100%;
|
||||
max-height: 250px;
|
||||
border-radius: 5px;
|
||||
}
|
||||
|
||||
.qr-preview .placeholder {
|
||||
color: #999;
|
||||
font-size: 1.1em;
|
||||
}
|
||||
|
||||
.download-section {
|
||||
display: none;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.download-section.active {
|
||||
display: flex;
|
||||
}
|
||||
|
||||
.btn-secondary {
|
||||
background: #6c757d;
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.btn-primary {
|
||||
background: #28a745;
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.qr-history {
|
||||
margin-top: 30px;
|
||||
padding: 25px;
|
||||
background: #f8f9fa;
|
||||
border-radius: 10px;
|
||||
border: 1px solid #e9ecef;
|
||||
}
|
||||
|
||||
.qr-history h3 {
|
||||
margin-bottom: 20px;
|
||||
color: #333;
|
||||
}
|
||||
|
||||
.qr-item {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 15px;
|
||||
padding: 15px;
|
||||
background: white;
|
||||
border-radius: 8px;
|
||||
margin-bottom: 10px;
|
||||
border: 1px solid #e9ecef;
|
||||
}
|
||||
|
||||
.qr-item img {
|
||||
width: 50px;
|
||||
height: 50px;
|
||||
border-radius: 5px;
|
||||
}
|
||||
|
||||
.qr-item-info {
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.qr-item-info h4 {
|
||||
color: #333;
|
||||
margin-bottom: 5px;
|
||||
}
|
||||
|
||||
.qr-item-info p {
|
||||
color: #666;
|
||||
font-size: 0.9em;
|
||||
}
|
||||
|
||||
.qr-item-actions {
|
||||
display: flex;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.btn-small {
|
||||
padding: 5px 15px;
|
||||
font-size: 12px;
|
||||
border-radius: 5px;
|
||||
}
|
||||
|
||||
@media (max-width: 768px) {
|
||||
.main-content {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
|
||||
.color-inputs {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
|
||||
.style-selector {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="container">
|
||||
<div class="header">
|
||||
<h1>🎯 QR Code Manager</h1>
|
||||
<p>Create, customize, and manage your QR codes with ease</p>
|
||||
<div style="position: absolute; top: 20px; right: 20px;">
|
||||
<a href="/logout" style="color: white; text-decoration: none; background: rgba(255,255,255,0.2); padding: 8px 15px; border-radius: 20px; font-size: 0.9em;">
|
||||
👤 Logout
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="main-content">
|
||||
<div class="form-section">
|
||||
<h2>Generate QR Code</h2>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="qr-type">QR Code Type</label>
|
||||
<select id="qr-type" onchange="toggleFields()">
|
||||
<option value="text">Text</option>
|
||||
<option value="url">URL/Website</option>
|
||||
<option value="link_page">Dynamic Link Page</option>
|
||||
<option value="wifi">WiFi</option>
|
||||
<option value="email">Email</option>
|
||||
<option value="phone">Phone</option>
|
||||
<option value="sms">SMS</option>
|
||||
<option value="vcard">Contact Card</option>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<!-- Text/URL content -->
|
||||
<div class="form-group" id="text-field">
|
||||
<label for="content">Content</label>
|
||||
<textarea id="content" placeholder="Enter your text or URL..."></textarea>
|
||||
</div>
|
||||
|
||||
<!-- WiFi fields -->
|
||||
<div class="wifi-fields" id="wifi-fields">
|
||||
<div class="form-group">
|
||||
<label for="wifi-ssid">Network Name (SSID)</label>
|
||||
<input type="text" id="wifi-ssid" placeholder="My WiFi Network">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="wifi-password">Password</label>
|
||||
<input type="password" id="wifi-password" placeholder="WiFi Password">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="wifi-security">Security Type</label>
|
||||
<select id="wifi-security">
|
||||
<option value="WPA">WPA/WPA2</option>
|
||||
<option value="WEP">WEP</option>
|
||||
<option value="nopass">No Password</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Link Page fields -->
|
||||
<div class="link-page-fields" id="link-page-fields">
|
||||
<div class="form-group">
|
||||
<label for="page-title">Page Title</label>
|
||||
<input type="text" id="page-title" placeholder="My Link Collection" value="My Links">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="page-description">Description</label>
|
||||
<textarea id="page-description" placeholder="A collection of useful links">Collection of useful links</textarea>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<p style="background: #e3f2fd; padding: 15px; border-radius: 8px; color: #1565c0; font-size: 0.9em;">
|
||||
<strong>💡 Dynamic Link Page:</strong> This creates a QR code that points to a web page where you can add, edit, and manage links. The QR code stays the same, but you can update the links anytime!
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Email fields -->
|
||||
<div class="email-fields" id="email-fields">
|
||||
<div class="form-group">
|
||||
<label for="email-address">Email Address</label>
|
||||
<input type="email" id="email-address" placeholder="contact@example.com">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="email-subject">Subject</label>
|
||||
<input type="text" id="email-subject" placeholder="Email subject">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="email-body">Message</label>
|
||||
<textarea id="email-body" placeholder="Email message..."></textarea>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- SMS fields -->
|
||||
<div class="sms-fields" id="sms-fields">
|
||||
<div class="form-group">
|
||||
<label for="sms-phone">Phone Number</label>
|
||||
<input type="tel" id="sms-phone" placeholder="+1234567890">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="sms-message">Message</label>
|
||||
<textarea id="sms-message" placeholder="SMS message..."></textarea>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- vCard fields -->
|
||||
<div class="vcard-fields" id="vcard-fields">
|
||||
<div class="form-group">
|
||||
<label for="vcard-name">Full Name</label>
|
||||
<input type="text" id="vcard-name" placeholder="John Doe">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="vcard-organization">Organization</label>
|
||||
<input type="text" id="vcard-organization" placeholder="Company Name">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="vcard-phone">Phone</label>
|
||||
<input type="tel" id="vcard-phone" placeholder="+1234567890">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="vcard-email">Email</label>
|
||||
<input type="email" id="vcard-email" placeholder="john@example.com">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="vcard-website">Website</label>
|
||||
<input type="url" id="vcard-website" placeholder="https://example.com">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<h3 style="margin: 25px 0 15px 0; color: #333;">Customization</h3>
|
||||
|
||||
<div class="form-group">
|
||||
<label>Colors</label>
|
||||
<div class="color-inputs">
|
||||
<div class="color-input-group">
|
||||
<input type="color" id="foreground-color" value="#000000">
|
||||
<span>Foreground</span>
|
||||
</div>
|
||||
<div class="color-input-group">
|
||||
<input type="color" id="background-color" value="#FFFFFF">
|
||||
<span>Background</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label>Style</label>
|
||||
<div class="style-selector">
|
||||
<div class="style-option active" data-style="square">
|
||||
<div>⬛</div>
|
||||
<div>Square</div>
|
||||
</div>
|
||||
<div class="style-option" data-style="rounded">
|
||||
<div>⬜</div>
|
||||
<div>Rounded</div>
|
||||
</div>
|
||||
<div class="style-option" data-style="circle">
|
||||
<div>⚫</div>
|
||||
<div>Circle</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="size">Size</label>
|
||||
<input type="range" id="size" min="5" max="15" value="10" oninput="updateSizeLabel()">
|
||||
<small id="size-label">10px per module</small>
|
||||
</div>
|
||||
|
||||
<button class="btn" onclick="generateQR()">Generate QR Code</button>
|
||||
</div>
|
||||
|
||||
<div class="result-section">
|
||||
<h2>Preview</h2>
|
||||
<div class="qr-preview" id="qr-preview">
|
||||
<div class="placeholder">
|
||||
<div style="font-size: 3em; margin-bottom: 10px;">📱</div>
|
||||
<div>Your QR code will appear here</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="download-section" id="download-section">
|
||||
<button class="btn btn-primary" onclick="downloadQR()">Download PNG</button>
|
||||
<button class="btn btn-secondary" onclick="copyToClipboard()">Copy Image</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="qr-history">
|
||||
<h3>Recent QR Codes</h3>
|
||||
<div id="qr-history-list">
|
||||
<p style="color: #666; text-align: center;">No QR codes generated yet</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
let currentQRId = null;
|
||||
let currentQRData = null;
|
||||
|
||||
function toggleFields() {
|
||||
const type = document.getElementById('qr-type').value;
|
||||
|
||||
// Hide all specific fields
|
||||
document.getElementById('text-field').style.display = 'none';
|
||||
document.querySelectorAll('.wifi-fields, .link-page-fields, .email-fields, .sms-fields, .vcard-fields').forEach(el => {
|
||||
el.classList.remove('active');
|
||||
});
|
||||
|
||||
// Show relevant fields
|
||||
if (type === 'text' || type === 'url' || type === 'phone') {
|
||||
document.getElementById('text-field').style.display = 'block';
|
||||
const contentField = document.getElementById('content');
|
||||
if (type === 'url') {
|
||||
contentField.placeholder = 'https://example.com';
|
||||
} else if (type === 'phone') {
|
||||
contentField.placeholder = '+1234567890';
|
||||
} else {
|
||||
contentField.placeholder = 'Enter your text...';
|
||||
}
|
||||
} else {
|
||||
document.getElementById(`${type.replace('_', '-')}-fields`).classList.add('active');
|
||||
}
|
||||
}
|
||||
|
||||
function updateSizeLabel() {
|
||||
const size = document.getElementById('size').value;
|
||||
document.getElementById('size-label').textContent = `${size}px per module`;
|
||||
}
|
||||
|
||||
// Style selector
|
||||
document.querySelectorAll('.style-option').forEach(option => {
|
||||
option.addEventListener('click', function() {
|
||||
document.querySelectorAll('.style-option').forEach(opt => opt.classList.remove('active'));
|
||||
this.classList.add('active');
|
||||
});
|
||||
});
|
||||
|
||||
async function generateQR() {
|
||||
const type = document.getElementById('qr-type').value;
|
||||
let content = '';
|
||||
let additionalData = {};
|
||||
|
||||
// Get content based on type
|
||||
if (type === 'text' || type === 'url' || type === 'phone') {
|
||||
content = document.getElementById('content').value;
|
||||
} else if (type === 'link_page') {
|
||||
additionalData.title = document.getElementById('page-title').value;
|
||||
additionalData.description = document.getElementById('page-description').value;
|
||||
} else if (type === 'wifi') {
|
||||
additionalData.wifi = {
|
||||
ssid: document.getElementById('wifi-ssid').value,
|
||||
password: document.getElementById('wifi-password').value,
|
||||
security: document.getElementById('wifi-security').value
|
||||
};
|
||||
} else if (type === 'email') {
|
||||
additionalData.email = {
|
||||
email: document.getElementById('email-address').value,
|
||||
subject: document.getElementById('email-subject').value,
|
||||
body: document.getElementById('email-body').value
|
||||
};
|
||||
} else if (type === 'sms') {
|
||||
additionalData.sms = {
|
||||
phone: document.getElementById('sms-phone').value,
|
||||
message: document.getElementById('sms-message').value
|
||||
};
|
||||
} else if (type === 'vcard') {
|
||||
additionalData.vcard = {
|
||||
name: document.getElementById('vcard-name').value,
|
||||
organization: document.getElementById('vcard-organization').value,
|
||||
phone: document.getElementById('vcard-phone').value,
|
||||
email: document.getElementById('vcard-email').value,
|
||||
website: document.getElementById('vcard-website').value
|
||||
};
|
||||
}
|
||||
|
||||
const requestData = {
|
||||
type: type,
|
||||
content: content,
|
||||
...additionalData,
|
||||
size: parseInt(document.getElementById('size').value),
|
||||
foreground_color: document.getElementById('foreground-color').value,
|
||||
background_color: document.getElementById('background-color').value,
|
||||
style: document.querySelector('.style-option.active').dataset.style
|
||||
};
|
||||
|
||||
try {
|
||||
const endpoint = type === 'link_page' ? '/api/create_link_page' : '/api/generate';
|
||||
const response = await fetch(endpoint, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify(requestData)
|
||||
});
|
||||
|
||||
const result = await response.json();
|
||||
|
||||
if (result.success) {
|
||||
currentQRId = result.qr_id;
|
||||
currentQRData = result.image_data;
|
||||
|
||||
// Show QR code
|
||||
const preview = document.getElementById('qr-preview');
|
||||
let previewHTML = `<img src="${result.image_data}" alt="Generated QR Code">`;
|
||||
|
||||
// Add special info for link pages
|
||||
if (type === 'link_page') {
|
||||
previewHTML += `
|
||||
<div style="margin-top: 15px; padding: 15px; background: #e3f2fd; border-radius: 8px; text-align: left;">
|
||||
<h4 style="margin-bottom: 10px; color: #1565c0;">🎉 Dynamic Link Page Created!</h4>
|
||||
<p style="margin-bottom: 10px; font-size: 0.9em;"><strong>Public URL:</strong> <a href="${result.page_url}" target="_blank">${result.page_url}</a></p>
|
||||
<p style="margin-bottom: 10px; font-size: 0.9em;"><strong>Edit URL:</strong> <a href="${result.edit_url}" target="_blank">${result.edit_url}</a></p>
|
||||
<p style="font-size: 0.9em; color: #666;">Share the QR code - visitors will see your link collection. Use the edit URL to manage your links!</p>
|
||||
</div>
|
||||
`;
|
||||
}
|
||||
|
||||
preview.innerHTML = previewHTML;
|
||||
|
||||
// Show download buttons
|
||||
document.getElementById('download-section').classList.add('active');
|
||||
|
||||
// Refresh history
|
||||
loadQRHistory();
|
||||
} else {
|
||||
alert('Error generating QR code: ' + result.error);
|
||||
}
|
||||
} catch (error) {
|
||||
alert('Error: ' + error.message);
|
||||
}
|
||||
}
|
||||
|
||||
async function downloadQR() {
|
||||
if (currentQRId) {
|
||||
window.open(`/api/download/${currentQRId}`, '_blank');
|
||||
}
|
||||
}
|
||||
|
||||
async function copyToClipboard() {
|
||||
if (currentQRData) {
|
||||
try {
|
||||
const response = await fetch(currentQRData);
|
||||
const blob = await response.blob();
|
||||
await navigator.clipboard.write([
|
||||
new ClipboardItem({ [blob.type]: blob })
|
||||
]);
|
||||
alert('QR code copied to clipboard!');
|
||||
} catch (error) {
|
||||
alert('Failed to copy to clipboard');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async function loadQRHistory() {
|
||||
try {
|
||||
const response = await fetch('/api/qr_codes');
|
||||
const qrCodes = await response.json();
|
||||
|
||||
const historyList = document.getElementById('qr-history-list');
|
||||
|
||||
if (qrCodes.length === 0) {
|
||||
historyList.innerHTML = '<p style="color: #666; text-align: center;">No QR codes generated yet</p>';
|
||||
return;
|
||||
}
|
||||
|
||||
historyList.innerHTML = qrCodes.map(qr => `
|
||||
<div class="qr-item">
|
||||
<img src="${qr.preview}" alt="QR Code">
|
||||
<div class="qr-item-info">
|
||||
<h4>${qr.type.toUpperCase()}${qr.type === 'link_page' ? ' 🔗' : ''}</h4>
|
||||
<p>Created: ${new Date(qr.created_at).toLocaleDateString()}</p>
|
||||
</div>
|
||||
<div class="qr-item-actions">
|
||||
<button class="btn btn-small btn-primary" onclick="downloadQRById('${qr.id}')">Download</button>
|
||||
${qr.type === 'link_page' ? `<button class="btn btn-small" onclick="openLinkPage('${qr.id}')" style="background: #28a745;">Manage</button>` : ''}
|
||||
<button class="btn btn-small btn-secondary" onclick="deleteQR('${qr.id}')">Delete</button>
|
||||
</div>
|
||||
</div>
|
||||
`).join('');
|
||||
} catch (error) {
|
||||
console.error('Failed to load QR history:', error);
|
||||
}
|
||||
}
|
||||
|
||||
async function downloadQRById(qrId) {
|
||||
window.open(`/api/download/${qrId}`, '_blank');
|
||||
}
|
||||
|
||||
async function deleteQR(qrId) {
|
||||
if (confirm('Are you sure you want to delete this QR code?')) {
|
||||
try {
|
||||
const response = await fetch(`/api/qr_codes/${qrId}`, {
|
||||
method: 'DELETE'
|
||||
});
|
||||
|
||||
if (response.ok) {
|
||||
loadQRHistory();
|
||||
} else {
|
||||
alert('Failed to delete QR code');
|
||||
}
|
||||
} catch (error) {
|
||||
alert('Error deleting QR code: ' + error.message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async function openLinkPage(qrId) {
|
||||
try {
|
||||
const response = await fetch(`/api/qr_codes/${qrId}`);
|
||||
const qrData = await response.json();
|
||||
|
||||
if (qrData.page_id) {
|
||||
window.open(`/edit/${qrData.page_id}`, '_blank');
|
||||
} else {
|
||||
alert('Link page not found');
|
||||
}
|
||||
} catch (error) {
|
||||
alert('Error opening link page: ' + error.message);
|
||||
}
|
||||
}
|
||||
|
||||
// Load history on page load
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
loadQRHistory();
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
281
app/templates/link_page.html
Normal file
281
app/templates/link_page.html
Normal file
@@ -0,0 +1,281 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>{{ page.title }}</title>
|
||||
<style>
|
||||
* {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
body {
|
||||
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
min-height: 100vh;
|
||||
padding: 20px;
|
||||
}
|
||||
|
||||
.container {
|
||||
max-width: 800px;
|
||||
margin: 0 auto;
|
||||
background: white;
|
||||
border-radius: 15px;
|
||||
box-shadow: 0 20px 40px rgba(0,0,0,0.1);
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.header {
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
color: white;
|
||||
padding: 40px 30px;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.header h1 {
|
||||
font-size: 2.5em;
|
||||
margin-bottom: 10px;
|
||||
font-weight: 300;
|
||||
}
|
||||
|
||||
.header p {
|
||||
font-size: 1.1em;
|
||||
opacity: 0.9;
|
||||
}
|
||||
|
||||
.stats {
|
||||
background: rgba(255,255,255,0.1);
|
||||
margin-top: 20px;
|
||||
padding: 15px;
|
||||
border-radius: 10px;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
gap: 30px;
|
||||
}
|
||||
|
||||
.stat-item {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.stat-number {
|
||||
font-size: 1.5em;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.stat-label {
|
||||
font-size: 0.9em;
|
||||
opacity: 0.8;
|
||||
margin-top: 5px;
|
||||
}
|
||||
|
||||
.content {
|
||||
padding: 30px;
|
||||
}
|
||||
|
||||
.links-section h2 {
|
||||
color: #333;
|
||||
margin-bottom: 25px;
|
||||
font-size: 1.8em;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.link-item {
|
||||
background: #f8f9fa;
|
||||
border: 1px solid #e9ecef;
|
||||
border-radius: 12px;
|
||||
padding: 20px;
|
||||
margin-bottom: 15px;
|
||||
transition: all 0.3s ease;
|
||||
cursor: pointer;
|
||||
text-decoration: none;
|
||||
display: block;
|
||||
color: inherit;
|
||||
}
|
||||
|
||||
.link-item:hover {
|
||||
transform: translateY(-2px);
|
||||
box-shadow: 0 8px 25px rgba(0,0,0,0.1);
|
||||
border-color: #667eea;
|
||||
}
|
||||
|
||||
.link-title {
|
||||
font-size: 1.3em;
|
||||
font-weight: 600;
|
||||
color: #333;
|
||||
margin-bottom: 8px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.link-icon {
|
||||
width: 20px;
|
||||
height: 20px;
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
border-radius: 50%;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
color: white;
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.link-description {
|
||||
color: #666;
|
||||
font-size: 0.95em;
|
||||
line-height: 1.4;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
.link-url {
|
||||
color: #667eea;
|
||||
font-size: 0.9em;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.empty-state {
|
||||
text-align: center;
|
||||
padding: 60px 20px;
|
||||
color: #666;
|
||||
}
|
||||
|
||||
.empty-state .icon {
|
||||
font-size: 4em;
|
||||
margin-bottom: 20px;
|
||||
opacity: 0.5;
|
||||
}
|
||||
|
||||
.empty-state h3 {
|
||||
font-size: 1.5em;
|
||||
margin-bottom: 10px;
|
||||
color: #333;
|
||||
}
|
||||
|
||||
.footer {
|
||||
background: #f8f9fa;
|
||||
padding: 20px;
|
||||
text-align: center;
|
||||
border-top: 1px solid #e9ecef;
|
||||
color: #666;
|
||||
font-size: 0.9em;
|
||||
}
|
||||
|
||||
.footer a {
|
||||
color: #667eea;
|
||||
text-decoration: none;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.footer a:hover {
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
.last-updated {
|
||||
margin-top: 10px;
|
||||
font-size: 0.8em;
|
||||
opacity: 0.7;
|
||||
}
|
||||
|
||||
@media (max-width: 768px) {
|
||||
.header {
|
||||
padding: 30px 20px;
|
||||
}
|
||||
|
||||
.header h1 {
|
||||
font-size: 2em;
|
||||
}
|
||||
|
||||
.content {
|
||||
padding: 20px;
|
||||
}
|
||||
|
||||
.stats {
|
||||
flex-direction: column;
|
||||
gap: 15px;
|
||||
}
|
||||
}
|
||||
|
||||
/* Link animation */
|
||||
@keyframes linkPulse {
|
||||
0% { transform: scale(1); }
|
||||
50% { transform: scale(1.02); }
|
||||
100% { transform: scale(1); }
|
||||
}
|
||||
|
||||
.link-item:active {
|
||||
animation: linkPulse 0.2s ease;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="container">
|
||||
<div class="header">
|
||||
<h1>{{ page.title }}</h1>
|
||||
<p>{{ page.description }}</p>
|
||||
|
||||
<div class="stats">
|
||||
<div class="stat-item">
|
||||
<div class="stat-number">{{ page.links|length }}</div>
|
||||
<div class="stat-label">Links</div>
|
||||
</div>
|
||||
<div class="stat-item">
|
||||
<div class="stat-number">{{ page.view_count }}</div>
|
||||
<div class="stat-label">Views</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="content">
|
||||
<div class="links-section">
|
||||
{% if page.links %}
|
||||
<h2>📚 Available Links</h2>
|
||||
{% for link in page.links %}
|
||||
<a href="{{ link.url }}" target="_blank" class="link-item">
|
||||
<div class="link-title">
|
||||
<div class="link-icon">🔗</div>
|
||||
{{ link.title }}
|
||||
</div>
|
||||
{% if link.description %}
|
||||
<div class="link-description">{{ link.description }}</div>
|
||||
{% endif %}
|
||||
<div class="link-url">{{ link.url }}</div>
|
||||
</a>
|
||||
{% endfor %}
|
||||
{% else %}
|
||||
<div class="empty-state">
|
||||
<div class="icon">📝</div>
|
||||
<h3>No links yet</h3>
|
||||
<p>This collection is empty. Check back later for new links!</p>
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="footer">
|
||||
<p>Powered by <a href="/">QR Code Manager</a></p>
|
||||
{% if page.updated_at %}
|
||||
<div class="last-updated">
|
||||
Last updated: {{ page.updated_at[:10] }} at {{ page.updated_at[11:19] }}
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
// Add click tracking (optional)
|
||||
document.querySelectorAll('.link-item').forEach(link => {
|
||||
link.addEventListener('click', function() {
|
||||
// You could add analytics here
|
||||
console.log('Link clicked:', this.querySelector('.link-title').textContent.trim());
|
||||
});
|
||||
});
|
||||
|
||||
// Auto-refresh every 30 seconds to get latest links
|
||||
setInterval(() => {
|
||||
window.location.reload();
|
||||
}, 30000);
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
253
app/templates/login.html
Normal file
253
app/templates/login.html
Normal file
@@ -0,0 +1,253 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>QR Code Manager - Login</title>
|
||||
<style>
|
||||
* {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
body {
|
||||
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
min-height: 100vh;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
padding: 20px;
|
||||
}
|
||||
|
||||
.login-container {
|
||||
background: white;
|
||||
border-radius: 15px;
|
||||
box-shadow: 0 20px 40px rgba(0,0,0,0.1);
|
||||
overflow: hidden;
|
||||
width: 100%;
|
||||
max-width: 400px;
|
||||
}
|
||||
|
||||
.login-header {
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
color: white;
|
||||
padding: 40px 30px;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.login-header h1 {
|
||||
font-size: 2.5em;
|
||||
margin-bottom: 10px;
|
||||
font-weight: 300;
|
||||
}
|
||||
|
||||
.login-header p {
|
||||
font-size: 1.1em;
|
||||
opacity: 0.9;
|
||||
}
|
||||
|
||||
.login-form {
|
||||
padding: 40px 30px;
|
||||
}
|
||||
|
||||
.form-group {
|
||||
margin-bottom: 25px;
|
||||
}
|
||||
|
||||
.form-group label {
|
||||
display: block;
|
||||
margin-bottom: 8px;
|
||||
font-weight: 600;
|
||||
color: #555;
|
||||
}
|
||||
|
||||
.form-group input {
|
||||
width: 100%;
|
||||
padding: 15px;
|
||||
border: 2px solid #e9ecef;
|
||||
border-radius: 8px;
|
||||
font-size: 16px;
|
||||
transition: border-color 0.3s;
|
||||
background: #f8f9fa;
|
||||
}
|
||||
|
||||
.form-group input:focus {
|
||||
outline: none;
|
||||
border-color: #667eea;
|
||||
background: white;
|
||||
}
|
||||
|
||||
.login-btn {
|
||||
width: 100%;
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
color: white;
|
||||
padding: 15px;
|
||||
border: none;
|
||||
border-radius: 8px;
|
||||
font-size: 18px;
|
||||
font-weight: 600;
|
||||
cursor: pointer;
|
||||
transition: transform 0.2s;
|
||||
}
|
||||
|
||||
.login-btn:hover {
|
||||
transform: translateY(-2px);
|
||||
}
|
||||
|
||||
.login-btn:active {
|
||||
transform: translateY(0);
|
||||
}
|
||||
|
||||
.alert {
|
||||
padding: 15px;
|
||||
border-radius: 8px;
|
||||
margin-bottom: 20px;
|
||||
text-align: center;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.alert-error {
|
||||
background: #f8d7da;
|
||||
border: 1px solid #f5c6cb;
|
||||
color: #721c24;
|
||||
}
|
||||
|
||||
.alert-success {
|
||||
background: #d4edda;
|
||||
border: 1px solid #c3e6cb;
|
||||
color: #155724;
|
||||
}
|
||||
|
||||
.alert-info {
|
||||
background: #d1ecf1;
|
||||
border: 1px solid #bee5eb;
|
||||
color: #0c5460;
|
||||
}
|
||||
|
||||
.login-footer {
|
||||
padding: 20px 30px;
|
||||
background: #f8f9fa;
|
||||
text-align: center;
|
||||
color: #666;
|
||||
font-size: 0.9em;
|
||||
}
|
||||
|
||||
.default-credentials {
|
||||
background: #fff3cd;
|
||||
border: 1px solid #ffeaa7;
|
||||
color: #856404;
|
||||
padding: 15px;
|
||||
border-radius: 8px;
|
||||
margin-bottom: 20px;
|
||||
text-align: center;
|
||||
font-size: 0.9em;
|
||||
}
|
||||
|
||||
.default-credentials strong {
|
||||
display: block;
|
||||
margin-bottom: 5px;
|
||||
}
|
||||
|
||||
@media (max-width: 480px) {
|
||||
.login-container {
|
||||
margin: 10px;
|
||||
}
|
||||
|
||||
.login-header {
|
||||
padding: 30px 20px;
|
||||
}
|
||||
|
||||
.login-header h1 {
|
||||
font-size: 2em;
|
||||
}
|
||||
|
||||
.login-form {
|
||||
padding: 30px 20px;
|
||||
}
|
||||
}
|
||||
|
||||
/* Security icon animation */
|
||||
.security-icon {
|
||||
font-size: 3em;
|
||||
margin-bottom: 15px;
|
||||
animation: pulse 2s infinite;
|
||||
}
|
||||
|
||||
@keyframes pulse {
|
||||
0% { transform: scale(1); }
|
||||
50% { transform: scale(1.05); }
|
||||
100% { transform: scale(1); }
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="login-container">
|
||||
<div class="login-header">
|
||||
<div class="security-icon">🔐</div>
|
||||
<h1>QR Manager</h1>
|
||||
<p>Secure Admin Access</p>
|
||||
</div>
|
||||
|
||||
<div class="login-form">
|
||||
{% with messages = get_flashed_messages(with_categories=true) %}
|
||||
{% if messages %}
|
||||
{% for category, message in messages %}
|
||||
<div class="alert alert-{{ category }}">{{ message }}</div>
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
{% endwith %}
|
||||
|
||||
<div class="default-credentials">
|
||||
<strong>Default Login Credentials:</strong>
|
||||
Username: admin<br>
|
||||
Password: admin123
|
||||
</div>
|
||||
|
||||
<form method="POST">
|
||||
<div class="form-group">
|
||||
<label for="username">Username</label>
|
||||
<input type="text" id="username" name="username" required autocomplete="username">
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="password">Password</label>
|
||||
<input type="password" id="password" name="password" required autocomplete="current-password">
|
||||
</div>
|
||||
|
||||
<button type="submit" class="login-btn">🚀 Login</button>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<div class="login-footer">
|
||||
<p>🔒 Secure QR Code Management System</p>
|
||||
<p style="margin-top: 5px; font-size: 0.8em; opacity: 0.7;">
|
||||
Change default credentials in production
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
// Auto-focus on username field
|
||||
document.getElementById('username').focus();
|
||||
|
||||
// Handle form submission
|
||||
document.querySelector('form').addEventListener('submit', function(e) {
|
||||
const username = document.getElementById('username').value;
|
||||
const password = document.getElementById('password').value;
|
||||
|
||||
if (!username || !password) {
|
||||
e.preventDefault();
|
||||
alert('Please enter both username and password');
|
||||
return;
|
||||
}
|
||||
|
||||
// Show loading state
|
||||
const btn = document.querySelector('.login-btn');
|
||||
btn.innerHTML = '🔄 Logging in...';
|
||||
btn.disabled = true;
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
20
app/utils/__init__.py
Normal file
20
app/utils/__init__.py
Normal file
@@ -0,0 +1,20 @@
|
||||
"""
|
||||
Utility modules for QR Code Manager
|
||||
"""
|
||||
|
||||
from .auth import init_admin, login_required, verify_password, get_admin_credentials
|
||||
from .qr_generator import QRCodeGenerator
|
||||
from .link_manager import LinkPageManager, link_pages_db
|
||||
from .data_manager import QRDataManager, qr_codes_db
|
||||
|
||||
__all__ = [
|
||||
'init_admin',
|
||||
'login_required',
|
||||
'verify_password',
|
||||
'get_admin_credentials',
|
||||
'QRCodeGenerator',
|
||||
'LinkPageManager',
|
||||
'link_pages_db',
|
||||
'QRDataManager',
|
||||
'qr_codes_db'
|
||||
]
|
||||
39
app/utils/auth.py
Normal file
39
app/utils/auth.py
Normal file
@@ -0,0 +1,39 @@
|
||||
"""
|
||||
Authentication utilities for QR Code Manager
|
||||
"""
|
||||
|
||||
import os
|
||||
import bcrypt
|
||||
from functools import wraps
|
||||
from flask import session, redirect, url_for, request, jsonify
|
||||
|
||||
# Admin configuration
|
||||
ADMIN_USERNAME = os.environ.get('ADMIN_USERNAME', 'admin')
|
||||
ADMIN_PASSWORD_HASH = None
|
||||
|
||||
def init_admin():
|
||||
"""Initialize admin user with password from environment or default"""
|
||||
global ADMIN_PASSWORD_HASH
|
||||
admin_password = os.environ.get('ADMIN_PASSWORD', 'admin123')
|
||||
ADMIN_PASSWORD_HASH = bcrypt.hashpw(admin_password.encode('utf-8'), bcrypt.gensalt())
|
||||
print(f"Admin user initialized: {ADMIN_USERNAME}")
|
||||
print(f"Default password: {admin_password if admin_password == 'admin123' else '***'}")
|
||||
|
||||
def verify_password(password, hashed):
|
||||
"""Verify a password against its hash"""
|
||||
return bcrypt.checkpw(password.encode('utf-8'), hashed)
|
||||
|
||||
def login_required(f):
|
||||
"""Authentication decorator"""
|
||||
@wraps(f)
|
||||
def decorated_function(*args, **kwargs):
|
||||
if 'logged_in' not in session:
|
||||
if request.endpoint and request.endpoint.startswith('api'):
|
||||
return jsonify({'error': 'Authentication required'}), 401
|
||||
return redirect(url_for('auth.login'))
|
||||
return f(*args, **kwargs)
|
||||
return decorated_function
|
||||
|
||||
def get_admin_credentials():
|
||||
"""Get admin credentials for authentication"""
|
||||
return ADMIN_USERNAME, ADMIN_PASSWORD_HASH
|
||||
58
app/utils/data_manager.py
Normal file
58
app/utils/data_manager.py
Normal file
@@ -0,0 +1,58 @@
|
||||
"""
|
||||
Data storage utilities for QR codes
|
||||
"""
|
||||
|
||||
import uuid
|
||||
from datetime import datetime
|
||||
|
||||
# In-memory storage for QR codes (in production, use a database)
|
||||
qr_codes_db = {}
|
||||
|
||||
class QRDataManager:
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
def save_qr_record(self, qr_type, content, settings, image_data, page_id=None):
|
||||
"""Save QR code record to database"""
|
||||
qr_id = str(uuid.uuid4())
|
||||
qr_record = {
|
||||
'id': qr_id,
|
||||
'type': qr_type,
|
||||
'content': content,
|
||||
'settings': settings,
|
||||
'created_at': datetime.now().isoformat(),
|
||||
'image_data': image_data
|
||||
}
|
||||
|
||||
if page_id:
|
||||
qr_record['page_id'] = page_id
|
||||
|
||||
qr_codes_db[qr_id] = qr_record
|
||||
return qr_id
|
||||
|
||||
def get_qr_record(self, qr_id):
|
||||
"""Get QR code record"""
|
||||
return qr_codes_db.get(qr_id)
|
||||
|
||||
def delete_qr_record(self, qr_id):
|
||||
"""Delete QR code record"""
|
||||
if qr_id in qr_codes_db:
|
||||
del qr_codes_db[qr_id]
|
||||
return True
|
||||
return False
|
||||
|
||||
def list_qr_codes(self):
|
||||
"""List all QR codes"""
|
||||
qr_list = []
|
||||
for qr_id, qr_data in qr_codes_db.items():
|
||||
qr_list.append({
|
||||
'id': qr_id,
|
||||
'type': qr_data['type'],
|
||||
'created_at': qr_data['created_at'],
|
||||
'preview': f'data:image/png;base64,{qr_data["image_data"]}'
|
||||
})
|
||||
return qr_list
|
||||
|
||||
def qr_exists(self, qr_id):
|
||||
"""Check if QR code exists"""
|
||||
return qr_id in qr_codes_db
|
||||
86
app/utils/link_manager.py
Normal file
86
app/utils/link_manager.py
Normal file
@@ -0,0 +1,86 @@
|
||||
"""
|
||||
Dynamic Link Page Manager utilities
|
||||
"""
|
||||
|
||||
import uuid
|
||||
from datetime import datetime
|
||||
|
||||
# In-memory storage for dynamic link pages (in production, use a database)
|
||||
link_pages_db = {}
|
||||
|
||||
class LinkPageManager:
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
def create_link_page(self, title="My Links", description="Collection of useful links"):
|
||||
"""Create a new dynamic link page"""
|
||||
page_id = str(uuid.uuid4())
|
||||
page_data = {
|
||||
'id': page_id,
|
||||
'title': title,
|
||||
'description': description,
|
||||
'links': [],
|
||||
'created_at': datetime.now().isoformat(),
|
||||
'updated_at': datetime.now().isoformat(),
|
||||
'view_count': 0
|
||||
}
|
||||
link_pages_db[page_id] = page_data
|
||||
return page_id
|
||||
|
||||
def add_link(self, page_id, title, url, description=""):
|
||||
"""Add a link to a page"""
|
||||
if page_id not in link_pages_db:
|
||||
return False
|
||||
|
||||
link_data = {
|
||||
'id': str(uuid.uuid4()),
|
||||
'title': title,
|
||||
'url': url if url.startswith(('http://', 'https://')) else f'https://{url}',
|
||||
'description': description,
|
||||
'created_at': datetime.now().isoformat()
|
||||
}
|
||||
|
||||
link_pages_db[page_id]['links'].append(link_data)
|
||||
link_pages_db[page_id]['updated_at'] = datetime.now().isoformat()
|
||||
return True
|
||||
|
||||
def update_link(self, page_id, link_id, title=None, url=None, description=None):
|
||||
"""Update a specific link"""
|
||||
if page_id not in link_pages_db:
|
||||
return False
|
||||
|
||||
for link in link_pages_db[page_id]['links']:
|
||||
if link['id'] == link_id:
|
||||
if title is not None:
|
||||
link['title'] = title
|
||||
if url is not None:
|
||||
link['url'] = url if url.startswith(('http://', 'https://')) else f'https://{url}'
|
||||
if description is not None:
|
||||
link['description'] = description
|
||||
|
||||
link_pages_db[page_id]['updated_at'] = datetime.now().isoformat()
|
||||
return True
|
||||
return False
|
||||
|
||||
def delete_link(self, page_id, link_id):
|
||||
"""Delete a specific link"""
|
||||
if page_id not in link_pages_db:
|
||||
return False
|
||||
|
||||
links = link_pages_db[page_id]['links']
|
||||
link_pages_db[page_id]['links'] = [link for link in links if link['id'] != link_id]
|
||||
link_pages_db[page_id]['updated_at'] = datetime.now().isoformat()
|
||||
return True
|
||||
|
||||
def increment_view_count(self, page_id):
|
||||
"""Increment view count for a page"""
|
||||
if page_id in link_pages_db:
|
||||
link_pages_db[page_id]['view_count'] += 1
|
||||
|
||||
def get_page(self, page_id):
|
||||
"""Get page data"""
|
||||
return link_pages_db.get(page_id)
|
||||
|
||||
def page_exists(self, page_id):
|
||||
"""Check if page exists"""
|
||||
return page_id in link_pages_db
|
||||
95
app/utils/qr_generator.py
Normal file
95
app/utils/qr_generator.py
Normal file
@@ -0,0 +1,95 @@
|
||||
"""
|
||||
QR Code generation utilities
|
||||
"""
|
||||
|
||||
import os
|
||||
import qrcode
|
||||
from qrcode.image.styledpil import StyledPilImage
|
||||
from qrcode.image.styles.moduledrawers import RoundedModuleDrawer, CircleModuleDrawer, SquareModuleDrawer
|
||||
from PIL import Image
|
||||
|
||||
class QRCodeGenerator:
|
||||
def __init__(self):
|
||||
self.default_settings = {
|
||||
'size': 10,
|
||||
'border': 4,
|
||||
'error_correction': qrcode.constants.ERROR_CORRECT_M,
|
||||
'foreground_color': '#000000',
|
||||
'background_color': '#FFFFFF',
|
||||
'style': 'square'
|
||||
}
|
||||
|
||||
def generate_qr_code(self, data, settings=None):
|
||||
"""Generate QR code with custom settings"""
|
||||
if settings is None:
|
||||
settings = self.default_settings.copy()
|
||||
else:
|
||||
merged_settings = self.default_settings.copy()
|
||||
merged_settings.update(settings)
|
||||
settings = merged_settings
|
||||
|
||||
# Create QR code instance
|
||||
qr = qrcode.QRCode(
|
||||
version=1,
|
||||
error_correction=settings['error_correction'],
|
||||
box_size=settings['size'],
|
||||
border=settings['border'],
|
||||
)
|
||||
|
||||
qr.add_data(data)
|
||||
qr.make(fit=True)
|
||||
|
||||
# For styled QR codes with custom module drawer
|
||||
if settings['style'] != 'square':
|
||||
# Choose module drawer based on style
|
||||
module_drawer = None
|
||||
if settings['style'] == 'rounded':
|
||||
module_drawer = RoundedModuleDrawer()
|
||||
elif settings['style'] == 'circle':
|
||||
module_drawer = CircleModuleDrawer()
|
||||
|
||||
# Generate the styled image
|
||||
img = qr.make_image(
|
||||
image_factory=StyledPilImage,
|
||||
module_drawer=module_drawer,
|
||||
fill_color=settings['foreground_color'],
|
||||
back_color=settings['background_color']
|
||||
)
|
||||
else:
|
||||
# Generate standard image with custom colors
|
||||
img = qr.make_image(
|
||||
fill_color=settings['foreground_color'],
|
||||
back_color=settings['background_color']
|
||||
)
|
||||
|
||||
return img
|
||||
|
||||
def add_logo(self, qr_img, logo_path, logo_size_ratio=0.2):
|
||||
"""Add logo to QR code"""
|
||||
try:
|
||||
logo = Image.open(logo_path)
|
||||
|
||||
# Calculate logo size
|
||||
qr_width, qr_height = qr_img.size
|
||||
logo_size = int(min(qr_width, qr_height) * logo_size_ratio)
|
||||
|
||||
# Resize logo
|
||||
logo = logo.resize((logo_size, logo_size), Image.Resampling.LANCZOS)
|
||||
|
||||
# Create a white background for the logo
|
||||
logo_bg = Image.new('RGB', (logo_size + 20, logo_size + 20), 'white')
|
||||
logo_bg.paste(logo, (10, 10))
|
||||
|
||||
# Calculate position to center the logo
|
||||
logo_pos = (
|
||||
(qr_width - logo_bg.width) // 2,
|
||||
(qr_height - logo_bg.height) // 2
|
||||
)
|
||||
|
||||
# Paste logo onto QR code
|
||||
qr_img.paste(logo_bg, logo_pos)
|
||||
|
||||
return qr_img
|
||||
except Exception as e:
|
||||
print(f"Error adding logo: {e}")
|
||||
return qr_img
|
||||
Reference in New Issue
Block a user